Skip to content

Commit daf13ee

Browse files
committed
Add additional tests for Path assertions
1 parent 620ec29 commit daf13ee

File tree

2 files changed

+73
-15
lines changed

2 files changed

+73
-15
lines changed

src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryContaining_with_String_Test.java

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
import org.assertj.core.internal.PathsBaseTest;
3434
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.params.ParameterizedTest;
36+
import org.junit.jupiter.params.provider.ValueSource;
3537

3638
/**
3739
* @author Valeriy Vyrva
@@ -108,27 +110,55 @@ void should_fail_if_actual_is_empty() throws IOException {
108110
then(error).hasMessage(directoryShouldContain(actual, emptyList(), "the 'glob:**' pattern").create());
109111
}
110112

111-
@Test
112-
void should_pass_if_actual_contains_at_least_one_path_matching_the_given_pattern() throws IOException {
113+
@ParameterizedTest
114+
@ValueSource(strings = {
115+
"glob:**file",
116+
// "glob:file", // fails due to gh-2329
117+
"regex:.*file",
118+
// "regex:file", // fails due to gh-2329
119+
})
120+
void should_pass_if_actual_directly_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
113121
// GIVEN
114122
Path actual = createDirectory(tempDir.resolve("actual"));
115-
createFile(actual.resolve("file"));
116123
createDirectory(actual.resolve("directory"));
117-
String syntaxAndPattern = "glob:**file";
124+
createFile(actual.resolve("file"));
118125
// WHEN/THEN
119126
paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern);
120127
}
121128

122-
@Test
123-
void should_fail_if_actual_does_not_contain_any_paths_matching_the_given_pattern() throws IOException {
129+
@ParameterizedTest
130+
@ValueSource(strings = {
131+
"glob:**file",
132+
"glob:file",
133+
"regex:.*file",
134+
"regex:file",
135+
})
136+
void should_fail_if_actual_does_not_contain_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
137+
// GIVEN
138+
Path actual = createDirectory(tempDir.resolve("actual"));
139+
Path directory = createDirectory(actual.resolve("directory"));
140+
// WHEN
141+
AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern));
142+
// THEN
143+
then(error).hasMessage(directoryShouldContain(actual, list(directory), "the '" + syntaxAndPattern + "' pattern").create());
144+
}
145+
146+
@ParameterizedTest
147+
@ValueSource(strings = {
148+
"glob:**file",
149+
"glob:file",
150+
"regex:.*file",
151+
"regex:file",
152+
})
153+
void should_fail_if_actual_recursively_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
124154
// GIVEN
125155
Path actual = createDirectory(tempDir.resolve("actual"));
126156
Path directory = createDirectory(actual.resolve("directory"));
127-
String syntaxAndPattern = "glob:**file";
157+
createFile(directory.resolve("file"));
128158
// WHEN
129159
AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern));
130160
// THEN
131-
then(error).hasMessage(directoryShouldContain(actual, list(directory), "the 'glob:**file' pattern").create());
161+
then(error).hasMessage(directoryShouldContain(actual, list(directory), "the '" + syntaxAndPattern + "' pattern").create());
132162
}
133163

134164
}

src/test/java/org/assertj/core/internal/paths/Paths_assertIsDirectoryNotContaining_with_String_Test.java

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
import org.assertj.core.internal.PathsBaseTest;
3333
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.params.ParameterizedTest;
35+
import org.junit.jupiter.params.provider.ValueSource;
3436

3537
/**
3638
* @author Valeriy Vyrva
@@ -105,24 +107,50 @@ void should_pass_if_actual_is_empty() throws IOException {
105107
paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern);
106108
}
107109

108-
@Test
109-
void should_fail_if_actual_contains_at_least_one_path_matching_the_given_pattern() throws IOException {
110+
@ParameterizedTest
111+
@ValueSource(strings = {
112+
"glob:**file",
113+
// "glob:file", // fails due to gh-2329
114+
"regex:.*file",
115+
// "regex:file", // fails due to gh-2329
116+
})
117+
void should_fail_if_actual_directly_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
110118
// GIVEN
111119
Path actual = createDirectory(tempDir.resolve("actual"));
112120
Path file = createFile(actual.resolve("file"));
113-
String syntaxAndPattern = "glob:**file";
114121
// WHEN
115122
AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern));
116123
// THEN
117-
then(error).hasMessage(directoryShouldNotContain(actual, list(file), "the 'glob:**file' pattern").create());
124+
then(error).hasMessage(directoryShouldNotContain(actual, list(file), "the '" + syntaxAndPattern + "' pattern").create());
118125
}
119126

120-
@Test
121-
void should_pass_if_actual_does_not_contain_any_paths_matching_the_given_pattern() throws IOException {
127+
@ParameterizedTest
128+
@ValueSource(strings = {
129+
"glob:**file",
130+
"glob:file",
131+
"regex:.*file",
132+
"regex:file",
133+
})
134+
void should_pass_if_actual_does_not_contain_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
122135
// GIVEN
123136
Path actual = createDirectory(tempDir.resolve("actual"));
124137
createDirectory(actual.resolve("directory"));
125-
String syntaxAndPattern = "glob:**file";
138+
// WHEN/THEN
139+
paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern);
140+
}
141+
142+
@ParameterizedTest
143+
@ValueSource(strings = {
144+
"glob:**file",
145+
"glob:file",
146+
"regex:.*file",
147+
"regex:file",
148+
})
149+
void should_pass_if_actual_recursively_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
150+
// GIVEN
151+
Path actual = createDirectory(tempDir.resolve("actual"));
152+
Path directory = createDirectory(actual.resolve("directory"));
153+
createFile(directory.resolve("file"));
126154
// WHEN/THEN
127155
paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern);
128156
}

0 commit comments

Comments
 (0)