Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
Closes #2635.
  • Loading branch information
scordio committed May 30, 2022
1 parent b444606 commit 795f527
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<opentest4j.version>1.2.0</opentest4j.version>
<!-- Dependency versions overriding -->
<junit.version>4.13.2</junit.version>
<junit-jupiter.version>5.8.2</junit-jupiter.version>
<junit-jupiter.version>5.9.0-M1</junit-jupiter.version>
<mockito.version>4.5.1</mockito.version>
<!-- Plugin versions -->
<bnd.version>6.2.0</bnd.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,23 @@

import static java.lang.String.format;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.BDDAssertions.then;
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.AssertionsUtil.expectAssertionError;
import static org.assertj.core.util.FailureMessages.actualIsNull;
import static org.assertj.core.util.Sets.newTreeSet;
import static org.junit.jupiter.api.condition.JRE.JAVA_18;

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;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.JRE;

class Classes_assertHasMethods_Test extends ClassesBaseTest {

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

@Test
void should_fail_if_no_methods_are_expected_and_methods_are_available() {
SortedSet<String> expectedMethods = newTreeSet("publicMethod",
"protectedMethod",
"privateMethod",
"finalize",
"wait",
"equals",
"toString",
"hashCode",
"getClass",
"clone",
"notify",
"notifyAll");
if (isJavaVersionBefore14()) {
expectedMethods.add("registerNatives");
}
assertThatAssertionErrorIsThrownBy(() -> classes.assertHasMethods(someInfo(), actual))
.withMessage(format(shouldNotHaveMethods(actual,
false,
expectedMethods).create()));
// WHEN
AssertionError assertionError = expectAssertionError(() -> classes.assertHasMethods(someInfo(), actual));
// THEN
then(assertionError).hasMessage(shouldNotHaveMethods(actual, false, actualMethods()).create());
}

private static SortedSet<String> actualMethods() {
SortedSet<String> actualMethods = newTreeSet("publicMethod",
"protectedMethod",
"privateMethod",
"finalize",
"wait",
"equals",
"toString",
"hashCode",
"getClass",
"clone",
"notify",
"notifyAll");

if (JRE.currentVersion().compareTo(JAVA_18) > 0) actualMethods.add("wait0");

return actualMethods;
}

@Test
Expand All @@ -94,11 +100,6 @@ void should_fail_if_expected_methods_are_missing() {
newTreeSet("missingMethod")).create()));
}

private static boolean isJavaVersionBefore14() {
BigDecimal javaVersion = new BigDecimal(System.getProperty("java.specification.version"));
return javaVersion.compareTo(new BigDecimal("14")) < 0;
}

@Test
void should_pass_with_directly_inherited_default_method() {
// GIVEN
Expand Down

0 comments on commit 795f527

Please sign in to comment.