DefaultTypeNameExtractor implements TypeNameExtractor { public String nameFor(Type generic) { if (generic instanceof ParameterizedType) { return nameFor((ParameterizedType) generic); } if (generic instanceof WildcardType) { return nameFor((WildcardType) generic); } if (generic instanceof TypeVariable<?>) { return nameFor((TypeVariable<?>) generic); } return nameFor((Class<?>) generic); }  String nameFor(Type generic);  }
@Test public void shouldDecapitalizeSomeCharsUntilItFindsOneUppercased() throws NoSuchMethodException { Assert.assertEquals("urlClassLoader",extractor.nameFor(URLClassLoader.class)); Assert.assertEquals("bigDecimal",extractor.nameFor(BigDecimal.class)); Assert.assertEquals("string",extractor.nameFor(String.class)); Assert.assertEquals("aClass",extractor.nameFor(AClass.class)); Assert.assertEquals("url",extractor.nameFor(URL.class)); }
@Test public void shouldDecapitalizeSomeCharsUntilItFindsOneUppercasedForListsAndArrays() throws NoSuchMethodException, SecurityException, NoSuchFieldException { Assert.assertEquals("stringList",extractor.nameFor(getField("strings"))); Assert.assertEquals("bigDecimalList",extractor.nameFor(getField("bigs"))); Assert.assertEquals("hashSet",extractor.nameFor(getField("bigsOld"))); Assert.assertEquals("class",extractor.nameFor(getField("clazz"))); Assert.assertEquals("aClassList",extractor.nameFor(AClass[].class)); Assert.assertEquals("urlClassLoaderList",extractor.nameFor(getField("urls"))); }
@Test public void shouldDecapitalizeSomeCharsUntilItFindsOneUppercasedForListsAndArraysForBoundedGenericElements() throws NoSuchMethodException, SecurityException, NoSuchFieldException { Assert.assertEquals("bigDecimalList",extractor.nameFor(getField("bigsLimited"))); Assert.assertEquals("bigDecimalList",extractor.nameFor(getField("bigsLimited2"))); Assert.assertEquals("objectList",extractor.nameFor(getField("objects"))); }
@Test public void shouldDiscoverGenericTypeParametersWhenThereIsInheritance() throws Exception { Assert.assertEquals("t",extractor.nameFor(XController.class.getMethod("edit").getGenericReturnType())); Assert.assertEquals("tList",extractor.nameFor(XController.class.getMethod("list").getGenericReturnType())); }