Author: sgoeschl
Date: Mon Sep 13 20:01:12 2010
New Revision: 996671

URL: http://svn.apache.org/viewvc?rev=996671&view=rev
Log:
Adding "testAddEnvironmentVariables()"

Modified:
    
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java

Modified: 
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java?rev=996671&r1=996670&r2=996671&view=diff
==============================================================================
--- 
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
 (original)
+++ 
commons/proper/exec/trunk/src/test/java/org/apache/commons/exec/DefaultExecutorTest.java
 Mon Sep 13 20:01:12 2010
@@ -30,6 +30,7 @@ import java.util.HashMap;
 import java.util.Map;
 
 import junit.framework.TestCase;
+import org.apache.commons.exec.environment.EnvironmentUtils;
 
 public class DefaultExecutorTest extends TestCase {
 
@@ -141,7 +142,11 @@ public class DefaultExecutorTest extends
         assertFalse(exec.isFailure(exitValue));
     }
 
-    public void testExecuteWithEnv() throws Exception {
+    /**
+     * Execute the test script and pass a environment containing
+     * 'TEST_ENV_VAR'.
+     */
+    public void testExecuteWithSingleEnvironmentVariable() throws Exception {
        Map env = new HashMap();
         env.put("TEST_ENV_VAR", "XYZ");
 
@@ -536,9 +541,25 @@ public class DefaultExecutorTest extends
         exec.execute(new CommandLine(environmentSript));
         String environment = baos.toString().trim();
         assertTrue("Found no environment variables", environment.length() > 0);
+        assertFalse(environment.contains("NEW_VAR"));
         System.out.println(environment);
     }
 
+    /**
+     * Call a script to dump the environment variables of the subprocess
+     * after adding a custom environment variable.
+     *
+     * @throws Exception the test failed
+     */
+    public void testAddEnvironmentVariables() throws Exception {
+        Map myEnvVars = new HashMap();
+        myEnvVars.putAll(EnvironmentUtils.getProcEnvironment());
+        myEnvVars.put("NEW_VAR","NEW_VAL");
+        exec.execute(new CommandLine(environmentSript), myEnvVars);
+        String environment = baos.toString().trim();
+        assertTrue(environment.contains("NEW_VAR"));
+    }
+
     // ======================================================================
     // === Testing bug fixes
     // ======================================================================


Reply via email to