@Override public List<Failure> loadFailures(InputStream report) { try { CheckstyleReportHandler handler = new CheckstyleReportHandler(); XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader(); xmlReader.setContentHandler(handler); xmlReader.parse(new InputSource(report)); return handler.failures(); } catch (SAXException | ParserConfigurationException | IOException e) { throw new AssertionError(e); } } };
checkstyle, timer, XmlReportFailuresSupplier.create(checkstyle, new CheckstyleReportHandler()), Paths.get(circleReportsDir, "checkstyle"))); proj.getTasks().withType(JavaCompile.class, javac ->
@Test public void translatesCheckstyleReport() throws IOException, TransformerException { Project project = ProjectBuilder.builder().withName("fooproject").withProjectDir(projectDir.getRoot()).build(); Checkstyle checkstyle = createCheckstyleTask(project); checkstyle.setDidWork(true); StyleTaskTimer timer = mock(StyleTaskTimer.class); when(timer.getTaskTimeNanos(checkstyle)).thenReturn(FAILED_CHECKSTYLE_TIME_NANOS); File targetFile = new File(projectDir.getRoot(), "reports/report.xml"); CircleStyleFinalizer finalizer = (CircleStyleFinalizer) project .task(ImmutableMap.of("type", CircleStyleFinalizer.class), "checkstyleTestCircleFinalizer"); finalizer.setStyleTask(checkstyle); finalizer.setStyleTaskTimer(timer); finalizer.setFailuresSupplier(XmlReportFailuresSupplier.create(checkstyle, new CheckstyleReportHandler())); finalizer.setTargetFile(targetFile); finalizer.createCircleReport(); String report = Resources.toString(targetFile.toURI().toURL(), UTF_8); String expectedReport = Resources.toString(testFile("two-namecheck-failures-checkstyle-report.xml"), UTF_8); assertThat(report).isEqualTo(expectedReport); }
@Test public void testNoErrors() throws IOException { List<Failure> failures = parseXml(new CheckstyleReportHandler(), testFile("no-failures-checkstyle.xml").openStream()) .failures(); assertThat(failures).isEmpty(); }
@Test public void translatesCheckstyleReport() throws IOException, TransformerException { Project project = ProjectBuilder.builder().withName("fooproject").withProjectDir(projectDir.getRoot()).build(); Checkstyle checkstyle = createCheckstyleTask(project); checkstyle.setDidWork(true); TaskTimer timer = mock(TaskTimer.class); when(timer.getTaskTimeNanos(checkstyle)).thenReturn(FAILED_CHECKSTYLE_TIME_NANOS); File targetFile = new File(projectDir.getRoot(), "reports/report.xml"); CircleStyleFinalizer finalizer = (CircleStyleFinalizer) project .task(ImmutableMap.of("type", CircleStyleFinalizer.class), "checkstyleTestCircleFinalizer"); finalizer.setStyleTask(checkstyle); finalizer.setTaskTimer(timer); finalizer.setFailuresSupplier(XmlReportFailuresSupplier.create(checkstyle, new CheckstyleReportHandler())); finalizer.setTargetFile(targetFile); finalizer.createCircleReport(); String report = Resources.toString(targetFile.toURI().toURL(), StandardCharsets.UTF_8) .replaceAll("\\p{Blank}*(?=<)", ""); String expectedReport = Resources.toString( testFile("two-namecheck-failures-checkstyle-report.xml"), StandardCharsets.UTF_8); assertThat(report).isEqualTo(expectedReport); }
@Test public void testNoErrors() throws IOException { List<Failure> failures = parseXml(new CheckstyleReportHandler(), testFile("no-failures-checkstyle.xml").openStream()) .failures(); assertThat(failures).isEmpty(); }
@Test public void doesNothingIfTaskSkipped() throws IOException, TransformerException { Project project = ProjectBuilder.builder().withName("fooproject").withProjectDir(projectDir.getRoot()).build(); Checkstyle checkstyle = createCheckstyleTask(project); checkstyle.setDidWork(false); TaskTimer timer = mock(TaskTimer.class); when(timer.getTaskTimeNanos(checkstyle)).thenReturn(FAILED_CHECKSTYLE_TIME_NANOS); File targetFile = new File(projectDir.getRoot(), "reports/report.xml"); CircleStyleFinalizer finalizer = (CircleStyleFinalizer) project .task(ImmutableMap.of("type", CircleStyleFinalizer.class), "checkstyleTestCircleFinalizer"); finalizer.setStyleTask(checkstyle); finalizer.setTaskTimer(timer); finalizer.setFailuresSupplier(XmlReportFailuresSupplier.create(checkstyle, new CheckstyleReportHandler())); finalizer.setTargetFile(targetFile); finalizer.createCircleReport(); assertThat(targetFile).doesNotExist(); assertThat(finalizer.getDidWork()).isFalse(); }
@Test public void testTwoErrors() throws IOException { List<Failure> failures = parseXml(new CheckstyleReportHandler(), testFile("two-namecheck-failures-checkstyle.xml").openStream()) .failures(); assertThat(failures).containsExactlyElementsOf(CHECKSTYLE_FAILURES); } }
@Test public void doesNothingIfTaskSkipped() throws IOException, TransformerException { Project project = ProjectBuilder.builder().withName("fooproject").withProjectDir(projectDir.getRoot()).build(); Checkstyle checkstyle = createCheckstyleTask(project); checkstyle.setDidWork(false); StyleTaskTimer timer = mock(StyleTaskTimer.class); when(timer.getTaskTimeNanos(checkstyle)).thenReturn(FAILED_CHECKSTYLE_TIME_NANOS); File targetFile = new File(projectDir.getRoot(), "reports/report.xml"); CircleStyleFinalizer finalizer = (CircleStyleFinalizer) project .task(ImmutableMap.of("type", CircleStyleFinalizer.class), "checkstyleTestCircleFinalizer"); finalizer.setStyleTask(checkstyle); finalizer.setStyleTaskTimer(timer); finalizer.setFailuresSupplier(XmlReportFailuresSupplier.create(checkstyle, new CheckstyleReportHandler())); finalizer.setTargetFile(targetFile); finalizer.createCircleReport(); assertThat(targetFile).doesNotExist(); assertThat(finalizer.getDidWork()).isFalse(); }
@Test public void testTwoErrors() throws IOException { List<Failure> failures = parseXml(new CheckstyleReportHandler(), testFile("two-namecheck-failures-checkstyle.xml").openStream()) .failures(); assertThat(failures).containsExactlyElementsOf(CHECKSTYLE_FAILURES); } }