From d275f72b1878404b0b4d80a4845969d3370f0e06 Mon Sep 17 00:00:00 2001 From: Cyrille Artho Date: Thu, 3 Jan 2019 22:25:23 +0900 Subject: [PATCH] Fix: else-if block was missing code, so the "user" option for console publisher was defunct. Fixed incl. unit tests (thanks to Franck for both). --- src/main/gov/nasa/jpf/report/Publisher.java | 1 + .../jpf/test/basic/ConsolePublisherTest.java | 108 ++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 src/tests/gov/nasa/jpf/test/basic/ConsolePublisherTest.java diff --git a/src/main/gov/nasa/jpf/report/Publisher.java b/src/main/gov/nasa/jpf/report/Publisher.java index 3935bfc..ceb827c 100644 --- a/src/main/gov/nasa/jpf/report/Publisher.java +++ b/src/main/gov/nasa/jpf/report/Publisher.java @@ -248,6 +248,7 @@ public abstract class Publisher { } else if ("platform".equalsIgnoreCase(item)){ publishPlatform(); } else if ("user".equalsIgnoreCase(item)) { + publishUser(); } else if ("dtg".equalsIgnoreCase(item)) { publishDTG(); } else if ("config".equalsIgnoreCase(item)){ diff --git a/src/tests/gov/nasa/jpf/test/basic/ConsolePublisherTest.java b/src/tests/gov/nasa/jpf/test/basic/ConsolePublisherTest.java new file mode 100644 index 0000000..30346f3 --- /dev/null +++ b/src/tests/gov/nasa/jpf/test/basic/ConsolePublisherTest.java @@ -0,0 +1,108 @@ +package gov.nasa.jpf.report; + +import gov.nasa.jpf.util.test.TestJPF; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import org.junit.Test; + +/** + * This class tests those methods of the ConsolePublisher class that are relevant + * to the report.console.start property. + * + * @author Franck van Breugel + */ +public class ConsolePublisherTest extends TestJPF { + /** + * Runs the tests with the given names. + * + * @param testMethods names of the test methods to be run. + */ + public static void main(String[] testMethods) { + runTestsOfThisClass(testMethods); + } + + /** + * Tests the value dtg for the property report.console.start. + */ + @Test + public void testDTG(){ + PrintStream out = System.out; + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stream)); + if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=dtg")){ + // do nothing + } else { + System.setOut(out); + assertTrue("output does not contain \"started:\"", stream.toString().contains("started: ")); + } + } + + /** + * Tests the value jpf for the property report.console.start. + */ + @Test + public void testJPF(){ + PrintStream out = System.out; + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stream)); + if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=jpf")){ + // do nothing + } else { + System.setOut(out); + assertTrue("output does not contain \"JavaPathfinder", stream.toString().contains("JavaPathfinder")); + } + } + + /** + * Tests the value platform for the property report.console.start. + */ + @Test + public void testPlatform(){ + PrintStream out = System.out; + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stream)); + if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=platform")){ + // do nothing + } else { + System.setOut(out); + assertTrue("output does not contain \"hostname:\"", stream.toString().contains("hostname: ")); + assertTrue("output does not contain \"arch:\"", stream.toString().contains("arch: ")); + assertTrue("output does not contain \"os:\"", stream.toString().contains("os: ")); + assertTrue("output does not contain \"java:\"", stream.toString().contains("java: ")); + } + } + + /** + * Tests the value sut for the property report.console.start. + */ + @Test + public void testSUT(){ + PrintStream out = System.out; + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stream)); + if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=sut")){ + // do nothing + } else { + System.setOut(out); + assertTrue("output does not contain \"system under test\"", stream.toString().contains("system under test")); + } + } + + /** + * Tests the value user for the property report.console.start. + */ + @Test + public void testUser(){ + PrintStream out = System.out; + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + System.setOut(new PrintStream(stream)); + if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=user")){ + // do nothing + } else { + System.setOut(out); + assertTrue("output does not contain \"user:\"", stream.toString().contains("user: ")); + } + } +} -- 2.34.1