+
+ @Test
+ public void testTrans()
+ {
+ Object[][] data = {
+ { "hello", new Object[] {}, "[hello]" },
+ { "hello", new Object[] {"world"}, "[hello][world]"}
+ };
+
+ for (Object[] datum : data) {
+ String key = (String)datum[0];
+ Object[] params = (Object[])datum[1];
+ String expected = (String)datum[2];
+ String actual = m_cfb.trans(key, params);
+ assertEquals(expected, actual);
+ }
+ }
+
+ @Test
+ public void testReportException_FBMsgFileNotFoundException() throws IOException
+ {
+ String[][] data = {
+ {
+ "/home/fred/findbugs3.0.1", "messages.xml",
+ "[cannot.load.fbmsg.file][messages.xml]\n[findbugs.home.is.set.to][FINDBUGS_HOME][/home/fred/findbugs3.0.1]\n"
+ },
+ {
+ null, "messages.xml",
+ "[cannot.load.fbmsg.file][messages.xml]\n[findbugs.home.is.not.set][FINDBUGS_HOME]\n"
+ },
+ {
+ null, null, "[cannot.load.fbmsg.file][null]\n[findbugs.home.is.not.set][FINDBUGS_HOME]\n"
+ }
+ };
+ EnvMock envMock = EnvMock.mock_putInstance();
+
+ for (String[] datum : data)
+ {
+ String fbHome = datum[0];
+ String filename = datum[1];
+ String expected = datum[2];
+
+ try (
+ StringWriter sw = new StringWriter();
+ PrintWriter pw = new PrintWriter(sw);
+ )
+ {
+ envMock.mock_putEnv(CFB.FINDBUGS_HOME, fbHome);
+ FBMsgFileNotFoundException exc = new FBMsgFileNotFoundException(filename);
+ m_cfb.reportException(pw, exc);
+
+ pw.close();
+ sw.close();
+
+ String actual = sw.toString();
+ boolean pass = actual.endsWith(expected);
+ if (!pass) {
+ System.out.println("Expected:\n" + expected + "\nActual:\n" + actual);
+ }
+ assertTrue(pass);
+ }
+ }
+ }