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 {
+ EnvMock envMock = EnvMock.mock_putInstance();
- try (
- StringWriter sw = new StringWriter();
- PrintWriter pw = new PrintWriter(sw);
- )
+ for (String[] datum : data)
{
- envMock.mock_putEnv(CFB.FINDBUGS_HOME, fbHome);
- FBMsgFileNotFoundException exc = new FBMsgFileNotFoundException(filename);
- m_cfb.reportException(pw, exc);
+ String fbHome = datum[0];
+ String filename = datum[1];
+ String expected = datum[2];
- pw.close();
- sw.close();
-
- String actual = sw.toString();
- boolean pass = actual.endsWith(expected);
- if (!pass) {
- System.out.println("Expected:\n" + expected + "\nActual:\n" + actual);
+ 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);
}
- assertTrue(pass);
}
}
+ finally {
+ EnvMock.mock_resetInstance();
+ }
}
}
return super.getEnv(variableName);
}
+ public void mock_putEnv(String variableName, String value) {
+ m_map.put(variableName, value);
+ }
+
public static EnvMock mock_putInstance() {
EnvMock mock = new EnvMock();
- m_inst = mock;
+ synchronized(Env.class) {
+ m_inst = mock;
+ }
return mock;
}
- public void mock_putEnv(String variableName, String value) {
- m_map.put(variableName, value);
+ public static void mock_resetInstance() {
+ synchronized(Env.class) {
+ m_inst = null;
+ }
}
}