Fix: else-if block was missing code, so the "user" option for console publisher was...
[jpf-core.git] / src / tests / gov / nasa / jpf / test / basic / ConsolePublisherTest.java
1 package gov.nasa.jpf.report;
2
3 import gov.nasa.jpf.util.test.TestJPF;
4
5 import java.io.ByteArrayOutputStream;
6 import java.io.PrintStream;
7
8 import org.junit.Test;
9
10 /**
11  * This class tests those methods of the ConsolePublisher class that are relevant
12  * to the report.console.start property.
13  *
14  * @author Franck van Breugel
15  */
16 public class ConsolePublisherTest extends TestJPF {
17     /**
18      * Runs the tests with the given names.
19      *
20      * @param testMethods names of the test methods to be run.
21      */
22     public static void main(String[] testMethods) {
23         runTestsOfThisClass(testMethods);
24     }
25
26     /**
27      * Tests the value dtg for the property report.console.start.
28      */
29     @Test
30     public void testDTG(){
31         PrintStream out = System.out;
32         ByteArrayOutputStream stream = new ByteArrayOutputStream();
33         System.setOut(new PrintStream(stream));
34         if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=dtg")){
35             // do nothing
36         } else {
37             System.setOut(out);
38             assertTrue("output does not contain \"started:\"", stream.toString().contains("started: "));
39         }
40     }
41
42     /**
43      * Tests the value jpf for the property report.console.start.
44      */
45     @Test
46     public void testJPF(){
47         PrintStream out = System.out;
48         ByteArrayOutputStream stream = new ByteArrayOutputStream();
49         System.setOut(new PrintStream(stream));
50         if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=jpf")){
51             // do nothing
52         } else {
53             System.setOut(out);
54             assertTrue("output does not contain \"JavaPathfinder", stream.toString().contains("JavaPathfinder"));
55         }
56     }
57
58     /**
59      * Tests the value platform for the property report.console.start.
60      */
61     @Test
62     public void testPlatform(){
63         PrintStream out = System.out;
64         ByteArrayOutputStream stream = new ByteArrayOutputStream();
65         System.setOut(new PrintStream(stream));
66         if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=platform")){
67             // do nothing
68         } else {
69             System.setOut(out);
70             assertTrue("output does not contain \"hostname:\"", stream.toString().contains("hostname: "));
71             assertTrue("output does not contain \"arch:\"", stream.toString().contains("arch: "));
72             assertTrue("output does not contain \"os:\"", stream.toString().contains("os: "));
73             assertTrue("output does not contain \"java:\"", stream.toString().contains("java: "));
74         }
75     }
76     
77        /**
78      * Tests the value sut for the property report.console.start.
79      */
80     @Test
81     public void testSUT(){
82         PrintStream out = System.out;
83         ByteArrayOutputStream stream = new ByteArrayOutputStream();
84         System.setOut(new PrintStream(stream));
85         if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=sut")){
86             // do nothing
87         } else {
88             System.setOut(out);
89             assertTrue("output does not contain \"system under test\"", stream.toString().contains("system under test"));
90         }
91     }
92
93     /**
94      * Tests the value user for the property report.console.start.
95      */
96     @Test
97     public void testUser(){
98         PrintStream out = System.out;
99         ByteArrayOutputStream stream = new ByteArrayOutputStream();
100         System.setOut(new PrintStream(stream));
101         if (verifyNoPropertyViolation("+report.publisher=console", "+report.console.start=user")){
102             // do nothing
103         } else {
104             System.setOut(out);
105             assertTrue("output does not contain \"user:\"", stream.toString().contains("user: "));
106         }
107     }
108 }