package net.jaekl.cfb;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+import java.util.List;
+
+import net.jaekl.qd.util.FileIOMock;
+import net.jaekl.qd.util.FileMock;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
public class ConfigTest {
+ private static final String CHRIS = "chris@localhost";
+ private static final String HUDSON = "hudson@jenkins.org";
+ private static final String MAIL_FROM = "findbugs@jaekl.net";
+ private static final String MAIL_TO = CHRIS + "," + HUDSON;
+ private static final String LOCALHOST = "localhost";
private static final String SAMPLE1 =
"; Path (relative or absolute) to the FINDBUGS_HOME, i.e., where FindBugs is installed\n"
+ "FindBugsHome=../findbugs-3.0.1/\n"
+ "; List (comma-separated) of email addresses to which notifications should be sent\n"
- + "notify=chris@localhost\n"
+ + "notify=" + MAIL_TO + "\n"
+ "\n"
+ "; Mail server setup\n"
- + "mail.smtp.host=localhost\n"
- + "mail.from=findbugs@localhost\n";
+ + "mail.smtp.host=" + LOCALHOST + "\n"
+ + "mail.from=" + MAIL_FROM + "\n";
+ @BeforeClass
+ public static void beforeClass() {
+ FileIOMock.mock_setInstance();
+ }
+
+ @AfterClass
+ public static void afterClass() {
+ FileIOMock.mock_clearInstance();
+ }
+
@Test
- public void testReadFile() {
- // TODO: wrap file access so that we can test this
+ public void testReadFile() throws IOException {
+ Config config = new Config();
+
+ FileMock fm = new FileMock("config.properties");
+ fm.mock_setContent(SAMPLE1);
+
+ config.readFile(fm);
+
+ assertEquals(MAIL_FROM, config.getMailFrom());
+ assertEquals(LOCALHOST, config.getMailSmtpHost());
+
+ List<String> notify = config.getNotify();
+ assertTrue(notify.contains(CHRIS));
+ assertTrue(notify.contains(HUDSON));
+ }
+
+ @Test
+ public void testReadEmptyFile() throws IOException {
+ Config config = new Config();
+ FileMock fm = new FileMock("empty.properties");
+ fm.mock_setContent("");
+
+ config.readFile(fm);
+
+ assertEquals("findbugs@localhost", config.getMailFrom());
+ assertEquals("localhost", config.getMailSmtpHost());
+ assertEquals(0, config.getNotify().size());
}
-
}