TypeTransformerFactory { public TypeTransformer getTransformer(Class<?> targetClass) { TypeTransformer normaliser = transformers.get(targetClass); if (normaliser == null) { Class<?> bestCandidate = findClosestAncestor(targetClass); if (bestCandidate != null) { normaliser = transformers.get(bestCandidate); transformers.put(targetClass, normaliser); } } return normaliser; }  void setTransformer(Class<?> targetClass, TypeTransformer normaliser); TypeTransformer getTransformer(Class<?> targetClass);  }
@Test public void normaliserLookupReturnsClosestParentIfNoExactMatch() { TypeTransformer normaliser = ttf.getTransformer(clow); assertEquals(normaliserMid, normaliser); }
@Test public void normaliserLookupReturnsExactMatchIfAny() { TypeTransformer normaliser = ttf.getTransformer(cmid); assertEquals(normaliserMid, normaliser); normaliser = ttf.getTransformer(ctop); assertEquals(normaliserTop, normaliser); }
@Test public void normaliserLookupReturnsNullWhenNolExactMatchNorParents() { TypeTransformer normaliser = ttf.getTransformer(String.class); assertNull(normaliser); }