Skip to content

Commit d393ef1

Browse files
scordioBananeweizen
andcommitted
Abort tests when symbolic links cannot be created (#3788)
Co-authored-by: Michael Keppler <Bananeweizen@users.noreply.github.com>
1 parent 2212433 commit d393ef1

15 files changed

Lines changed: 29 additions & 20 deletions

assertj-core/src/test/java/org/assertj/core/internal/PathsBaseTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.assertj.core.internal;
1717

18+
import static java.nio.file.Files.createSymbolicLink;
1819
import static org.assertj.core.testkit.TestData.someInfo;
1920
import static org.mockito.Mockito.mockingDetails;
2021
import static org.mockito.Mockito.reset;
@@ -27,6 +28,8 @@
2728
import org.junit.jupiter.api.BeforeAll;
2829
import org.junit.jupiter.api.BeforeEach;
2930
import org.junit.jupiter.api.io.TempDir;
31+
import org.junit.platform.commons.function.Try;
32+
import org.opentest4j.TestAbortedException;
3033

3134
/**
3235
* Base class for {@link Paths} tests.
@@ -71,4 +74,10 @@ void resetSpies() {
7174
reset(nioFilesWrapper, failures, diff, binaryDiff);
7275
}
7376

77+
// https://github.com/assertj/assertj/issues/3183
78+
protected static Path tryToCreateSymbolicLink(Path link, Path target) {
79+
return Try.call(() -> createSymbolicLink(link, target))
80+
.getOrThrow(e -> new TestAbortedException("Failed to create symbolic link", e));
81+
}
82+
7483
}

assertj-core/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWithRaw_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void should_pass_if_actual_ends_with_other() throws IOException {
7777
void should_fail_if_actual_is_not_canonical() throws IOException {
7878
// GIVEN
7979
Path file = createFile(tempDir.resolve("file"));
80-
Path actual = createSymbolicLink(tempDir.resolve("actual"), file);
80+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), file);
8181
Path other = Paths.get("file");
8282
// WHEN
8383
AssertionError error = expectAssertionError(() -> underTest.assertEndsWithRaw(INFO, actual, other));

assertj-core/src/test/java/org/assertj/core/internal/paths/Paths_assertEndsWith_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void should_pass_if_actual_ends_with_other() throws IOException {
9494
void should_pass_if_actual_is_not_canonical() throws IOException {
9595
// GIVEN
9696
Path file = createFile(tempDir.resolve("file"));
97-
Path actual = createSymbolicLink(tempDir.resolve("actual"), file);
97+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), file);
9898
Path other = Paths.get("file");
9999
// WHEN/THEN
100100
underTest.assertEndsWith(INFO, actual, other);

assertj-core/src/test/java/org/assertj/core/internal/paths/Paths_assertExistsNoFollowLinks_Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void should_pass_if_actual_exists() throws IOException {
6060
void should_pass_if_actual_is_a_symbolic_link_and_target_exists() throws IOException {
6161
// GIVEN
6262
Path target = createFile(tempDir.resolve("target"));
63-
Path actual = createSymbolicLink(tempDir.resolve("actual"), target);
63+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), target);
6464
// WHEN/THEN
6565
underTest.assertExistsNoFollowLinks(INFO, actual);
6666
}
@@ -69,7 +69,7 @@ void should_pass_if_actual_is_a_symbolic_link_and_target_exists() throws IOExcep
6969
void should_pass_if_actual_is_a_symbolic_link_and_target_does_not_exist() throws IOException {
7070
// GIVEN
7171
Path target = tempDir.resolve("non-existent");
72-
Path actual = createSymbolicLink(tempDir.resolve("actual"), target);
72+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), target);
7373
// WHEN/THEN
7474
underTest.assertExistsNoFollowLinks(INFO, actual);
7575
}

assertj-core/src/test/java/org/assertj/core/internal/paths/Paths_assertExists_Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void should_pass_if_actual_exists() throws IOException {
6060
void should_pass_if_actual_is_a_symbolic_link_and_target_exists() throws IOException {
6161
// GIVEN
6262
Path target = createFile(tempDir.resolve("target"));
63-
Path actual = createSymbolicLink(tempDir.resolve("actual"), target);
63+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), target);
6464
// WHEN/THEN
6565
underTest.assertExists(INFO, actual);
6666
}
@@ -69,7 +69,7 @@ void should_pass_if_actual_is_a_symbolic_link_and_target_exists() throws IOExcep
6969
void should_fail_if_actual_is_a_symbolic_link_and_target_does_not_exist() throws IOException {
7070
// GIVEN
7171
Path target = tempDir.resolve("non-existent");
72-
Path actual = createSymbolicLink(tempDir.resolve("actual"), target);
72+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), target);
7373
// WHEN
7474
AssertionError error = expectAssertionError(() -> underTest.assertExists(INFO, actual));
7575
// THEN

assertj-core/src/test/java/org/assertj/core/internal/paths/Paths_assertHasFileName_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void should_pass_with_existing_directory() throws IOException {
9595
@Test
9696
void should_pass_with_existing_symbolic_link() throws IOException {
9797
// GIVEN
98-
Path actual = createSymbolicLink(tempDir.resolve("actual"), tempDir);
98+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), tempDir);
9999
String filename = "actual";
100100
// WHEN/THEN
101101
underTest.assertHasFileName(INFO, actual, filename);

assertj-core/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParentRaw_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void should_pass_if_actual_has_no_parent() {
6060
void should_fail_if_actual_is_not_canonical() throws IOException {
6161
// GIVEN
6262
Path root = tempDir.getRoot();
63-
Path actual = createSymbolicLink(tempDir.resolve("actual"), root);
63+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), root);
6464
// WHEN
6565
AssertionError error = expectAssertionError(() -> underTest.assertHasNoParentRaw(INFO, actual));
6666
// THEN

assertj-core/src/test/java/org/assertj/core/internal/paths/Paths_assertHasNoParent_Test.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void should_pass_if_actual_has_no_parent() {
7777
void should_pass_if_actual_is_not_canonical() throws IOException {
7878
// GIVEN
7979
Path root = tempDir.getRoot();
80-
Path actual = createSymbolicLink(tempDir.resolve("actual"), root);
80+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), root);
8181
// WHEN/THEN
8282
underTest.assertHasNoParent(INFO, actual);
8383
}

assertj-core/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParentRaw_Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ void should_fail_if_actual_is_not_canonical() throws IOException {
8989
// GIVEN
9090
Path expected = createDirectory(tempDir.resolve("expected"));
9191
Path file = createFile(expected.resolve("file"));
92-
Path actual = createSymbolicLink(tempDir.resolve("actual"), file);
92+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), file);
9393
// WHEN
9494
AssertionError error = expectAssertionError(() -> underTest.assertHasParentRaw(INFO, actual, expected));
9595
// THEN
@@ -100,7 +100,7 @@ void should_fail_if_actual_is_not_canonical() throws IOException {
100100
void should_fail_if_expected_is_not_canonical() throws IOException {
101101
// GIVEN
102102
Path directory = createDirectory(tempDir.resolve("directory"));
103-
Path expected = createSymbolicLink(tempDir.resolve("expected"), directory);
103+
Path expected = tryToCreateSymbolicLink(tempDir.resolve("expected"), directory);
104104
Path actual = createFile(directory.resolve("actual"));
105105
// WHEN
106106
AssertionError error = expectAssertionError(() -> underTest.assertHasParentRaw(INFO, actual, expected));

assertj-core/src/test/java/org/assertj/core/internal/paths/Paths_assertHasParent_Test.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void should_pass_if_actual_is_not_canonical() throws IOException {
120120
// GIVEN
121121
Path expected = createDirectory(tempDir.resolve("expected"));
122122
Path file = createFile(expected.resolve("file"));
123-
Path actual = createSymbolicLink(tempDir.resolve("actual"), file);
123+
Path actual = tryToCreateSymbolicLink(tempDir.resolve("actual"), file);
124124
// WHEN/THEN
125125
underTest.assertHasParent(INFO, actual, expected);
126126
}
@@ -129,7 +129,7 @@ void should_pass_if_actual_is_not_canonical() throws IOException {
129129
void should_pass_if_expected_is_not_canonical() throws IOException {
130130
// GIVEN
131131
Path directory = createDirectory(tempDir.resolve("directory"));
132-
Path expected = createSymbolicLink(tempDir.resolve("expected"), directory);
132+
Path expected = tryToCreateSymbolicLink(tempDir.resolve("expected"), directory);
133133
Path actual = createFile(directory.resolve("actual"));
134134
// WHEN/THEN
135135
underTest.assertHasParent(INFO, actual, expected);

0 commit comments

Comments
 (0)