### Question:
PortMappingParser { static Map<String, PortMapping> parsePortMappings(final List<String> portSpecs) { final Map<String, PortMapping> explicitPorts = Maps.newHashMap(); for (final String spec : portSpecs) { final PortMappingWithName portMappingWithName = parsePortMapping(spec); final String name = portMappingWithName.name(); if (explicitPorts.containsKey(name)) { throw new IllegalArgumentException("Duplicate port mapping name: " + name); } explicitPorts.put(name, portMappingWithName.portMapping()); } return ImmutableMap.copyOf(explicitPorts); } private  PortMappingParser();   }### Answer:
@Test public void testParsePortMappings() throws Exception { final Map<String, PortMapping> mappings = PortMappingParser.parsePortMappings(testDataToSpecs(GOOD_SPECS)); final Map<String, PortMapping> expectedMappings = new HashMap<>(); for (final TestData d : GOOD_SPECS) { expectedMappings.put(d.getName(), d.getPortMapping()); } assertThat(mappings, equalTo(expectedMappings)); }
@Test public void testParsePortMappingsDuplicateName() throws Exception { final ImmutableList<TestData> specs = ImmutableList.<TestData>builder() .addAll(GOOD_SPECS) .add(GOOD_SPECS.get(0)) .build(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Duplicate port mapping name: " + GOOD_SPECS.get(0).getName()); PortMappingParser.parsePortMappings(testDataToSpecs(specs)); }