@Test public void parseReportShouldReturnNullWhenXMLFileIsIncorrect() { LizardReportParser parser = new LizardReportParser(); assertNotNull("correct file is null", incorrectFile); Map<String, List<Measure>> report = parser.parseReport(incorrectFile); assertNull("report is not null", report); }
@Test public void parseReportShouldReturnMapWhenXMLFileIsCorrect() { LizardReportParser parser = new LizardReportParser(); assertNotNull("correct file is null", correctFile); Map<String, List<Measure>> report = parser.parseReport(correctFile); assertNotNull("report is null", report); assertTrue( "Key is not there", report.containsKey("App/Controller/Accelerate/AccelerationViewController.h")); List<Measure> list1 = report.get("App/Controller/Accelerate/AccelerationViewController.h"); assertEquals(4, list1.size()); for (Measure measure : list1) { String s = measure.getMetric().getKey(); if (s.equals(CoreMetrics.FUNCTIONS_KEY)) { assertEquals("Header Functions has a wrong value", 0, measure.getIntValue().intValue()); } else if (s.equals(CoreMetrics.COMPLEXITY_KEY)) { assertEquals("Header Complexity has a wrong value", 0, measure.getIntValue().intValue()); } else if (s.equals(CoreMetrics.FILE_COMPLEXITY_KEY)) { assertEquals( "Header File Complexity has a wrong value", 0.0d, measure.getValue().doubleValue(), 0.0d); } else if (s.equals(CoreMetrics.COMPLEXITY_IN_FUNCTIONS_KEY)) { assertEquals( "Header Complexity in Functions has a wrong value", 0, measure.getIntValue().intValue()); } else if (s.equals(CoreMetrics.FUNCTION_COMPLEXITY_KEY)) { assertEquals( "Header Functions Complexity has a wrong value", 0.0d, measure.getValue().doubleValue(), 0.0d); } } assertTrue( "Key is not there", report.containsKey("App/Controller/Accelerate/AccelerationViewController.m")); List<Measure> list2 = report.get("App/Controller/Accelerate/AccelerationViewController.m"); assertEquals(7, list2.size()); for (Measure measure : list2) { String s = measure.getMetric().getKey(); if (s.equals(CoreMetrics.FUNCTIONS_KEY)) { assertEquals("MFile Functions has a wrong value", 2, measure.getIntValue().intValue()); } else if (s.equals(CoreMetrics.COMPLEXITY_KEY)) { assertEquals("MFile Complexity has a wrong value", 6, measure.getIntValue().intValue()); } else if (s.equals(CoreMetrics.FILE_COMPLEXITY_KEY)) { assertEquals( "MFile File Complexity has a wrong value", 6.0d, measure.getValue().doubleValue(), 0.0d); } else if (s.equals(CoreMetrics.COMPLEXITY_IN_FUNCTIONS_KEY)) { assertEquals( "MFile Complexity in Functions has a wrong value", 6, measure.getIntValue().intValue()); } else if (s.equals(CoreMetrics.FUNCTION_COMPLEXITY_KEY)) { assertEquals( "MFile Functions Complexity has a wrong value", 3.0d, measure.getValue().doubleValue(), 0.0d); } } }