Address some edge cases related to bootstrapping a fresh system.
[cfb.git] / test / net / jaekl / cfb / analyze / NotifierTest.java
diff --git a/test/net/jaekl/cfb/analyze/NotifierTest.java b/test/net/jaekl/cfb/analyze/NotifierTest.java
new file mode 100644 (file)
index 0000000..e6cee95
--- /dev/null
@@ -0,0 +1,78 @@
+package net.jaekl.cfb.analyze;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import net.jaekl.cfb.CfbBundleMock;
+import net.jaekl.cfb.Config;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class NotifierTest {
+       private CfbBundleMock m_bundle;
+       private Config m_config;
+       private MessageMapMock m_msgMap;
+       private NotifierMock m_notifier;
+
+       @Before
+       public void setUp() {
+               m_bundle = new CfbBundleMock();
+               m_config = new Config();
+               m_msgMap = new MessageMapMock();
+               m_notifier = new NotifierMock(m_bundle, m_config);
+       }
+       
+       @Test
+       public void testConstructSubject_noPrior() throws IOException {
+               String[][] data = {
+                               {
+                                       "ProjectNameGoesHere",
+                                       "0.7.42-SNAPSHOT",
+                                       "[cfb.mail.subject][[no.earlier.run]][[version.num][",
+                                       "][0.7.42-SNAPSHOT]]"
+                               },
+                               {
+                                       "ProjectNameGoesHere",
+                                       null,
+                                       "[cfb.mail.subject][[no.earlier.run]][[analyzed.at][",
+                                       "]]"
+                               },
+                               {
+                                       null,
+                                       "0.7.42-SNAPSHOT",
+                                       "[cfb.mail.subject][[no.earlier.run]][[version.num][",
+                                       "][0.7.42-SNAPSHOT]]"
+                               },
+                               {
+                                       null,
+                                       null,
+                                       "[cfb.mail.subject][[no.earlier.run]][[analyzed.at][",
+                                       "]]"
+                               }
+                       };
+               
+               for (String[] datum : data) {
+                       String projectName = datum[0];
+                       String buildNumber = datum[1];
+                       String expectedPart1 = datum[2];
+                       String expectedPart2 = datum[3];
+                       
+                       Analysis first = null;
+                       Analysis second = new Analysis(projectName, buildNumber);
+                       
+                       Delta delta = new Delta(first, second);
+                       HtmlReport htmlReport = new HtmlReport(m_bundle, m_msgMap.getColl(), delta);
+                       
+                       String actual = m_notifier.constructSubject(htmlReport);
+                       boolean pass = (actual.startsWith(expectedPart1)) && (actual.endsWith(expectedPart2));
+                       if (!pass) {
+                               System.out.println("ProjectName:\n" + projectName + "\nVersion:\n" + buildNumber 
+                                               + "\nExpected:\n" + expectedPart1 + "{date}" + expectedPart2 + "\nActual:\n" + actual);
+                       }
+                       assertTrue(pass);
+               }
+       }
+
+}