Address some edge cases related to bootstrapping a fresh system.
[cfb.git] / test / net / jaekl / cfb / analyze / NotifierTest.java
1 package net.jaekl.cfb.analyze;
2
3 import static org.junit.Assert.assertTrue;
4
5 import java.io.IOException;
6
7 import net.jaekl.cfb.CfbBundleMock;
8 import net.jaekl.cfb.Config;
9
10 import org.junit.Before;
11 import org.junit.Test;
12
13 public class NotifierTest {
14         private CfbBundleMock m_bundle;
15         private Config m_config;
16         private MessageMapMock m_msgMap;
17         private NotifierMock m_notifier;
18
19         @Before
20         public void setUp() {
21                 m_bundle = new CfbBundleMock();
22                 m_config = new Config();
23                 m_msgMap = new MessageMapMock();
24                 m_notifier = new NotifierMock(m_bundle, m_config);
25         }
26         
27         @Test
28         public void testConstructSubject_noPrior() throws IOException {
29                 String[][] data = {
30                                 {
31                                         "ProjectNameGoesHere",
32                                         "0.7.42-SNAPSHOT",
33                                         "[cfb.mail.subject][[no.earlier.run]][[version.num][",
34                                         "][0.7.42-SNAPSHOT]]"
35                                 },
36                                 {
37                                         "ProjectNameGoesHere",
38                                         null,
39                                         "[cfb.mail.subject][[no.earlier.run]][[analyzed.at][",
40                                         "]]"
41                                 },
42                                 {
43                                         null,
44                                         "0.7.42-SNAPSHOT",
45                                         "[cfb.mail.subject][[no.earlier.run]][[version.num][",
46                                         "][0.7.42-SNAPSHOT]]"
47                                 },
48                                 {
49                                         null,
50                                         null,
51                                         "[cfb.mail.subject][[no.earlier.run]][[analyzed.at][",
52                                         "]]"
53                                 }
54                         };
55                 
56                 for (String[] datum : data) {
57                         String projectName = datum[0];
58                         String buildNumber = datum[1];
59                         String expectedPart1 = datum[2];
60                         String expectedPart2 = datum[3];
61                         
62                         Analysis first = null;
63                         Analysis second = new Analysis(projectName, buildNumber);
64                         
65                         Delta delta = new Delta(first, second);
66                         HtmlReport htmlReport = new HtmlReport(m_bundle, m_msgMap.getColl(), delta);
67                         
68                         String actual = m_notifier.constructSubject(htmlReport);
69                         boolean pass = (actual.startsWith(expectedPart1)) && (actual.endsWith(expectedPart2));
70                         if (!pass) {
71                                 System.out.println("ProjectName:\n" + projectName + "\nVersion:\n" + buildNumber 
72                                                 + "\nExpected:\n" + expectedPart1 + "{date}" + expectedPart2 + "\nActual:\n" + actual);
73                         }
74                         assertTrue(pass);
75                 }
76         }
77
78 }