NimChimpsky
NimChimpsky

Reputation: 47280

Assert.assertAllValuesInArrayAreEqual - unit testing in java using junit, there is no such method?

Or is there ?

I just have

int[] results

and want to check each element in array has the same int value.

(yeah I could just loop through them).

Upvotes: 0

Views: 57

Answers (1)

codebox
codebox

Reputation: 20254

There's no need to loop, just convert the array into a Set object and then check its length, if the length is 1 then everything in the array was equal.

    Integer[] myArray = ...;
    assertThat(new HashSet(Arrays.asList(myArray)).size(), is(1));

Upvotes: 5

Related Questions