@Test public void testParsePortMappingBadSpecs() throws Exception { for (final TestData d : BAD_SPECS) { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Bad port mapping: " + d.getSpec()); PortMappingParser.parsePortMapping(d.getSpec()); } }
static PortMappingWithName parsePortMapping(final String portSpec) { final Matcher matcher = PATTERN.matcher(portSpec); if (!matcher.matches()) { throw new IllegalArgumentException("Bad port mapping: " + portSpec); } final String name = matcher.group("n"); final String ip = matcher.group("ip"); final int internal = Integer.parseInt(matcher.group("i")); final Integer external = nullOrInteger(matcher.group("e")); final String protocol = fromNullable(matcher.group("p")).or(TCP); return PortMappingWithName.create(name, PortMapping.builder() .ip(ip) .internalPort(internal) .externalPort(external) .protocol(protocol) .build()); }
PortMappingParser { static PortMappingWithName parsePortMapping(final String portSpec) { final Matcher matcher = PATTERN.matcher(portSpec); if (!matcher.matches()) { throw new IllegalArgumentException("Bad port mapping: " + portSpec); } final String name = matcher.group("n"); final String ip = matcher.group("ip"); final int internal = Integer.parseInt(matcher.group("i")); final Integer external = nullOrInteger(matcher.group("e")); final String protocol = fromNullable(matcher.group("p")).or(TCP); return PortMappingWithName.create(name, PortMapping.builder() .ip(ip) .internalPort(internal) .externalPort(external) .protocol(protocol) .build()); } }
PortMappingParser { static PortMappingWithName parsePortMapping(final String portSpec) { final Matcher matcher = PATTERN.matcher(portSpec); if (!matcher.matches()) { throw new IllegalArgumentException("Bad port mapping: " + portSpec); } final String name = matcher.group("n"); final String ip = matcher.group("ip"); final int internal = Integer.parseInt(matcher.group("i")); final Integer external = nullOrInteger(matcher.group("e")); final String protocol = fromNullable(matcher.group("p")).or(TCP); return PortMappingWithName.create(name, PortMapping.builder() .ip(ip) .internalPort(internal) .externalPort(external) .protocol(protocol) .build()); } private  PortMappingParser(); }
PortMappingParser { static PortMappingWithName parsePortMapping(final String portSpec) { final Matcher matcher = PATTERN.matcher(portSpec); if (!matcher.matches()) { throw new IllegalArgumentException("Bad port mapping: " + portSpec); } final String name = matcher.group("n"); final String ip = matcher.group("ip"); final int internal = Integer.parseInt(matcher.group("i")); final Integer external = nullOrInteger(matcher.group("e")); final String protocol = fromNullable(matcher.group("p")).or(TCP); return PortMappingWithName.create(name, PortMapping.builder() .ip(ip) .internalPort(internal) .externalPort(external) .protocol(protocol) .build()); } private  PortMappingParser();  }
PortMappingParser { static PortMappingWithName parsePortMapping(final String portSpec) { final Matcher matcher = PATTERN.matcher(portSpec); if (!matcher.matches()) { throw new IllegalArgumentException("Bad port mapping: " + portSpec); } final String name = matcher.group("n"); final String ip = matcher.group("ip"); final int internal = Integer.parseInt(matcher.group("i")); final Integer external = nullOrInteger(matcher.group("e")); final String protocol = fromNullable(matcher.group("p")).or(TCP); return PortMappingWithName.create(name, PortMapping.builder() .ip(ip) .internalPort(internal) .externalPort(external) .protocol(protocol) .build()); } private  PortMappingParser();   }