More unit testing.
[cfb.git] / test / net / jaekl / cfb / CFBTest.java
index 08d9c393f626e431214536a7001933d6adce3301..6d446676e0e32d1243830f7c537fc1f44a0fc673 100644 (file)
@@ -171,33 +171,39 @@ public class CFBTest {
                                        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();
+               }
        }
 }