You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2020/02/17 18:13:51 UTC

[jspwiki] 02/11: small refactor to AttachmentManagerTest

This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 214c1a958bdce935cbb1d1651652eebba88c7dda
Author: juanpablo <ju...@apache.org>
AuthorDate: Sun Feb 2 20:51:28 2020 +0100

    small refactor to AttachmentManagerTest
---
 .../wiki/attachment/AttachmentManagerTest.java     | 39 ++++++++--------------
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/jspwiki-main/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java b/jspwiki-main/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java
index b4cd203..a231cb9 100644
--- a/jspwiki-main/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java
+++ b/jspwiki-main/src/test/java/org/apache/wiki/attachment/AttachmentManagerTest.java
@@ -31,53 +31,38 @@ import java.io.InputStreamReader;
 import java.io.StringReader;
 import java.io.StringWriter;
 import java.util.List;
-import java.util.Properties;
 
-public class AttachmentManagerTest
-{
+public class AttachmentManagerTest {
+
     public static final String NAME1 = "TestPage";
     public static final String NAMEU = "TestPage\u00e6";
 
-    Properties props = TestEngine.getTestProperties();
-
     TestEngine m_engine;
     AttachmentManager m_manager;
 
     static String c_fileContents = "ABCDEFGHIJKLMNOPQRSTUVWxyz";
 
     @BeforeEach
-    public void setUp()
-        throws Exception
-    {
-        CacheManager m_cacheManager = CacheManager.getInstance();
-        m_cacheManager.clearAll();
-        m_cacheManager.removeAllCaches();
-
-        m_engine  = new TestEngine(props);
+    public void setUp() throws Exception {
+        m_engine  = TestEngine.build();
         m_manager = m_engine.getAttachmentManager();
 
         m_engine.saveText( NAME1, "Foobar" );
         m_engine.saveText( NAMEU, "Foobar" );
     }
 
-    private File makeAttachmentFile()
-        throws Exception
-    {
-        File tmpFile = File.createTempFile("test","txt");
+    private File makeAttachmentFile() throws Exception {
+        final File tmpFile = File.createTempFile("test","txt");
         tmpFile.deleteOnExit();
-
-        FileWriter out = new FileWriter( tmpFile );
-
-        FileUtil.copyContents( new StringReader( c_fileContents ), out );
-
-        out.close();
+        try( final FileWriter out = new FileWriter( tmpFile ) ) {
+            FileUtil.copyContents( new StringReader( c_fileContents ), out );
+        }
 
         return tmpFile;
     }
 
     @AfterEach
-    public void tearDown()
-    {
+    public void tearDown() {
         m_engine.deleteTestPage( NAME1 );
         m_engine.deleteTestPage( NAMEU );
 
@@ -85,6 +70,10 @@ public class AttachmentManagerTest
         TestEngine.deleteAttachments(NAMEU);
 
         TestEngine.emptyWorkDir();
+
+        final CacheManager m_cacheManager = CacheManager.getInstance();
+        m_cacheManager.clearAll();
+        m_cacheManager.removeAllCaches();
     }
 
     @Test