Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B54AB174FF for ; Thu, 23 Apr 2015 18:27:25 +0000 (UTC) Received: (qmail 6056 invoked by uid 500); 23 Apr 2015 18:26:19 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 6015 invoked by uid 500); 23 Apr 2015 18:26:19 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 6002 invoked by uid 99); 23 Apr 2015 18:26:19 -0000 Received: from Unknown (HELO hades.apache.org) (140.211.11.105) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Apr 2015 18:26:18 +0000 Received: from hades.apache.org (localhost [127.0.0.1]) by hades.apache.org (ASF Mail Server at hades.apache.org) with ESMTP id CDF9BAC006A for ; Thu, 23 Apr 2015 18:26:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1675700 - /poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java Date: Thu, 23 Apr 2015 18:26:01 -0000 To: commits@poi.apache.org From: nick@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20150423182601.CDF9BAC006A@hades.apache.org> Author: nick Date: Thu Apr 23 18:26:01 2015 New Revision: 1675700 URL: http://svn.apache.org/r1675700 Log: Make the opening code generic Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java Modified: poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java?rev=1675700&r1=1675699&r2=1675700&view=diff ============================================================================== --- poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java (original) +++ poi/trunk/src/testcases/org/apache/poi/poifs/filesystem/TestFileSystemBugs.java Thu Apr 23 18:26:01 2015 @@ -17,7 +17,9 @@ package org.apache.poi.poifs.filesystem; +import java.util.ArrayList; import java.util.Iterator; +import java.util.List; import junit.framework.TestCase; @@ -27,26 +29,40 @@ import org.apache.poi.POIDataSamples; * Tests bugs across both POIFSFileSystem and NPOIFSFileSystem */ public final class TestFileSystemBugs extends TestCase { + protected static POIDataSamples _samples = POIDataSamples.getPOIFSInstance(); + + protected List openedFSs; + protected void tearDown() throws Exception { + if (openedFSs != null && !openedFSs.isEmpty()) { + for (NPOIFSFileSystem fs : openedFSs) { + try { + fs.close(); + } catch (Exception e) { + System.err.println("Error closing FS: " + e); + } + } + } + openedFSs = null; + } + protected DirectoryNode[] openSample(String name) throws Exception { + POIFSFileSystem ofs = new POIFSFileSystem( + _samples.openResourceAsStream(name)); + NPOIFSFileSystem nfs = new NPOIFSFileSystem( + _samples.openResourceAsStream(name)); + + if (openedFSs == null) openedFSs = new ArrayList(); + openedFSs.add(nfs); + + return new DirectoryNode[] { ofs.getRoot(), nfs.getRoot() }; + } + /** * Test that we can open files that come via Lotus notes. * These have a top level directory without a name.... */ public void testNotesOLE2Files() throws Exception { - POIDataSamples _samples = POIDataSamples.getPOIFSInstance(); - - // Open the file up with the two FileSystems - @SuppressWarnings("resource") - DirectoryNode[] roots = new DirectoryNode[] { - new POIFSFileSystem( - _samples.openResourceAsStream("Notes.ole2") - ).getRoot(), - new NPOIFSFileSystem( - _samples.openResourceAsStream("Notes.ole2") - ).getRoot() - }; - // Check the contents - for (DirectoryNode root : roots) { + for (DirectoryNode root : openSample("Notes.ole2")) { assertEquals(1, root.getEntryCount()); Entry entry = root.getEntries().next(); @@ -69,10 +85,6 @@ public final class TestFileSystemBugs ex entry = it.next(); assertEquals(true, entry.isDocumentEntry()); assertEquals("\u0001CompObj", entry.getName()); - - // Tidy - if (root.getNFileSystem() != null) - root.getNFileSystem().close(); } } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org