I am trying to assert that a given array contains at least one instance of a given element. Is there an assert method that already does this? If so which one?
I am using Java6 and JUnit3.
assertThat(Arrays.asList(yourArray), hasItem(yourElement));
This will give you fine-grained information in the event of a test failure. It will print out your element and the collection it's looking in.
hasItem() is a part of Java Hamcrest, which was last updated in 2012.hasItem() is deprecatedNot a built-in assert, no. You'd need to use assertTrue() and check the array yourself using something like Arrays.binarySearch(), ArrayUtils.contains(), or your own method.
testArrayContains(ary, object)ArrayUtils approach, It seems my Project is including Apache Commons. I was about to create my own method, but I might as well use that one.