]> source.dussan.org Git - poi.git/commitdiff
Undo changes to file in assertCloseDoesNotModifyFile to not have dirty files after...
authorDominik Stadler <centic@apache.org>
Sun, 3 Jan 2016 21:37:52 +0000 (21:37 +0000)
committerDominik Stadler <centic@apache.org>
Sun, 3 Jan 2016 21:37:52 +0000 (21:37 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1722756 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/sl/usermodel/BaseTestSlideShowFactory.java

index bc95aa91b3820c4218e047acb7f70b67111e57b2..f6326f779234afb9e16ffb2cccfd3be00b393b0d 100644 (file)
@@ -21,21 +21,18 @@ import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 
-import java.io.ByteArrayOutputStream;
-
 import org.apache.poi.POIDataSamples;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
 
 public class BaseTestSlideShowFactory {
     private static final POIDataSamples _slTests = POIDataSamples.getSlideShowInstance();
-    private static final POILogger LOGGER = POILogFactory.getLogger(BaseTestSlideShowFactory.class);
 
     protected static void testFactoryFromFile(String file) throws Exception {
         SlideShow<?,?> ss;
@@ -167,8 +164,23 @@ public class BaseTestSlideShowFactory {
         final byte[] before = readFile(filename);
         ss.close();
         final byte[] after = readFile(filename);
-        assertArrayEquals(filename + " sample file was modified as a result of closing the slideshow",
-                before, after);
+
+        try {
+            assertArrayEquals(filename + " sample file was modified as a result of closing the slideshow",
+                    before, after);
+        } catch (AssertionError e) {
+            // if the file after closing is different, then re-set 
+            // the file to the state before in order to not have a dirty SCM 
+            // working tree when running this test
+            FileOutputStream str = new FileOutputStream(_slTests.getFile(filename));
+            try {
+                str.write(before);
+            } finally {
+                str.close();
+            }
+            
+            throw e;
+        }
     }
 
     private static File fromFile(String file) {