TagMapper implements Transformer { public static TagMapper getMapper(Field field) { if (field == null) { throw new NullPointerException("field must be one of Name, ID, Type or Owner."); } return new TagMapper(field); } private  TagMapper(Field field); static TagMapper getMapper(Field field); @Override String transform(Object obj); String transform(Tag tag); List<String> map(List<Tag> tags);  }
@Test public void badField() { try { TagMapper.getMapper(null); fail("Expected failure"); } catch (NullPointerException e) { } }
@Test public void apacheCollectionsIntegration() { Transformer tm = TagMapper.getMapper(Field.Name); @SuppressWarnings("unchecked") Collection<String> names = CollectionUtils.collect(tags, tm); List<String> expected = Arrays.asList( "tagName_0", "tagName_1", "tagName_2", "tagName_3", "tagName_4", "tagName_5", "tagName_6", "tagName_7", "tagName_8", "tagName_9" ); assertEquals(expected, names); }