You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by cs...@apache.org on 2017/08/17 14:29:56 UTC

[04/27] karaf git commit: Extract methods

Extract methods


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/5b4da2cd
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/5b4da2cd
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/5b4da2cd

Branch: refs/heads/model_features
Commit: 5b4da2cd85b527b335d59ff4fc2ec686ee913558
Parents: 5497403
Author: Christian Schneider <ch...@die-schneider.net>
Authored: Tue Aug 15 16:05:13 2017 +0200
Committer: Christian Schneider <ch...@die-schneider.net>
Committed: Tue Aug 15 16:05:13 2017 +0200

----------------------------------------------------------------------
 .../jaas/modules/ldap/LdapLoginModuleTest.java  | 24 ++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/5b4da2cd/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java
----------------------------------------------------------------------
diff --git a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java
index ea29eef..186bdb2 100644
--- a/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java
+++ b/jaas/modules/src/test/java/org/apache/karaf/jaas/modules/ldap/LdapLoginModuleTest.java
@@ -38,6 +38,7 @@ import javax.security.auth.login.LoginException;
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.security.Principal;
@@ -59,6 +60,7 @@ import static org.junit.Assert.fail;
 )
 public class LdapLoginModuleTest extends AbstractLdapTestUnit {
     
+    private static final String PROPS_PATH = "org/apache/karaf/jaas/modules/ldap/ldap.properties";
     private static boolean portUpdated;
 
     @Before
@@ -70,18 +72,22 @@ public class LdapLoginModuleTest extends AbstractLdapTestUnit {
             }
 
             // Read in ldap.properties and substitute in the correct port
-            File f = new File(basedir + "/src/test/resources/org/apache/karaf/jaas/modules/ldap/ldap.properties");
-
-            FileInputStream inputStream = new FileInputStream(f);
-            String content = IOUtils.toString(inputStream, "UTF-8");
-            inputStream.close();
+            String content = readProperties(basedir + "/src/test/resources/" + PROPS_PATH);
             content = content.replaceAll("portno", "" + getLdapServer().getPort());
+            writeProperties(basedir + "/target/test-classes/" + PROPS_PATH, content);
+            portUpdated = true;
+        }
+    }
 
-            File f2 = new File(basedir + "/target/test-classes/org/apache/karaf/jaas/modules/ldap/ldap.properties");
-            FileOutputStream outputStream = new FileOutputStream(f2);
+    private String readProperties(String path) throws FileNotFoundException, IOException {
+        try (FileInputStream inputStream = new FileInputStream(new File(path))) {;
+            return IOUtils.toString(inputStream, "UTF-8");
+        }
+    }
+
+    private void writeProperties(String path, String content) throws FileNotFoundException, IOException {
+        try (FileOutputStream outputStream = new FileOutputStream(new File(path))) {
             IOUtils.write(content, outputStream, "UTF-8");
-            outputStream.close();
-            portUpdated = true;
         }
     }