1 package org.mockito.internal.matchers; 2 3 import org.junit.Test; 4 5 import java.util.ArrayList; 6 import java.util.List; 7 8 import static org.assertj.core.api.Assertions.assertThat; 9 10 public class InstanceOfTest { 11 12 @Test should_describe_the_matcher()13 public void should_describe_the_matcher() { 14 assertThat(new InstanceOf(Object.class).toString()).contains("isA") 15 .contains("Object"); 16 assertThat(new InstanceOf(Object[].class).toString()).contains("isA") 17 .contains("Object[]"); 18 assertThat(new InstanceOf(Object.class, "matches something").toString()).isEqualTo("matches something"); 19 } 20 21 @Test should_check_instance_type()22 public void should_check_instance_type() { 23 assertThat(new InstanceOf(Object.class).matches(new Object())).isTrue(); 24 assertThat(new InstanceOf(Object.class).matches(new ArrayList())).isTrue(); 25 assertThat(new InstanceOf(List.class).matches(new ArrayList())).isTrue(); 26 assertThat(new InstanceOf(List.class).matches(new Object())).isFalse(); 27 } 28 29 @Test should_check_for_primitive_wrapper_types()30 public void should_check_for_primitive_wrapper_types() { 31 assertThat(new InstanceOf(int.class).matches(1000)).isTrue(); 32 assertThat(new InstanceOf(Integer.class).matches(1000)).isTrue(); 33 assertThat(new InstanceOf(int.class).matches(new Integer(1000))).isTrue(); 34 assertThat(new InstanceOf(Integer.class).matches(new Integer(1000))).isTrue(); 35 36 assertThat(new InstanceOf(double.class).matches(1000.1)).isTrue(); 37 assertThat(new InstanceOf(Double.class).matches(1000.1)).isTrue(); 38 assertThat(new InstanceOf(double.class).matches(new Double(1000.1))).isTrue(); 39 assertThat(new InstanceOf(Double.class).matches(new Double(1000.1))).isTrue(); 40 41 assertThat(new InstanceOf(int.class).matches(1000L)).isFalse(); 42 assertThat(new InstanceOf(Integer.class).matches(1000L)).isFalse(); 43 assertThat(new InstanceOf(int.class).matches(new Long(1000))).isFalse(); 44 assertThat(new InstanceOf(Integer.class).matches(new Long(1000))).isFalse(); 45 46 assertThat(new InstanceOf(long.class).matches(1000L)).isTrue(); 47 assertThat(new InstanceOf(Long.class).matches(1000L)).isTrue(); 48 assertThat(new InstanceOf(long.class).matches(new Long(1000))).isTrue(); 49 assertThat(new InstanceOf(Long.class).matches(new Long(1000))).isTrue(); 50 51 assertThat(new InstanceOf(long.class).matches(1000)).isFalse(); 52 assertThat(new InstanceOf(Long.class).matches(1000)).isFalse(); 53 assertThat(new InstanceOf(long.class).matches(new Integer(1000))).isFalse(); 54 assertThat(new InstanceOf(Long.class).matches(new Integer(1000))).isFalse(); 55 } 56 57 @Test can_be_vararg_aware()58 public void can_be_vararg_aware() { 59 assertThat(new InstanceOf.VarArgAware(Number[].class)).isInstanceOf(VarargMatcher.class); 60 assertThat(new InstanceOf.VarArgAware(Number[].class).matches(new Integer[0])).isTrue(); 61 assertThat(new InstanceOf.VarArgAware(Number[].class).matches(new Number[0])).isTrue(); 62 assertThat(new InstanceOf.VarArgAware(Number[].class).matches(new Object[0])).isFalse(); 63 } 64 } 65