WayWriter extends EntityWriter { public void process(Way way) { List<WayNode> wayNodes; Collection<Tag> tags; beginOpenElement(); addCommonAttributes(way); addMetatags(way); wayNodes = way.getWayNodes(); tags = way.getTags(); if (wayNodes.size() > 0 || tags.size() > 0) { endOpenElement(false); for (WayNode wayNode : wayNodes) { wayNodeWriter.processWayNode(wayNode); } for (Tag tag : tags) { tagWriter.process(tag); } closeElement(); } else { endOpenElement(true); } } WayWriter(String elementName, int indentLevel); void process(Way way); @Override void setWriter(final Writer writer);  }
@Test public final void testProcessNormalWay() { Way way = new Way(new CommonEntityData(1234, 2, timestamp, new OsmUser(23, "someuser"), 0)); way.getWayNodes().add(new WayNode(1235)); way.getWayNodes().add(new WayNode(1236)); way.getTags().add(new Tag("waykey", "wayvalue")); testWayWriter.process(way); try { testBufferedWriter.flush(); } catch (IOException e) { e.printStackTrace(); fail("IOException"); } String[] strArray = testWriter.toString().split("\\n", 5); assertTrue("Way opening element does not match.", strArray[0].matches(wayOpeningMatch)); assertTrue("Way node 1 does not match.", strArray[1].matches(wayNode1Match)); assertTrue("Way node 2 does not match.", strArray[2].matches(wayNode2Match)); assertTrue("Way tag does not match.", strArray[3].matches(wayTagMatch)); assertTrue("Way closing element does not match.", strArray[4].matches(wayClosingMatch)); }
@Test public final void testProcessWayWithNoUser() { Way way = new Way(new CommonEntityData(1234, 2, timestamp, OsmUser.NONE, 0)); way.getWayNodes().add(new WayNode(1235)); way.getWayNodes().add(new WayNode(1236)); way.getTags().add(new Tag("waykey", "wayvalue")); testWayWriter.process(way); try { testBufferedWriter.flush(); } catch (IOException e) { e.printStackTrace(); fail("IOException"); } String wayOpeningNoUserMatch = "^\\s*<way\\s*" + "id=['\"]1234['\"]\\s*" + "version=['\"]2['\"]\\s*" + "timestamp=['\"]2013-10-07T10:24:31Z?['\"]\\s*" + ">\\s*"; String[] strArray = testWriter.toString().split("\\n", 5); assertTrue("Way opening element does not match.", strArray[0].matches(wayOpeningNoUserMatch)); assertTrue("Way node 1 does not match.", strArray[1].matches(wayNode1Match)); assertTrue("Way node 2 does not match.", strArray[2].matches(wayNode2Match)); assertTrue("Way tag does not match.", strArray[3].matches(wayTagMatch)); assertTrue("Way closing element does not match.", strArray[4].matches(wayClosingMatch)); }
@Test public final void testProcessWayNoTags() { Way way = new Way(new CommonEntityData(1234, 2, timestamp, new OsmUser(23, "someuser"), 0)); way.getWayNodes().add(new WayNode(1235)); way.getWayNodes().add(new WayNode(1236)); testWayWriter.process(way); try { testBufferedWriter.flush(); } catch (IOException e) { e.printStackTrace(); fail("IOException"); } String[] strArray = testWriter.toString().split("\\n", 4); assertTrue("Way opening element does not match.", strArray[0].matches(wayOpeningMatch)); assertTrue("Way node 1 does not match.", strArray[1].matches(wayNode1Match)); assertTrue("Way node 2 does not match.", strArray[2].matches(wayNode2Match)); assertTrue("Way closing element does not match.", strArray[3].matches(wayClosingMatch)); }