Skip to content

Commit

Permalink
Add additional tests for Path assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Sep 16, 2021
1 parent 620ec29 commit daf13ee
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

import org.assertj.core.internal.PathsBaseTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

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

@Test
void should_pass_if_actual_contains_at_least_one_path_matching_the_given_pattern() throws IOException {
@ParameterizedTest
@ValueSource(strings = {
"glob:**file",
// "glob:file", // fails due to gh-2329
"regex:.*file",
// "regex:file", // fails due to gh-2329
})
void should_pass_if_actual_directly_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
// GIVEN
Path actual = createDirectory(tempDir.resolve("actual"));
createFile(actual.resolve("file"));
createDirectory(actual.resolve("directory"));
String syntaxAndPattern = "glob:**file";
createFile(actual.resolve("file"));
// WHEN/THEN
paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern);
}

@Test
void should_fail_if_actual_does_not_contain_any_paths_matching_the_given_pattern() throws IOException {
@ParameterizedTest
@ValueSource(strings = {
"glob:**file",
"glob:file",
"regex:.*file",
"regex:file",
})
void should_fail_if_actual_does_not_contain_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
// GIVEN
Path actual = createDirectory(tempDir.resolve("actual"));
Path directory = createDirectory(actual.resolve("directory"));
// WHEN
AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern));
// THEN
then(error).hasMessage(directoryShouldContain(actual, list(directory), "the '" + syntaxAndPattern + "' pattern").create());
}

@ParameterizedTest
@ValueSource(strings = {
"glob:**file",
"glob:file",
"regex:.*file",
"regex:file",
})
void should_fail_if_actual_recursively_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
// GIVEN
Path actual = createDirectory(tempDir.resolve("actual"));
Path directory = createDirectory(actual.resolve("directory"));
String syntaxAndPattern = "glob:**file";
createFile(directory.resolve("file"));
// WHEN
AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryContaining(info, actual, syntaxAndPattern));
// THEN
then(error).hasMessage(directoryShouldContain(actual, list(directory), "the 'glob:**file' pattern").create());
then(error).hasMessage(directoryShouldContain(actual, list(directory), "the '" + syntaxAndPattern + "' pattern").create());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import org.assertj.core.internal.PathsBaseTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

/**
* @author Valeriy Vyrva
Expand Down Expand Up @@ -105,24 +107,50 @@ void should_pass_if_actual_is_empty() throws IOException {
paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern);
}

@Test
void should_fail_if_actual_contains_at_least_one_path_matching_the_given_pattern() throws IOException {
@ParameterizedTest
@ValueSource(strings = {
"glob:**file",
// "glob:file", // fails due to gh-2329
"regex:.*file",
// "regex:file", // fails due to gh-2329
})
void should_fail_if_actual_directly_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
// GIVEN
Path actual = createDirectory(tempDir.resolve("actual"));
Path file = createFile(actual.resolve("file"));
String syntaxAndPattern = "glob:**file";
// WHEN
AssertionError error = expectAssertionError(() -> paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern));
// THEN
then(error).hasMessage(directoryShouldNotContain(actual, list(file), "the 'glob:**file' pattern").create());
then(error).hasMessage(directoryShouldNotContain(actual, list(file), "the '" + syntaxAndPattern + "' pattern").create());
}

@Test
void should_pass_if_actual_does_not_contain_any_paths_matching_the_given_pattern() throws IOException {
@ParameterizedTest
@ValueSource(strings = {
"glob:**file",
"glob:file",
"regex:.*file",
"regex:file",
})
void should_pass_if_actual_does_not_contain_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
// GIVEN
Path actual = createDirectory(tempDir.resolve("actual"));
createDirectory(actual.resolve("directory"));
String syntaxAndPattern = "glob:**file";
// WHEN/THEN
paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern);
}

@ParameterizedTest
@ValueSource(strings = {
"glob:**file",
"glob:file",
"regex:.*file",
"regex:file",
})
void should_pass_if_actual_recursively_contains_any_entries_matching_the_given_pattern(String syntaxAndPattern) throws IOException {
// GIVEN
Path actual = createDirectory(tempDir.resolve("actual"));
Path directory = createDirectory(actual.resolve("directory"));
createFile(directory.resolve("file"));
// WHEN/THEN
paths.assertIsDirectoryNotContaining(info, actual, syntaxAndPattern);
}
Expand Down

0 comments on commit daf13ee

Please sign in to comment.