X-Git-Url: http://jaekl.net/gitweb/?p=cfb.git;a=blobdiff_plain;f=test%2Fnet%2Fjaekl%2Fcfb%2FConfigTest.java;h=e7ca44c87025517f864700db538861ec5b08ad5f;hp=3fafe87bf0c668cefae6a5db021bd958ee93ef0e;hb=900ffbe1fcb2ecce1e29b526d928c930161aa09f;hpb=c0bde8e3268a2f1ba05166b174a0d733237dc246 diff --git a/test/net/jaekl/cfb/ConfigTest.java b/test/net/jaekl/cfb/ConfigTest.java index 3fafe87..e7ca44c 100644 --- a/test/net/jaekl/cfb/ConfigTest.java +++ b/test/net/jaekl/cfb/ConfigTest.java @@ -1,24 +1,72 @@ 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 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()); } - }