@Test public void testEquals() throws Exception { TypeDescription identical = describe(SampleClass.class); assertThat(identical, is(identical)); TypeDescription equalFirst = mock(TypeDescription.class); when(equalFirst.getSort()).thenReturn(TypeDefinition.Sort.NON_GENERIC); when(equalFirst.asErasure()).thenReturn(equalFirst); when(equalFirst.getName()).thenReturn(SampleClass.class.getName()); assertThat(describe(SampleClass.class), is(equalFirst)); assertThat(describe(SampleClass.class), not(describe(SampleInterface.class))); assertThat( describe(SampleClass.class), not((TypeDescription) new TypeDescription.ForLoadedType(SampleInterface.class))); TypeDefinition nonRawType = mock(TypeDescription.Generic.class); when(nonRawType.getSort()).thenReturn(TypeDefinition.Sort.VARIABLE); assertThat(describe(SampleClass.class), not(nonRawType)); assertThat(describe(SampleClass.class), not(new Object())); assertThat(describe(SampleClass.class), not(equalTo(null))); assertThat( describe(Object[].class), is((TypeDescription) new TypeDescription.ForLoadedType(Object[].class))); assertThat(describe(Object[].class), not(TypeDescription.OBJECT)); }