18
18
import static org .assertj .core .error .ShouldHaveMethods .shouldNotHaveMethods ;
19
19
import static org .assertj .core .test .TestData .someInfo ;
20
20
import static org .assertj .core .util .Arrays .array ;
21
+ import static org .assertj .core .util .AssertionsUtil .assertThatAssertionErrorIsThrownBy ;
21
22
import static org .assertj .core .util .FailureMessages .actualIsNull ;
22
23
import static org .assertj .core .util .Sets .newTreeSet ;
23
24
25
+ import java .math .BigDecimal ;
26
+ import java .util .SortedSet ;
27
+
24
28
import org .assertj .core .internal .ClassesBaseTest ;
25
29
import org .assertj .core .util .Strings ;
26
30
import org .junit .jupiter .api .BeforeEach ;
@@ -46,20 +50,25 @@ public void should_pass_if_actual_has_expected_accessible_public_methods() {
46
50
47
51
@ Test
48
52
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 ()));
63
72
}
64
73
65
74
@ Test
@@ -84,4 +93,9 @@ public void should_fail_if_expected_methods_are_missing() {
84
93
newTreeSet (expected ),
85
94
newTreeSet ("missingMethod" )).create ()));
86
95
}
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
+ }
87
101
}
0 commit comments