@Test public void addAndRemoveGenericType() throws ClassNotFoundException { JavaClassSource javaClass = Roaster.create(JavaClassSource.class); javaClass.setPackage("it.coopservice.test"); javaClass.setName("SimpleClass"); javaClass.addTypeVariable().setName("T"); Assert.assertTrue(javaClass.getTypeVariables().get(0).getBounds().isEmpty()); Assert.assertTrue(javaClass.toString().contains("<T>")); javaClass.removeTypeVariable("T"); Assert.assertFalse(javaClass.toString().contains("<T>")); }
@Test public void getClassGenericsName() throws ClassNotFoundException { JavaClassSource javaClass = Roaster.create(JavaClassSource.class); javaClass.setPackage("it.coopservice.test"); javaClass.setName("SimpleClass"); javaClass.addTypeVariable("I"); javaClass.addTypeVariable("O"); List<TypeVariableSource<JavaClassSource>> typeVariables = javaClass.getTypeVariables(); Assert.assertNotNull(typeVariables); Assert.assertEquals(2, typeVariables.size()); Assert.assertEquals("I", typeVariables.get(0).getName()); Assert.assertTrue(typeVariables.get(0).getBounds().isEmpty()); Assert.assertEquals("O", typeVariables.get(1).getName()); Assert.assertTrue(typeVariables.get(1).getBounds().isEmpty()); }