-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement EnvPathParser, Test, maven.yml Reconfiguration
- Loading branch information
rikkarth
committed
Dec 6, 2023
1 parent
e7740c6
commit fd3a56e
Showing
7 changed files
with
91 additions
and
42 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
39 changes: 29 additions & 10 deletions
39
src/test/java/pt/codeforge/toolertools/pathfinder/EnvPathParserTest.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 |
---|---|---|
@@ -1,28 +1,47 @@ | ||
package pt.codeforge.toolertools.pathfinder; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class EnvPathParserTest { | ||
|
||
@BeforeEach | ||
void setup() { | ||
System.setProperty("$HOME", "test"); | ||
@ParameterizedTest | ||
@ValueSource(strings = "$HOME") | ||
void givenUnixValidEnvVariable_testgetEnvPath_shouldReturnValidPath(String input) { | ||
String result = EnvPathParser.getEnvPath(input); | ||
|
||
assertValidResult(input, result); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = "$HOME/$TEMP") | ||
void givenUnixMultipleValidEnvVariables_testgetEnvPath_shouldReturnValidPath(String input) { | ||
String result = EnvPathParser.getEnvPath(input); | ||
|
||
assertValidResult(input, result); | ||
} | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = "$HOMEDRIVE/$HOMEPATH") | ||
void testGetEnvPath(String input) { | ||
@ValueSource(strings = "$HOME/%HOME%") | ||
void givenUnixAndMysMultipleValidEnvVariables_testgetEnvPath_shouldReturnValidPath(String input) { | ||
String result = EnvPathParser.getEnvPath(input); | ||
|
||
System.out.println(EnvPathParser.getEnvPath(input)); | ||
assertValidResult(input, result); | ||
} | ||
|
||
@Test | ||
void testBadGetEnvPath() { | ||
Assertions.assertThrows(IllegalArgumentException.class, () -> EnvPathParser.getEnvPath(null)); | ||
void givenNullInput_testGetEnvPath_shouldThrowIllegalArgumentException() { | ||
assertThrows(IllegalArgumentException.class, () -> EnvPathParser.getEnvPath(null), | ||
"EnvPathParser#getEnvPath should throw IllegalArgumentException.class."); | ||
} | ||
|
||
private static void assertValidResult(String input, String result) { | ||
assertNotEquals(input, result, "Input should not be equal to result."); | ||
assertFalse(result.isEmpty(), "Result should not be empty."); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/java/pt/codeforge/toolertools/utils/ParametersProvider.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,21 @@ | ||
package pt.codeforge.toolertools.utils; | ||
|
||
import java.util.stream.Stream; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
|
||
public class ParametersProvider { | ||
|
||
public static final String PARAMETERS_PROVIDER_CLASS = "pt.codeforge.toolertools.utils.ParametersProvider"; | ||
|
||
public static Stream<Arguments> getEnvPaths(){ | ||
return Stream.of( | ||
Arguments.of("$HOMEDRIVE/$HOMEPATH"), | ||
Arguments.of("$TEMP/test"), | ||
Arguments.of("test/$HOMEPATH/"), | ||
Arguments.of("../$HOMEPATH/"), | ||
Arguments.of("./$HOMEPATH/"), | ||
Arguments.of("$HOMEDRIVE/$HOMEPATH/test"), | ||
Arguments.of("") | ||
); | ||
} | ||
} |