Skip to content

Commit 11fa8e4

Browse files
Fix Classes_assertHasMethods_Test#should_fail_if_no_methods_are_expected_and_methods_are_available on Java 14+.
1 parent 7090511 commit 11fa8e4

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

src/test/java/org/assertj/core/internal/classes/Classes_assertHasMethods_Test.java

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@
1818
import static org.assertj.core.error.ShouldHaveMethods.shouldNotHaveMethods;
1919
import static org.assertj.core.test.TestData.someInfo;
2020
import static org.assertj.core.util.Arrays.array;
21+
import static org.assertj.core.util.AssertionsUtil.assertThatAssertionErrorIsThrownBy;
2122
import static org.assertj.core.util.FailureMessages.actualIsNull;
2223
import static org.assertj.core.util.Sets.newTreeSet;
2324

25+
import java.math.BigDecimal;
26+
import java.util.SortedSet;
27+
2428
import org.assertj.core.internal.ClassesBaseTest;
2529
import org.assertj.core.util.Strings;
2630
import org.junit.jupiter.api.BeforeEach;
@@ -46,20 +50,25 @@ public void should_pass_if_actual_has_expected_accessible_public_methods() {
4650

4751
@Test
4852
public void should_fail_if_no_methods_are_expected_and_methods_are_available() {
49-
assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> classes.assertHasMethods(someInfo(), actual))
50-
.withMessage(format(shouldNotHaveMethods(actual, false,
51-
newTreeSet("publicMethod",
52-
"protectedMethod",
53-
"privateMethod",
54-
"finalize",
55-
"wait", "equals",
56-
"toString",
57-
"hashCode",
58-
"getClass",
59-
"clone",
60-
"registerNatives",
61-
"notify",
62-
"notifyAll")).create()));
53+
SortedSet<String> expectedMethods = newTreeSet("publicMethod",
54+
"protectedMethod",
55+
"privateMethod",
56+
"finalize",
57+
"wait",
58+
"equals",
59+
"toString",
60+
"hashCode",
61+
"getClass",
62+
"clone",
63+
"notify",
64+
"notifyAll");
65+
if (isJavaVersionBefore14()) {
66+
expectedMethods.add("registerNatives");
67+
}
68+
assertThatAssertionErrorIsThrownBy(() -> classes.assertHasMethods(someInfo(), actual))
69+
.withMessage(format(shouldNotHaveMethods(actual,
70+
false,
71+
expectedMethods).create()));
6372
}
6473

6574
@Test
@@ -84,4 +93,9 @@ public void should_fail_if_expected_methods_are_missing() {
8493
newTreeSet(expected),
8594
newTreeSet("missingMethod")).create()));
8695
}
96+
97+
private static boolean isJavaVersionBefore14() {
98+
BigDecimal javaVersion = new BigDecimal(System.getProperty("java.specification.version"));
99+
return javaVersion.compareTo(new BigDecimal("14")) < 0;
100+
}
87101
}

0 commit comments

Comments
 (0)