Skip to content

Commit e0bb550

Browse files
committed
#7 sanitizing done
1 parent d7d4061 commit e0bb550

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/objectionary/jucs/blob/master/LICENSE.txt)
1313

1414
There is a simple annotation in this package, which may help you
15-
turn files in classpath into sources of a JUnit test method.
15+
turn files in classpath into sources of a JUnit5 test method.
1616

1717
First, add this to your `pom.xml`:
1818

@@ -31,7 +31,7 @@ import org.junit.jupiter.params.ParameterizedTest;
3131

3232
final class SimpleTest {
3333
@ParameterizedTest
34-
@ClasspathSource(value="org/example", glob="**/*.yaml")
34+
@ClasspathSource(value="org/example/", glob="**/*.yaml")
3535
void simpleTest(String y) {
3636
// In the "y" variable is the content of the YAML file
3737
}

src/main/java/org/eolang/jucs/JucsProvider.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Stream<? extends Arguments> provideArguments(
8181
*/
8282
private Collection<String> yamls(final String prefix) {
8383
final Collection<String> out = new LinkedList<>();
84-
final String home = String.format("%s%s", this.annotation.value(), prefix);
84+
final String home = String.format("%s/%s", this.sanitized(), prefix);
8585
final String folder = new UncheckedText(
8686
new TextOf(new ResourceOf(home))
8787
).asString();
@@ -99,4 +99,21 @@ private Collection<String> yamls(final String prefix) {
9999
}
100100
return out;
101101
}
102+
103+
/**
104+
* Get sanitized home path.
105+
* @return The path without front slash and with a tailing one
106+
*/
107+
private String sanitized() {
108+
final String path = this.annotation.value();
109+
int begin = 0;
110+
if (path.charAt(0) == '/') {
111+
begin = 1;
112+
}
113+
int end = path.length();
114+
if (path.charAt(end - 1) == '/') {
115+
end -= 1;
116+
}
117+
return path.substring(begin, end);
118+
}
102119
}

src/test/java/org/eolang/jucs/JucsProviderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@
3434
final class JucsProviderTest {
3535

3636
@ParameterizedTest
37-
@ClasspathSource("com/yegor256/jucs/")
37+
@ClasspathSource("com/yegor256/jucs")
3838
void simpleTest(final String file) {
3939
Assertions.assertEquals(file, "Hello, world!\n");
4040
}
4141

4242
@ParameterizedTest
43-
@ClasspathSource(value = "com/yegor256/jucs/", glob = "**/*.text")
43+
@ClasspathSource(value = "/com/yegor256/jucs", glob = "**/*.text")
4444
void findsInFolders(final String file) {
4545
Assertions.assertEquals(file, "hey!\n");
4646
}

0 commit comments

Comments
 (0)