/** * {@inheritDoc} */ public void process(BoundContainer bound) { if (boundWritten) { throw new OsmosisRuntimeException("Bound element already written and only one allowed."); } if (entitiesWritten) { throw new OsmosisRuntimeException("Can't write bound element after other entities."); } boundWriter.process(bound.getEntity()); boundWritten = true; } }
/** * {@inheritDoc} */ public void process(BoundContainer bound) { if (boundWritten) { throw new OsmosisRuntimeException("Bound element already written and only one allowed."); } if (entitiesWritten) { throw new OsmosisRuntimeException("Can't write bound element after other entities."); } boundWriter.process(bound.getEntity()); boundWritten = true; } }
/** * Test non-writing of a Bound element with an empty origin string. */ @Test public final void testProcess2() { BoundWriter bw = new BoundWriter("bound", 2, true); bw.setWriter(testBufferedWriter); bw.process(new Bound(20.123456, -21.987654, 22.555555, -23.234567, "")); try { testBufferedWriter.flush(); } catch (IOException e) { e.printStackTrace(); fail("IOException"); } assertTrue(testWriter.toString().equals("")); // not written; empty string } }
/** * Test writing out a normal Bound element. */ @Test public final void testProcess1() { BoundWriter bw = new BoundWriter("bound", 2, true); bw.setWriter(testBufferedWriter); bw.process(new Bound(20.123456, -21.987654, 22.555555, -23.234567, "originstring")); try { testBufferedWriter.flush(); } catch (IOException e) { e.printStackTrace(); fail("IOException"); } // If this test fails, it could be because the regex has broken. There are a number of // variations which are valid XML which this regex won't catch. It might need any number of // \\s* to account for variable whitespace. String regexMatch = "^\\s*<bound\\s*" + "box=['\"]-23.23457,-21.98765,22.55556,20.12346['\"]\\s*" + "origin=['\"]originstring['\"]/>\\s*$"; assertTrue(testWriter.toString().matches(regexMatch)); }