3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
6 import java.io.IOException;
9 import net.jaekl.qd.util.FileIOMock;
10 import net.jaekl.qd.util.FileMock;
12 import org.junit.AfterClass;
13 import org.junit.BeforeClass;
14 import org.junit.Test;
16 public class ConfigTest {
17 private static final String CHRIS = "chris@localhost";
18 private static final String DB_HOST = "dbserver";
19 private static final int DB_PORT = 1234;
20 private static final String DB_NAME = "Fred";
21 private static final String DB_PASS = "Pebbles";
22 private static final String DB_USER = "Wilma";
23 private static final String HUDSON = "hudson@jenkins.org";
24 private static final String MAIL_FROM = "findbugs@jaekl.net";
25 private static final String MAIL_TO = CHRIS + "," + HUDSON;
26 private static final String LOCALHOST = "localhost";
28 private static final String SAMPLE1 =
29 "; Path (relative or absolute) to the FINDBUGS_HOME, i.e., where FindBugs is installed\n"
30 + "FindBugsHome=../findbugs-3.0.1/\n"
31 + "; List (comma-separated) of email addresses to which notifications should be sent\n"
32 + "notify=" + MAIL_TO + "\n"
34 + "; Mail server setup\n"
35 + "mail.smtp.host=" + LOCALHOST + "\n"
36 + "mail.from=" + MAIL_FROM + "\n"
39 + "db.host=" + DB_HOST + "\n"
40 + "db.port=" + DB_PORT + "\n"
41 + "db.name=" + DB_NAME + "\n"
42 + "db.user=" + DB_USER + "\n"
43 + "db.pass=" + DB_PASS + "\n";
46 public static void beforeClass() {
47 FileIOMock.mock_setInstance();
51 public static void afterClass() {
52 FileIOMock.mock_clearInstance();
56 public void testReadFile() throws IOException {
57 Config config = new Config();
59 FileMock fm = new FileMock("config.properties");
60 fm.mock_setContent(SAMPLE1);
64 assertEquals(MAIL_FROM, config.getMailFrom());
65 assertEquals(LOCALHOST, config.getMailSmtpHost());
67 List<String> notify = config.getNotify();
68 assertTrue(notify.contains(CHRIS));
69 assertTrue(notify.contains(HUDSON));
71 assertEquals(DB_HOST, config.getDbHost());
72 assertEquals(DB_PORT, config.getDbPort());
73 assertEquals(DB_NAME, config.getDbName());
74 assertEquals(DB_USER, config.getDbUser());
75 assertEquals(DB_PASS, config.getDbPass());
79 public void testReadEmptyFile() throws IOException {
80 Config config = new Config();
81 FileMock fm = new FileMock("empty.properties");
82 fm.mock_setContent("");
86 assertEquals("findbugs@localhost", config.getMailFrom());
87 assertEquals("localhost", config.getMailSmtpHost());
88 assertEquals(0, config.getNotify().size());