1 package org.djutils.traceverifier;
2
3 import static org.junit.Assert.assertTrue;
4 import static org.junit.Assert.fail;
5
6 import java.io.File;
7 import java.io.IOException;
8
9 import org.junit.Rule;
10 import org.junit.Test;
11 import org.junit.rules.TemporaryFolder;
12
13
14
15
16
17
18
19
20
21
22
23 public class TraceVerifierTest
24 {
25
26
27 @Rule
28 public TemporaryFolder testDir = new TemporaryFolder();
29
30
31
32
33
34 @SuppressWarnings("resource")
35 @Test
36 public void testTraceVerifier() throws IOException
37 {
38 try
39 {
40 new TraceVerifier("/Non/Existent/Path/And/File/Name");
41 fail("non existent path should have thrown an exception");
42 }
43 catch (IOException ioe)
44 {
45
46 }
47
48
49 String traceFileName = this.testDir.getRoot().getCanonicalPath() + File.separator + "traceFile.txt";
50
51 TraceVerifier tv = new TraceVerifier(traceFileName);
52 assertTrue("toString returns something descriptive", tv.toString().startsWith("TraceVerifier"));
53
54 tv.sample("sample 1", "state 1");
55 tv.sample("sample 2", "state 2");
56 tv.sample("sample 3", "state 3");
57 tv.close();
58
59 tv = new TraceVerifier(traceFileName);
60 try
61 {
62 tv.sample("sample 1", "not state 1");
63 fail("tv.sample(...) should have raised an exception");
64 }
65 catch (TraceVerifierException re)
66 {
67
68 assertTrue("Got wrong message: " + re.getMessage() + " of exception " + re.getClass(),
69 re.getMessage().startsWith("Discrepancy found"));
70 }
71 try
72 {
73 tv.sample("not sample 2", "state 2");
74 fail("tv.sample(...) should have raised an exception");
75 }
76 catch (TraceVerifierException re)
77 {
78
79 assertTrue("Got wrong message: " + re.getMessage() + " of exception " + re.getClass(),
80 re.getMessage().startsWith("Discrepancy found"));
81 }
82 tv.sample("sample 3", "state 3");
83 tv.close();
84 }
85
86 }