示例#1
0
 @Override
 public ISpecies getParentSpecies() {
   if (parentSpecies == null) {
     final TypeDescription parentSpecDesc = getDescription().getParent();
     // Takes care of invalid species (see Issue 711)
     if (parentSpecDesc == null || parentSpecDesc == getDescription()) {
       return null;
     }
     ISpecies currentMacroSpec = this.getMacroSpecies();
     while (currentMacroSpec != null && parentSpecies == null) {
       parentSpecies = currentMacroSpec.getMicroSpecies(parentSpecDesc.getName());
       currentMacroSpec = currentMacroSpec.getMacroSpecies();
     }
   }
   return parentSpecies;
 }
 @Test
 public void testEquals() throws Exception {
   TypeDescription identical = describe(SampleClass.class);
   assertThat(identical, equalTo(identical));
   TypeDescription equalFirst = mock(TypeDescription.class);
   when(equalFirst.getName()).thenReturn(SampleClass.class.getName());
   assertThat(describe(SampleClass.class), equalTo(equalFirst));
   assertThat(describe(SampleClass.class), not(equalTo(describe(SampleInterface.class))));
   assertThat(
       describe(SampleClass.class),
       not(equalTo((TypeDescription) new TypeDescription.ForLoadedType(SampleInterface.class))));
   assertThat(describe(SampleClass.class), not(equalTo(new Object())));
   assertThat(describe(SampleClass.class), not(equalTo(null)));
   assertThat(
       describe(Object[].class),
       equalTo((TypeDescription) new TypeDescription.ForLoadedType(Object[].class)));
   assertThat(
       describe(Object[].class),
       not(equalTo((TypeDescription) new TypeDescription.ForLoadedType(Object.class))));
 }
 @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));
 }