1414
1515import static java .lang .String .format ;
1616import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
17+ import static org .assertj .core .api .BDDAssertions .then ;
1718import static org .assertj .core .error .ShouldHaveMethods .shouldHaveMethods ;
1819import static org .assertj .core .error .ShouldHaveMethods .shouldNotHaveMethods ;
1920import static org .assertj .core .test .TestData .someInfo ;
2021import 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 ;
2223import static org .assertj .core .util .FailureMessages .actualIsNull ;
2324import static org .assertj .core .util .Sets .newTreeSet ;
25+ import static org .junit .jupiter .api .condition .JRE .JAVA_18 ;
2426
25- import java .math .BigDecimal ;
2627import java .util .SortedSet ;
2728
2829import org .assertj .core .internal .ClassesBaseTest ;
2930import org .assertj .core .util .Strings ;
3031import org .junit .jupiter .api .BeforeEach ;
3132import org .junit .jupiter .api .Test ;
33+ import org .junit .jupiter .api .condition .JRE ;
3234
3335class 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