### Question:
JsonToImageTranslator { @VisibleForTesting static ImmutableSet<Port> portMapToSet(@Nullable Map<String, Map<?, ?>> portMap) throws BadContainerConfigurationFormatException { if (portMap == null) { return ImmutableSet.of(); } ImmutableSet.Builder<Port> ports = new ImmutableSet.Builder<>(); for (Map.Entry<String, Map<?, ?>> entry : portMap.entrySet()) { String port = entry.getKey(); Matcher matcher = PORT_PATTERN.matcher(port); if (!matcher.matches()) { throw new BadContainerConfigurationFormatException( "Invalid port configuration: '" + port + "'."); } int portNumber = Integer.parseInt(matcher.group("portNum")); String protocol = matcher.group("protocol"); ports.add(Port.parseProtocol(portNumber, protocol)); } return ports.build(); } private  JsonToImageTranslator(); static Image toImage(V21ManifestTemplate manifestTemplate); static Image toImage(
      BuildableManifestTemplate manifestTemplate,
      ContainerConfigurationTemplate containerConfigurationTemplate);  }### Answer:
@Test public void testPortMapToList() throws BadContainerConfigurationFormatException { ImmutableSortedMap<String, Map<?, ?>> input = ImmutableSortedMap.of( "1000", ImmutableMap.of(), "2000/tcp", ImmutableMap.of(), "3000/udp", ImmutableMap.of()); ImmutableSet<Port> expected = ImmutableSet.of(Port.tcp(1000), Port.tcp(2000), Port.udp(3000)); Assert.assertEquals(expected, JsonToImageTranslator.portMapToSet(input)); ImmutableList<Map<String, Map<?, ?>>> badInputs = ImmutableList.of( ImmutableMap.of("abc", ImmutableMap.of()), ImmutableMap.of("1000-2000", ImmutableMap.of()), ImmutableMap.of("/udp", ImmutableMap.of()), ImmutableMap.of("123/xxx", ImmutableMap.of())); for (Map<String, Map<?, ?>> badInput : badInputs) { try { JsonToImageTranslator.portMapToSet(badInput); Assert.fail(); } catch (BadContainerConfigurationFormatException ignored) { } } }