### Question:
PortRanges { public static PortRange fromString(String s) { List<PortRange> l = new ArrayList<PortRange>(); for (String si: s.split(",")) { si = si.trim(); int start, end; if (si.endsWith("+")) { String si2 = si.substring(0, si.length()-1).trim(); start = Integer.parseInt(si2); end = MAX_PORT; } else if (si.indexOf('-')>0) { int v = si.indexOf('-'); start = Integer.parseInt(si.substring(0, v).trim()); end = Integer.parseInt(si.substring(v+1).trim()); } else if (si.length()==0) { continue; } else { l.add(new SinglePort(Integer.parseInt(si))); continue; } l.add(new LinearPortRange(start, end)); } if (l.size() == 1) { return l.get(0); } else { return new AggregatePortRange(l); } }  static PortRange fromInteger(int x); static PortRange fromIterable(Iterable<?> c); static PortRange fromString(String s); @SuppressWarnings("rawtypes") static void init(); static final int MAX_PORT; static final PortRange ANY_HIGH_PORT; }### Answer:
@Test public void testFromString() { PortRange r = PortRanges.fromString("80,8080,8000,8080-8099"); assertContents(r, 80, 8080, 8000, 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089, 8090, 8091, 8092, 8093, 8094, 8095, 8096, 8097, 8098, 8099); }
@Test public void testFromStringWithSpaces() { PortRange r = PortRanges.fromString(" 80 , 8080 , 8000 , 8080 - 8099 "); assertContents(r, 80, 8080, 8000, 8080, 8081, 8082, 8083, 8084, 8085, 8086, 8087, 8088, 8089, 8090, 8091, 8092, 8093, 8094, 8095, 8096, 8097, 8098, 8099); }
@Test public void testFromStringWithSpacesToString() { PortRange r = PortRanges.fromString(" 80 , 8080 , 8000 , 8080 - 8099 "); Assert.assertEquals(r.toString(), "80,8080,8000,8080-8099"); }