### Question:
ScanMappingToScanConfigTransformer { public ScanConfig transform(List<ScanMapping> mappings) { ScanConfig config = new ScanConfig(); if (mappings==null || mappings.size()==0) { return config; } for (ScanMapping mapping: mappings) { MappingData data = MappingData.fromString(mapping.getData()); config.getNamePatternMappings().put(mapping.getId(), convert(data)); } return config; }  ScanConfig transform(List<ScanMapping> mappings);  }### Answer:
@Test public void null_transformed_to_config() { ScanConfig result = transformerToTest.transform(null); assertNotNull(result); assertEquals(0, result.getNamePatternMappings().size()); }
@Test public void empty_list_transformed_to_config() { ScanConfig result = transformerToTest.transform(new ArrayList<>()); assertNotNull(result); assertEquals(0, result.getNamePatternMappings().size()); }
@Test public void one_mapping_containing_one_entry_transformed_to_config() { ScanMapping mapping1 = createMapping("id1",new MappingEntry("pattern1","replacement1","comment1")); ScanConfig result = transformerToTest.transform(Collections.singletonList(mapping1)); assertNotNull(result); assertEquals(1, result.getNamePatternMappings().size()); List<NamePatternToIdEntry> namePatternList = result.getNamePatternMappings().get("id1"); assertEquals(1,namePatternList.size()); NamePatternToIdEntry first = namePatternList.get(0); assertEquals("pattern1", first.getNamePattern()); assertEquals("replacement1", first.getId()); }
@Test public void one_mapping_containing_two_entries_transformed_to_config() { ScanMapping mapping1 = createMapping("id1",new MappingEntry("pattern1","replacement1","comment1"),new MappingEntry("pattern2","replacement2","comment2")); ScanConfig result = transformerToTest.transform(Collections.singletonList(mapping1)); assertNotNull(result); assertEquals(1, result.getNamePatternMappings().size()); List<NamePatternToIdEntry> namePatternList = result.getNamePatternMappings().get("id1"); assertEquals(2,namePatternList.size()); NamePatternToIdEntry first = namePatternList.get(0); assertEquals("pattern1", first.getNamePattern()); assertEquals("replacement1", first.getId()); NamePatternToIdEntry second = namePatternList.get(1); assertEquals("pattern2", second.getNamePattern()); assertEquals("replacement2", second.getId()); }
@Test public void two_mappings_containing_four_entries_transformed_to_config() { ScanMapping mapping1 = createMapping("id1",new MappingEntry("pattern1","replacement1","comment1"),new MappingEntry("pattern2","replacement2","comment2")); ScanMapping mapping2 = createMapping("id2",new MappingEntry("pattern3","replacement3",null),new MappingEntry("pattern4","replacement4",null)); List<ScanMapping> list = new ArrayList<>(); list.add(mapping1); list.add(mapping2); ScanConfig result = transformerToTest.transform(list); assertNotNull(result); assertEquals(2, result.getNamePatternMappings().size()); List<NamePatternToIdEntry> namePatternList1 = result.getNamePatternMappings().get("id1"); assertEquals(2,namePatternList1.size()); NamePatternToIdEntry first = namePatternList1.get(0); assertEquals("pattern1", first.getNamePattern()); assertEquals("replacement1", first.getId()); NamePatternToIdEntry second = namePatternList1.get(1); assertEquals("pattern2", second.getNamePattern()); assertEquals("replacement2", second.getId()); List<NamePatternToIdEntry> namePatternList2 = result.getNamePatternMappings().get("id2"); assertEquals(2,namePatternList2.size()); NamePatternToIdEntry first2 = namePatternList2.get(0); assertEquals("pattern3", first2.getNamePattern()); assertEquals("replacement3", first2.getId()); NamePatternToIdEntry second2 = namePatternList2.get(1); assertEquals("pattern4", second2.getNamePattern()); assertEquals("replacement4", second2.getId()); }