| 25 | import net.sourceforge.pmd.stat.Metric; |
| 26 | |
| 27 | public class ReportTest implements ThreadSafeReportListener { |
| 28 | |
| 29 | private boolean violationSemaphore; |
| 30 | private boolean metricSemaphore; |
| 31 | |
| 32 | @Override |
| 33 | public void ruleViolationAdded(RuleViolation ruleViolation) { |
| 34 | violationSemaphore = true; |
| 35 | } |
| 36 | |
| 37 | @Override |
| 38 | public void metricAdded(Metric metric) { |
| 39 | metricSemaphore = true; |
| 40 | } |
| 41 | |
| 42 | @Test |
| 43 | public void testMetric0() { |
| 44 | Report r = new Report(); |
| 45 | assertFalse("Default report shouldn't contain metrics", r.hasMetrics()); |
| 46 | } |
| 47 | |
| 48 | @Test |
| 49 | public void testMetric1() { |
| 50 | Report r = new Report(); |
| 51 | assertFalse("Default report shouldn't contain metrics", r.hasMetrics()); |
| 52 | |
| 53 | r.addMetric(new Metric("m1", 0, 0.0, 1.0, 2.0, 3.0, 4.0)); |
| 54 | assertTrue("Expected metrics weren't there", r.hasMetrics()); |
| 55 | |
| 56 | Iterator<Metric> ms = r.metrics(); |
| 57 | assertTrue("Should have some metrics in there now", ms.hasNext()); |
| 58 | |
| 59 | Object o = ms.next(); |
| 60 | assertTrue("Expected Metric, got " + o.getClass(), o instanceof Metric); |
| 61 | |
| 62 | Metric m = (Metric) o; |
| 63 | assertEquals("metric name mismatch", "m1", m.getMetricName()); |
| 64 | assertEquals("wrong low value", 1.0, m.getLowValue(), 0.05); |
| 65 | assertEquals("wrong high value", 2.0, m.getHighValue(), 0.05); |
| 66 | assertEquals("wrong avg value", 3.0, m.getAverage(), 0.05); |
| 67 | assertEquals("wrong std dev value", 4.0, m.getStandardDeviation(), 0.05); |
| 68 | } |
| 69 | |
| 70 | // Files are grouped together now. |
| 71 | @Test |
| 72 | public void testSortedReportFile() throws IOException { |
| 73 | Report r = new Report(); |
| 74 | RuleContext ctx = new RuleContext(); |
| 75 | ctx.setSourceCodeFile(new File("foo")); |
| 76 | Node s = getNode(10, 5); |
| 77 | Rule rule1 = new MockRule("name", "desc", "msg", "rulesetname"); |
| 78 | r.addRuleViolation(new ParametricRuleViolation<>(rule1, ctx, s, rule1.getMessage())); |
| 79 | ctx.setSourceCodeFile(new File("bar")); |
| 80 | Node s1 = getNode(10, 5); |
| 81 | Rule rule2 = new MockRule("name", "desc", "msg", "rulesetname"); |
| 82 | r.addRuleViolation(new ParametricRuleViolation<>(rule2, ctx, s1, rule2.getMessage())); |
| 83 | Renderer rend = new XMLRenderer(); |
| 84 | String result = render(rend, r); |
nothing calls this directly
no outgoing calls
no test coverage detected