-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from gdgib/G2-1512-CaseInsensitiveEnvironments
G2-1512 Support case insensitive environment maps
- Loading branch information
Showing
9 changed files
with
162 additions
and
12 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
4 changes: 1 addition & 3 deletions
4
...ria/command/main/TestDispatchCommand.java → .../command/command/TestDispatchCommand.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
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
50 changes: 50 additions & 0 deletions
50
...est/java/com/g2forge/alexandria/command/invocation/environment/TestSystemEnvironment.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,50 @@ | ||
package com.g2forge.alexandria.command.invocation.environment; | ||
|
||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import org.junit.Test; | ||
|
||
import com.g2forge.alexandria.adt.associative.map.MapBuilder; | ||
import com.g2forge.alexandria.test.HAssert; | ||
|
||
public class TestSystemEnvironment { | ||
@Test | ||
public void caseInsensitive() { | ||
final String key = "Key", value = "Value"; | ||
final Map<String, String> inputMap = new MapBuilder<>(key, value).build(); | ||
final Map<String, String> outputMap = new SystemEnvironment() { | ||
@Override | ||
protected Map<String, String> getSystemEnvironment() { | ||
return inputMap; | ||
} | ||
|
||
@Override | ||
protected boolean isCaseInsensitive() { | ||
return true; | ||
} | ||
}.toMap(); | ||
HAssert.assertEquals(value, outputMap.get(key)); | ||
HAssert.assertEquals(value, outputMap.get(key.toUpperCase())); | ||
HAssert.assertEquals(value, outputMap.get(key.toLowerCase())); | ||
} | ||
|
||
@Test | ||
public void caseSensitive() { | ||
final String key = "Key", value = "Value"; | ||
final Map<String, String> inputMap = new MapBuilder<>(key, value).build(); | ||
final Map<String, String> outputMap = new SystemEnvironment() { | ||
@Override | ||
protected Map<String, String> getSystemEnvironment() { | ||
return inputMap; | ||
} | ||
|
||
@Override | ||
protected boolean isCaseInsensitive() { | ||
return false; | ||
} | ||
}.toMap(); | ||
HAssert.assertEquals(value, outputMap.get(key)); | ||
HAssert.assertFalse(Objects.equals(value, outputMap.get(key.toUpperCase())) && Objects.equals(value, outputMap.get(key.toLowerCase()))); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...m/g2forge/alexandria/command/invocation/environment/modified/TestModifiedEnvironment.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,58 @@ | ||
package com.g2forge.alexandria.command.invocation.environment.modified; | ||
|
||
import java.util.Map; | ||
import java.util.SortedMap; | ||
|
||
import org.junit.Test; | ||
|
||
import com.g2forge.alexandria.adt.associative.map.MapBuilder; | ||
import com.g2forge.alexandria.command.invocation.environment.MapEnvironment; | ||
import com.g2forge.alexandria.command.invocation.environment.SystemEnvironment; | ||
import com.g2forge.alexandria.test.HAssert; | ||
|
||
public class TestModifiedEnvironment { | ||
@Test | ||
public void unspecified() { | ||
final String key = "Key", value = "Value"; | ||
final ModifiedEnvironment environment = ModifiedEnvironment.builder().base(new MapEnvironment(new MapBuilder<>(key, value).build())).modifier(key, EnvironmentModifier.Unspecified).build(); | ||
HAssert.assertNull(environment.apply(key)); | ||
HAssert.assertTrue(environment.toMap().isEmpty()); | ||
} | ||
|
||
@Test | ||
public void inherit() { | ||
final String key = "Key", value = "Value"; | ||
final ModifiedEnvironment environment = ModifiedEnvironment.builder().base(new MapEnvironment(new MapBuilder<>(key, value).build())).modifier(key, EnvironmentModifier.Inherit).build(); | ||
HAssert.assertEquals(value, environment.apply(key)); | ||
HAssert.assertEquals(1, environment.toMap().size()); | ||
} | ||
|
||
@Test | ||
public void value() { | ||
final String key = "Key", value = "Value", other = "Other"; | ||
final ModifiedEnvironment environment = ModifiedEnvironment.builder().base(new MapEnvironment(new MapBuilder<>(key, value).build())).modifier(key, new EnvironmentValue(other)).build(); | ||
HAssert.assertEquals(other, environment.apply(key)); | ||
HAssert.assertEquals(1, environment.toMap().size()); | ||
} | ||
|
||
@Test | ||
public void caseInsensitive() { | ||
final String key = "Key", value = "Value"; | ||
final Map<String, String> inputMap = new MapBuilder<>(key, value).build(); | ||
final Map<String, String> outputMap = ModifiedEnvironment.builder().base(new SystemEnvironment() { | ||
@Override | ||
protected Map<String, String> getSystemEnvironment() { | ||
return inputMap; | ||
} | ||
|
||
@Override | ||
protected boolean isCaseInsensitive() { | ||
return true; | ||
} | ||
}).build().toMap(); | ||
HAssert.assertEquals(value, outputMap.get(key)); | ||
HAssert.assertEquals(value, outputMap.get(key.toUpperCase())); | ||
HAssert.assertEquals(value, outputMap.get(key.toLowerCase())); | ||
HAssert.assertInstanceOf(SortedMap.class, outputMap); | ||
} | ||
} |
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