-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support for assertEmpty #465
Comments
You would normally write: import org.junit.Test;
import static org.junit.Assert.*;
import static org.hamcrest.text.IsEmptyString.*;
public class EmptyStringTest
{
@Test
public void test()
{
assertThat("", isEmptyString());
}
} |
If that solves your problem, can you close the issue? Thanks for your contribution, hopefully it will help someone else too :) |
Yes and No ;) I'm using JUnit 4.10 (via maven) which has a dependency to hamcrest-core 1.1, the core version does not have the text package included. There is however, a hamcrest-text 1.1 that does have this package, but not the IsEmptyString class (and it's not in maven). I like to keep version synchronised but it looks like that's not possible in thise case. I can however include hamcrest-all 1.3 and exclude hamcrest-core 1.1 from JUnit (perhaps you could rollout a JUnit version that uses 1.3? :) ). But wait... running assertThat("", isEmptyString()); throws a:
because of (copy & paste from decompiled class, excuse the capitalization):
which is inside the IsEmptyString class So, there appears to be an issue in the hamcrest IsEmptyString class, but quite honestly I don't understand what's supposed to happen inside the AnyOf class, perhaps you do? Guess I have to stick to my old trick. |
You're right, I do apologise. That's what you would need to write if Hamcrest 1.3 was supported ;) See #404. The AnyOf class allows you to specify an array (vararg) of matchers; the result will be true if 'any of' the matchers return true. The IsEmptyString use of AnyOf is to combine a null matcher with an empty string matcher to create a nullOrEmptyString matcher. |
Right, this should be better once we get #404 submitted. |
Closed hoping the next release will have #404 fixed this. |
Hello,
Sorry if this has been requested/discussed before, I didn't find a reference to a similar request.
I'd like to have an assertEmpty(...) method that tests for instance if a String is empty. I understand that:
assertEquals("", someString);
assertTrue(someString.isEmpty());
have similar effect, but it reads so much easier:
assertEmpty(someString);
any thoughts on that?
Thanks,
The text was updated successfully, but these errors were encountered: