mirror of
https://github.com/hapifhir/org.hl7.fhir.core.git
synced 2025-03-05 19:09:11 +00:00
Test coverage
This commit is contained in:
parent
d8309796ca
commit
3c7abb5eff
@ -5,6 +5,8 @@ import java.io.FilenameFilter;
|
||||
import java.io.IOException;
|
||||
|
||||
public class AsteriskFilter implements FilenameFilter {
|
||||
|
||||
|
||||
String dir;
|
||||
String regex;
|
||||
|
||||
@ -22,6 +24,10 @@ public class AsteriskFilter implements FilenameFilter {
|
||||
else
|
||||
regex = regex + "\\" + expression.charAt(i);
|
||||
}
|
||||
isDirValid();
|
||||
}
|
||||
|
||||
protected void isDirValid() throws IOException {
|
||||
File f = new File(dir);
|
||||
if (!f.exists()) {
|
||||
throw new IOException("Directory " + dir + " does not exist");
|
||||
|
@ -0,0 +1,76 @@
|
||||
package org.hl7.fhir.validation.cli.utils;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class AsteriskFilterTests {
|
||||
|
||||
private static Stream<Arguments> provideValidFiltersAndDirsForwardSlash() {
|
||||
return Stream.of(
|
||||
Arguments.of("one/*", "one/", ".*"),
|
||||
Arguments.of("/one/*", "/one/", ".*"),
|
||||
Arguments.of("/one/*.*", "/one/", ".*\\..*"),
|
||||
Arguments.of("/one/two.*", "/one/", "two\\..*"),
|
||||
Arguments.of("/one/*.two", "/one/", ".*\\.two"),
|
||||
Arguments.of("one/*/*", "one/*/", ".*"),
|
||||
Arguments.of("one/*/*.*", "one/*/", ".*\\..*"),
|
||||
Arguments.of("/one/two/*", "/one/two/",".*"),
|
||||
Arguments.of("one/two/*/*.*", "one/two/*/", ".*\\..*"),
|
||||
Arguments.of("one/two/*/three.*", "one/two/*/", "three\\..*"),
|
||||
Arguments.of("one/two/*/*.three", "one/two/*/", ".*\\.three"),
|
||||
Arguments.of("one/two/*/*.*three", "one/two/*/", ".*\\..*three"),
|
||||
Arguments.of("/one-two/*", "/one-two/", ".*"),
|
||||
Arguments.of("/one-two/three/*", "/one-two/three/", ".*")
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("provideValidFiltersAndDirsForwardSlash")
|
||||
public void testValidFilterDirAndRegex(String filterString, String expectedDir, String expectedRegex) throws IOException {
|
||||
//Test with forward slash separators
|
||||
testFilterDirExtraction(filterString, expectedDir, expectedRegex);
|
||||
//Test with backward slash separators
|
||||
testFilterDirExtraction(filterString.replace('/','\\'), expectedDir.replace('/','\\'), expectedRegex.replace('/','\\'));
|
||||
}
|
||||
|
||||
private static void testFilterDirExtraction(String filterString, String expectedDir, String expectedRegex) throws IOException {
|
||||
AsteriskFilter asteriskFilter = getAsteriskFilterWithoutDirValidityCheck(filterString);
|
||||
assertEquals(expectedRegex, asteriskFilter.regex);
|
||||
assertEquals(expectedDir, asteriskFilter.dir);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(
|
||||
strings = {
|
||||
"",
|
||||
"one/",
|
||||
"one\\",
|
||||
"one/two",
|
||||
"one\\two"
|
||||
}
|
||||
)
|
||||
public void testInvalidFilterThrowsException(String filterString) {
|
||||
IOException thrown = Assertions.assertThrows(IOException.class, () -> {
|
||||
AsteriskFilter asteriskFilter = getAsteriskFilterWithoutDirValidityCheck(filterString);
|
||||
}, "NumberFormatException was expected");
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static AsteriskFilter getAsteriskFilterWithoutDirValidityCheck(String filterString) throws IOException {
|
||||
return new AsteriskFilter(filterString) {
|
||||
@Override
|
||||
protected void isDirValid() throws IOException {
|
||||
// Dont check for existent directory in this case.
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user