StringToEnvelopeConverter implements Converter<String, Envelope> { public Envelope convert(String source) { if (source == null) { return null; } else { String[] args = source.trim().split("[\\s,]+"); if (args.length != 4) { throw new IllegalArgumentException("Cannot parse envelope from " + source + ", expected format is \"xmin,ymin,xmax,ymax\""); } else { double[] coords = new double[4]; try { for (int i = 0; i < coords.length; i++) { coords[i] = Double.parseDouble(args[i]); } return new Envelope(coords[0], coords[1], coords[2], coords[3]); } catch (NumberFormatException nfe) { throw new IllegalArgumentException("Cannot parse envelope from " + source + ", expected format is \"xmin,ymin,xmax,ymax\"", nfe); } } } }  Envelope convert(String source);  }
@Test public void testConvertWithoutWhitespace() { StringToEnvelopeConverter converter= new StringToEnvelopeConverter(); Envelope result = converter.convert("1.1,2.2,3.3333,4"); Assert.assertEquals(new Envelope(1.1,2.2,3.3333,4), result); }
@Test public void testConvertWithWhitespace() { StringToEnvelopeConverter converter= new StringToEnvelopeConverter(); Envelope result = converter.convert(" \n 1.1, 2.2\t,\n3.3333 ,4 \n \t "); Assert.assertEquals(new Envelope(1.1,2.2,3.3333,4), result); }