PageRenderTime 68ms CodeModel.GetById 59ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/testability-explorer/src/test/java/com/google/test/metric/report/XMLReportLoaderTest.java

http://testability-explorer.googlecode.com/
Java | 68 lines | 51 code | 11 blank | 6 comment | 0 complexity | 4cec4ef4f40536d560b633ac6aee8a9a MD5 | raw file
 1package com.google.test.metric.report;
 2
 3import java.io.Reader;
 4import java.io.StringReader;
 5
 6import junit.framework.TestCase;
 7
 8import org.w3c.dom.Document;
 9import org.xml.sax.SAXException;
10
11/**
12 * Tests for {@link XMLReportLoader}.
13 *
14 * @author alexeagle@google.com (Alex Eagle)
15 */
16public class XMLReportLoaderTest extends TestCase {
17  private XMLReportLoader loader;
18
19  @Override
20  protected void setUp() throws Exception {
21    super.setUp();
22    loader = new XMLReportLoader();
23  }
24
25  public void testReadBlank() throws Exception {
26    try {
27      loader.loadXML(new StringReader(""));
28      fail("Should throw exception on empty document");
29    } catch (SAXException e) {
30      // expected
31    }
32  }
33
34  public void testSingleClass() throws Exception {
35    Reader in = new StringReader("<class></class>");
36    Document classCosts = loader.loadXML(in);
37    assertEquals(1, classCosts.getChildNodes().getLength());
38    assertEquals("class", classCosts.getChildNodes().item(0).getNodeName());
39  }
40
41  public void testClassWithCost() throws Exception {
42    Reader in = new StringReader("<class cost=\"12\" class=\"com.google.Foobar\"></class>");
43    Document classCosts = loader.loadXML(in);
44    assertEquals("12", classCosts.getElementsByTagName("class").
45        item(0).getAttributes().getNamedItem("cost").getNodeValue());
46    assertEquals("com.google.Foobar", classCosts.getElementsByTagName("class").
47            item(0).getAttributes().getNamedItem("class").getNodeValue());
48
49  }
50
51  public void testMethods() throws Exception {
52    Reader in = new StringReader("<class cost=\"12\">" +
53        "<method cyclomatic=\"2\" global=\"2\" line=\"123\" "
54        + "lod=\"0\" name=\"methodName\" overall=\"22\"></method></class>");
55    Document classCosts = loader.loadXML(in);
56    assertEquals("22", classCosts.getElementsByTagName("method").
57        item(0).getAttributes().getNamedItem("overall").getNodeValue());
58    assertEquals("methodName", classCosts.getElementsByTagName("method").
59            item(0).getAttributes().getNamedItem("name").getNodeValue());
60    assertEquals("2", classCosts.getElementsByTagName("method").
61            item(0).getAttributes().getNamedItem("cyclomatic").getNodeValue());
62    assertEquals("123", classCosts.getElementsByTagName("method").
63            item(0).getAttributes().getNamedItem("line").getNodeValue());
64    assertEquals("2", classCosts.getElementsByTagName("method").
65            item(0).getAttributes().getNamedItem("global").getNodeValue());
66
67  }
68}