@Override public void startCounts(final Counts counts, final BufferedWriter out) throws IOException { out.write("<counts "); out.write("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"); out.write("xsi:noNamespaceSchemaLocation=\"http://matsim.org/files/dtd/counts_v1.xsd\"\n"); if (counts.getName() != null) { out.write(" name=\"" + counts.getName() + "\""); } else { out.write(" name=\"\""); } if (counts.getDescription() != null) { out.write(" desc=\"" + counts.getDescription() + "\""); } out.write(" year=\"" + counts.getYear() + "\" "); out.write(" > \n"); }
Assert.assertNotNull(fixture.counts.getName());
/** * @throws SAXException * @throws ParserConfigurationException * @throws IOException * * @author mrieser */ @Test public void testWriteParse_nameIsNull() throws SAXException, ParserConfigurationException, IOException { CountsFixture f = new CountsFixture(); f.setUp(); f.counts.setName(null); Assert.assertNull(f.counts.getName()); String filename = this.utils.getOutputDirectory() + "counts.xml"; new CountsWriter(f.counts).write(filename); Counts counts2 = new Counts(); new CountsReaderMatsimV1(counts2).readFile(filename); Assert.assertEquals("", counts2.getName()); } }
public void testSEElementCounts() throws SAXException { AttributeFactory attributeFactory = new AttributeFactory(); final Counts counts = new Counts(); MatsimCountsReader reader = new MatsimCountsReader(counts); reader.setDoctype("counts_v1.xsd"); reader.startElement("", "counts", "counts", attributeFactory.createCountsAttributes()); assertEquals("Counts attribute setting failed", "testName", counts.getName()); assertEquals("Counts attribute setting failed", "testDesc", counts.getDescription()); assertEquals("Counts attribute setting failed", 2000, counts.getYear()); try { reader.endElement("", "counts", "counts"); } catch (SAXException e) { throw new RuntimeException(e); } }
public void testSECounts() { AttributeFactory attributeFactory = new AttributeFactory(); final Counts counts = new Counts(); CountsReaderMatsimV1 reader = new CountsReaderMatsimV1(counts); reader.startTag("counts", attributeFactory.createCountsAttributes(), null); assertEquals("Counts attribute setting failed", "testName", counts.getName()); assertEquals("Counts attribute setting failed", "testDesc", counts.getDescription()); assertEquals("Counts attribute setting failed", 2000, counts.getYear()); }