Fix Classes_assertHasMethods_Test#should_fail_if_no_methods_are_expected_and_methods_are_available on Java 14+.
@@ -18,9 +18,13 @@ import static org.assertj.core.error.ShouldHaveMethods.shouldHaveMethods;
import static org.assertj.core.error.ShouldHaveMethods.shouldNotHaveMethods;
import static org.assertj.core.test.TestData.someInfo;
import static org.assertj.core.util.Arrays.array;
+import static org.assertj.core.util.AssertionsUtil.assertThatAssertionErrorIsThrownBy;
import static org.assertj.core.util.FailureMessages.actualIsNull;
import static org.assertj.core.util.Sets.newTreeSet;
+import java.math.BigDecimal;
+import java.util.SortedSet;
+
import org.assertj.core.internal.ClassesBaseTest;
import org.assertj.core.util.Strings;
import org.junit.jupiter.api.BeforeEach;
@@ -46,20 +50,25 @@ public class Classes_assertHasMethods_Test extends ClassesBaseTest {
@Test
public void should_fail_if_no_methods_are_expected_and_methods_are_available() {
- assertThatExceptionOfType(AssertionError.class).isThrownBy(() -> classes.assertHasMethods(someInfo(), actual))
- .withMessage(format(shouldNotHaveMethods(actual, false,
- newTreeSet("publicMethod",
+ SortedSet<String> expectedMethods = newTreeSet("publicMethod",
"protectedMethod",
"privateMethod",
"finalize",
- "wait", "equals",
+ "wait",
+ "equals",
"toString",
"hashCode",
"getClass",
"clone",
- "registerNatives",
"notify",
- "notifyAll")).create()));
+ "notifyAll");
+ if (isJavaVersionBefore14()) {
+ expectedMethods.add("registerNatives");
+ }
+ assertThatAssertionErrorIsThrownBy(() -> classes.assertHasMethods(someInfo(), actual))
+ .withMessage(format(shouldNotHaveMethods(actual,
+ false,
+ expectedMethods).create()));
}
@Test
@@ -84,4 +93,9 @@ public class Classes_assertHasMethods_Test extends ClassesBaseTest {
newTreeSet(expected),
newTreeSet("missingMethod")).create()));
}
+
+ private static boolean isJavaVersionBefore14() {
+ BigDecimal javaVersion = new BigDecimal(System.getProperty("java.specification.version"));
+ return javaVersion.compareTo(new BigDecimal("14")) < 0;
+ }
}
