Fixing a few bugs in the statistics printout.
[jpf-core.git] / src / tests / ReporterResourcesTest.java
1 import java.io.BufferedReader;
2 import java.io.IOException;
3 import java.io.InputStream;
4 import java.io.InputStreamReader;
5
6 import org.junit.Before;
7 import org.junit.Test;
8
9 import gov.nasa.jpf.Config;
10 import gov.nasa.jpf.JPF;
11 import gov.nasa.jpf.util.test.TestJPF;
12
13 /**
14  * This is a plain JUnit test to check whether required resource files exist on
15  * JPF classpath.
16  *
17  * @author Jeanderson Candido
18  *
19  */
20 public class ReporterResourcesTest extends TestJPF {
21
22   private JPF jpf;
23
24   @Before
25   public void setup() {
26     String[] configArgs = { "+vm.class=.vm.MultiProcessVM", "+target.1=HelloWorld", "+target.2=HelloWorld" };
27     this.jpf = new JPF(new Config(configArgs));
28   }
29
30   @Test
31   public void checkResources() throws IOException {
32     assertNotNull("build.properties should exist on classpath", jpf.getClass().getResourceAsStream("build.properties"));
33     assertNotNull(".version should exist on classpath", jpf.getClass().getResourceAsStream(".version"));
34   }
35
36   @Test
37   public void hashMustExist() {
38     InputStream stream = jpf.getClass().getResourceAsStream(".version");
39     assertTrue(".version file should be non-empty", !readContentFrom(stream).trim().isEmpty());
40   }
41
42   private String readContentFrom(InputStream stream) {
43     BufferedReader buffer = new BufferedReader(new InputStreamReader(stream));
44     StringBuilder output = new StringBuilder();
45     try {
46       while (buffer.ready()) {
47         output.append(buffer.readLine().trim()).append("\n");
48       }
49     } catch (IOException e) {
50       fail("Should not have failed while reading the file");
51     }
52     return output.toString();
53   }
54
55 }