-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #10 - RegexBasedInterpolatorTest fails when building with maven 3…
….4.0-SNAPSHOT Tests fails because the $HOME env var is no longer defined inside mvn.cmd and is not found (some tests pass even if the env var is not found!). - Changed the OperatingSystemUtils to allow mocking the Map of env vars. - Fixed tests to use mocking whenever the env vars are not the focus of the unit test. - When testing with a REAL env var, it is chosen to be $JAVA_HOME since it is required to be present to run mvn script. - Added tests to EnvarBasedValueSource and fixed.EnvarBasedValueSource.
- Loading branch information
1 parent
0eff699
commit 0af4e03
Showing
8 changed files
with
319 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
src/test/java/org/codehaus/plexus/interpolation/EnvarBasedValueSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package org.codehaus.plexus.interpolation; | ||
|
||
/* | ||
* Copyright 2007 The Codehaus Foundation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class EnvarBasedValueSourceTest | ||
{ | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
EnvarBasedValueSource.resetStatics(); | ||
} | ||
|
||
@Test | ||
public void testNoArgConstructorIsCaseSensitive() | ||
throws IOException | ||
{ | ||
OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource() | ||
{ | ||
public Map<String, String> getEnvMap() | ||
{ | ||
HashMap<String, String> map = new HashMap<String, String>(); | ||
map.put( "aVariable", "variable" ); | ||
return map; | ||
} | ||
} ); | ||
|
||
EnvarBasedValueSource source = new EnvarBasedValueSource(); | ||
|
||
assertEquals( "variable", source.getValue( "aVariable" ) ); | ||
assertEquals( "variable", source.getValue( "env.aVariable" ) ); | ||
assertNull( source.getValue( "AVARIABLE" ) ); | ||
assertNull( source.getValue( "env.AVARIABLE" ) ); | ||
} | ||
|
||
@Test | ||
public void testCaseInsensitive() | ||
throws IOException | ||
{ | ||
OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource() | ||
{ | ||
public Map<String, String> getEnvMap() | ||
{ | ||
HashMap<String, String> map = new HashMap<String, String>(); | ||
map.put( "aVariable", "variable" ); | ||
return map; | ||
} | ||
} ); | ||
|
||
EnvarBasedValueSource source = new EnvarBasedValueSource( false ); | ||
|
||
assertEquals( "variable", source.getValue( "aVariable" ) ); | ||
assertEquals( "variable", source.getValue( "env.aVariable" ) ); | ||
assertEquals( "variable", source.getValue( "AVARIABLE" ) ); | ||
assertEquals( "variable", source.getValue( "env.AVARIABLE" ) ); | ||
} | ||
|
||
@Test | ||
public void testGetRealEnvironmentVariable() | ||
throws IOException | ||
{ | ||
OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.DefaultEnvVarSource() ); | ||
|
||
EnvarBasedValueSource source = new EnvarBasedValueSource(); | ||
|
||
String realEnvVar = "JAVA_HOME"; | ||
|
||
String realValue = System.getenv().get( realEnvVar ); | ||
assertNotNull( "Can't run this test until " + realEnvVar + " env variable is set", realValue ); | ||
|
||
assertEquals( realValue, source.getValue( realEnvVar ) ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
src/test/java/org/codehaus/plexus/interpolation/fixed/EnvarBasedValueSourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package org.codehaus.plexus.interpolation.fixed; | ||
|
||
/* | ||
* Copyright 2007 The Codehaus Foundation. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.codehaus.plexus.interpolation.os.OperatingSystemUtils; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
public class EnvarBasedValueSourceTest | ||
{ | ||
|
||
@Before | ||
public void setUp() | ||
{ | ||
EnvarBasedValueSource.resetStatics(); | ||
} | ||
|
||
@Test | ||
public void testNoArgConstructorIsCaseSensitive() | ||
throws IOException | ||
{ | ||
OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource() | ||
{ | ||
public Map<String, String> getEnvMap() | ||
{ | ||
HashMap<String, String> map = new HashMap<String, String>(); | ||
map.put( "aVariable", "variable" ); | ||
return map; | ||
} | ||
} ); | ||
|
||
EnvarBasedValueSource source = new EnvarBasedValueSource(); | ||
|
||
assertEquals( "variable", source.getValue( "aVariable", null ) ); | ||
assertEquals( "variable", source.getValue( "env.aVariable", null ) ); | ||
assertNull( source.getValue( "AVARIABLE", null ) ); | ||
assertNull( source.getValue( "env.AVARIABLE", null ) ); | ||
} | ||
|
||
@Test | ||
public void testCaseInsensitive() | ||
throws IOException | ||
{ | ||
OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.EnvVarSource() | ||
{ | ||
public Map<String, String> getEnvMap() | ||
{ | ||
HashMap<String, String> map = new HashMap<String, String>(); | ||
map.put( "aVariable", "variable" ); | ||
return map; | ||
} | ||
} ); | ||
|
||
EnvarBasedValueSource source = new EnvarBasedValueSource( false ); | ||
|
||
assertEquals( "variable", source.getValue( "aVariable", null ) ); | ||
assertEquals( "variable", source.getValue( "env.aVariable", null ) ); | ||
assertEquals( "variable", source.getValue( "AVARIABLE", null ) ); | ||
assertEquals( "variable", source.getValue( "env.AVARIABLE", null ) ); | ||
} | ||
|
||
@Test | ||
public void testGetRealEnvironmentVariable() | ||
throws IOException | ||
{ | ||
OperatingSystemUtils.setEnvVarSource( new OperatingSystemUtils.DefaultEnvVarSource() ); | ||
|
||
EnvarBasedValueSource source = new EnvarBasedValueSource(); | ||
|
||
String realEnvVar = "JAVA_HOME"; | ||
|
||
String realValue = System.getenv().get( realEnvVar ); | ||
assertNotNull( "Can't run this test until " + realEnvVar + " env variable is set", realValue ); | ||
|
||
assertEquals( realValue, source.getValue( realEnvVar, null ) ); | ||
} | ||
|
||
} |
Oops, something went wrong.