Skip to content

Commit 795f527

Browse files
committed
Fix test
Closes #2635.
1 parent b444606 commit 795f527

File tree

2 files changed

+28
-27
lines changed

2 files changed

+28
-27
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<opentest4j.version>1.2.0</opentest4j.version>
4444
<!-- Dependency versions overriding -->
4545
<junit.version>4.13.2</junit.version>
46-
<junit-jupiter.version>5.8.2</junit-jupiter.version>
46+
<junit-jupiter.version>5.9.0-M1</junit-jupiter.version>
4747
<mockito.version>4.5.1</mockito.version>
4848
<!-- Plugin versions -->
4949
<bnd.version>6.2.0</bnd.version>

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

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,23 @@
1414

1515
import static java.lang.String.format;
1616
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
17+
import static org.assertj.core.api.BDDAssertions.then;
1718
import static org.assertj.core.error.ShouldHaveMethods.shouldHaveMethods;
1819
import static org.assertj.core.error.ShouldHaveMethods.shouldNotHaveMethods;
1920
import static org.assertj.core.test.TestData.someInfo;
2021
import static org.assertj.core.util.Arrays.array;
21-
import static org.assertj.core.util.AssertionsUtil.assertThatAssertionErrorIsThrownBy;
22+
import static org.assertj.core.util.AssertionsUtil.expectAssertionError;
2223
import static org.assertj.core.util.FailureMessages.actualIsNull;
2324
import static org.assertj.core.util.Sets.newTreeSet;
25+
import static org.junit.jupiter.api.condition.JRE.JAVA_18;
2426

25-
import java.math.BigDecimal;
2627
import java.util.SortedSet;
2728

2829
import org.assertj.core.internal.ClassesBaseTest;
2930
import org.assertj.core.util.Strings;
3031
import org.junit.jupiter.api.BeforeEach;
3132
import org.junit.jupiter.api.Test;
33+
import org.junit.jupiter.api.condition.JRE;
3234

3335
class Classes_assertHasMethods_Test extends ClassesBaseTest {
3436

@@ -50,25 +52,29 @@ void should_pass_if_actual_has_expected_accessible_public_methods() {
5052

5153
@Test
5254
void should_fail_if_no_methods_are_expected_and_methods_are_available() {
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()));
55+
// WHEN
56+
AssertionError assertionError = expectAssertionError(() -> classes.assertHasMethods(someInfo(), actual));
57+
// THEN
58+
then(assertionError).hasMessage(shouldNotHaveMethods(actual, false, actualMethods()).create());
59+
}
60+
61+
private static SortedSet<String> actualMethods() {
62+
SortedSet<String> actualMethods = newTreeSet("publicMethod",
63+
"protectedMethod",
64+
"privateMethod",
65+
"finalize",
66+
"wait",
67+
"equals",
68+
"toString",
69+
"hashCode",
70+
"getClass",
71+
"clone",
72+
"notify",
73+
"notifyAll");
74+
75+
if (JRE.currentVersion().compareTo(JAVA_18) > 0) actualMethods.add("wait0");
76+
77+
return actualMethods;
7278
}
7379

7480
@Test
@@ -94,11 +100,6 @@ void should_fail_if_expected_methods_are_missing() {
94100
newTreeSet("missingMethod")).create()));
95101
}
96102

97-
private static boolean isJavaVersionBefore14() {
98-
BigDecimal javaVersion = new BigDecimal(System.getProperty("java.specification.version"));
99-
return javaVersion.compareTo(new BigDecimal("14")) < 0;
100-
}
101-
102103
@Test
103104
void should_pass_with_directly_inherited_default_method() {
104105
// GIVEN

0 commit comments

Comments
 (0)