1package org.hamcrest.collection;2import org.hamcrest.AbstractMatcherTest;3import org.hamcrest.BaseMatcher;4import org.hamcrest.Description;5import org.hamcrest.Matcher;6import static org.hamcrest.collection.IsArray.array;7import static org.hamcrest.core.IsEqual.equalTo;8@SuppressWarnings("unchecked")9public class IsArrayTest extends AbstractMatcherTest {10 @Override11 protected Matcher<?> createMatcher() {12 return array(equalTo("irrelevant"));13 }14 public void testMatchesAnArrayThatMatchesAllTheElementMatchers() {15 assertMatches("should match array with matching elements",16 array(equalTo("a"), equalTo("b"), equalTo("c")), new String[]{"a", "b", "c"});17 }18 19 public void testDoesNotMatchAnArrayWhenElementsDoNotMatch() {20 assertDoesNotMatch("should not match array with different elements",21 array(equalTo("a"), equalTo("b")), new String[]{"b", "c"});22 }23 24 public void testDoesNotMatchAnArrayOfDifferentSize() {25 assertDoesNotMatch("should not match larger array",26 array(equalTo("a"), equalTo("b")), new String[]{"a", "b", "c"});27 assertDoesNotMatch("should not match smaller array",28 array(equalTo("a"), equalTo("b")), new String[]{"a"});29 }30 31 public void testDoesNotMatchNull() {32 assertDoesNotMatch("should not match null",33 array(equalTo("a")), null);34 }35 36 public void testHasAReadableDescription() {37 assertDescription("[\"a\", \"b\"]", array(equalTo("a"), equalTo("b")));38 }39 40 public void testHasAReadableMismatchDescriptionUsing() {41 assertMismatchDescription("element <0> was \"c\"", array(equalTo("a"), equalTo("b")), new String[]{"c", "b"});42 }43 44 public void testHasAReadableMismatchDescriptionUsingCustomMatchers() {45 final BaseMatcher<String> m = new BaseMatcher<String>() {46 @Override public boolean matches(Object item) { return false; }47 @Override public void describeTo(Description description) { description.appendText("c"); }48 @Override public void describeMismatch(Object item, Description description) {49 description.appendText("didn't match");50 }51 };52 assertMismatchDescription("element <0> didn't match", array(m, equalTo("b")), new String[]{"c", "b"});53 }54}...