Skip to content
drewbourne edited this page Sep 13, 2010 · 1 revision

array matches if each of the matchers given are satisfied by the element at the same index in the array that is being matched.

  // explicit definition of matchers
  assertThat([1, 1.9, 4], array(equalTo(1), closeTo(2, 0.1), equalTo(4));

  // implicit using equalTo()
  assertThat([1, 1.9, 4], array(1, 2, 4));

arrayWithSize matches an Array with the expected number of items.

  assertThat([1, 2, 3], arrayWithSize(3));

emptyArray matches an Array with zero items.

  assertThat([], emptyArray());

everyItem matches an Array if every item matches the given Matcher.

  assertThat([1, 2, 3], everyItem(isA(Number)));

hasItem matches an Array that contains at least one item that matches the given Matcher.

  assertThat([1, 2, 3], hasItem(equalTo(3));

hasItems matches an Array if each of the matchers given are satisfied by any item in the array.

  assertThat([1, 2, 3, 4], hasItems(equalTo(2), equalTo(4)));