--
You received this message because you are subscribed to the Google Groups "easytesting" group.
To post to this group, send email to easyt...@googlegroups.com.
To unsubscribe from this group, send email to easytesting...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/easytesting?hl=en.
Johannes
> assertThat(variable).isEqualTo(a).or().isEqualTo(b);
>
> Is there any support or workaround for things like that ?
I didn't test it, but the obvious workaround would be:
try {
assertThat(variable).isEqualTo(a);
catch (AssertionError e) {
assertThat(variable).isEqualTo(b);
}
Which is terribly ugly of course. I haven't hacked on fest so I wouldn't
be surprised to be corrected (more so if not), but couldn't that be
"sugared" (with a big patch) into the following syntax?
assertThat(variable).begin().isEqualTo(a).or().isEqualTo(b).end();
Almost Java code follows.
--Adam
public class ObjectAssert … {
…
public OrableObjectAssert begin() {
return new OrableObjectAssert(this);
}
}
public class OrableObjectAssert implements ObjectAssert {
…
protected OrableObjectAssert(ObjectAssert decorated) {
this.originalDecorated = decorated;
this.currentDecorated = decorated;
this.assertErros = new LinkedList<AssertionError>();
this.isTrue = true;
}
public OrableObjectAssert isEqualTo(Object expected) {
try {
if (isTrue)
currentDecorated = currentDecorated.isEqualTo(expected);
} catch (AssertionError e) {
assertErros.append(e);
isTrue = false;
}
return this;
}
public OrableObjectAssert or() {
if (isTrue) {
return new NeverRaisingObjectAssert(currentDecorated);
} else {
currentDecorated = originalDecorated;
isTrue = true;
return this;
}
}
public ObjectAssert end() {
if (assertErros.length != 0)
raise joinErrors(assertErros);
return currentDecorated;
}
}
Currently we don't support "or" out-of-the-box. I still don't know how we can achieve that in FEST. One approach could be like the one you showed:assertThat(variable).isEqualTo(a).or().isEqualTo(b);which is pretty understandable, but hard to implement (we'll need to keep state after "or" and then batch all the following assertions.)
It seems to me that you are trying to come up with a generic solution
for a case that doesn't have a valid real life example. Conditional
logic in tests is a smell. If I had a need to write an assertion like
that, I'd have rather create my own:
assertThat(something).isEqualToAnyOf(a, b)
Best regards,
Bartosz
If it needs be, then definitely you'd better use a isEqualToOneOf(T...)
method, which:
- is easy to implement
- is easily understood when reading test cases
- is easy to use when writing a TC
For the implementation, one may want to guarantee that there is at least
one argument:
isEqualToOneOf(T a, T... others)
that makes the implementation just a little bit more complex but ensures
no one can write an assertion like:
assertThat(something).isEqualToOneOf();
which is obviously meaningless.
Just my 2 cents
Jean-Francois
assertThat(variable).isEqualTo(a).or().isEqualTo(b);
One example: I used an external tool for image conversion (imagemagick).
Then I check the md5sum of the output. Now I'd like to support multiple
imagemagick versions that all return slightly different results.
Maybe not the best example... But that is one point where "or" might be
a fast fix.
Thanks,
Joahnnes Schneider
> easyt...@googlegroups.com <mailto:easyt...@googlegroups.com>.
> To unsubscribe from this group, send email to
> easytesting...@googlegroups.com
> <mailto:easytesting%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/group/easytesting?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "easytesting" group.
> To post to this group, send email to easyt...@googlegroups.com
> <mailto:easyt...@googlegroups.com>.
> To unsubscribe from this group, send email to
> easytesting...@googlegroups.com
> <mailto:easytesting%2Bunsu...@googlegroups.com>.
> For more options, visit this group at
> http://groups.google.com/group/easytesting?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "easytesting" group.
> To post to this group, send email to easyt...@googlegroups.com.
> To unsubscribe from this group, send email to
> easytesting...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/easytesting?hl=en.
- --
Johannes Schneider - blog.cedarsoft.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
iQEcBAEBAgAGBQJM79fmAAoJEAytD9R7Qv6dNQIH/1V89OOPqdlrW0/2Nn7yCYwI
+Wz2Xvvp4GdhUWeBcsXN6Fc2EKaxPi9U7/rrwuQTLCq2yAjOoJRE05H8xV3aZrJX
25USq1spAap+6L8qHVNo4LgMNJ+pOTX1Qqj66mrsFFPHedQNzDAjUQd6gCvJSeJK
9UG038slXcJ6WVHJbzd/94HS+42PryLElMbPKO66zT9PTMkwctDmZmJZFOcpOEUS
zjkVXbTuMoPxdEvhIuGjD8eYz2Bm1ikoZvFFHlPUp0YH5QddsfA98HtAu3cYAB8C
GiKOCQobhY18TXXK1itMUtdXCpYGwIi1XpaN6fGTq0V5iyXBKtxSznPuV98Ti0E=
=7P67
-----END PGP SIGNATURE-----
for the time being - that is without isIn(...) - you might try
something like:
assertThat(Arrays.asList(checksumOne, checksumTwo,
checksumThree)).contains(actualChecksum);
This of course reverts the actual vs. expected semantics of the
FEST-Assert API, so take care when the test actually fails and you try
to interpret the error message, but at least you have a working solution.
Best regards
Ansgar