Fix test · assertj/assertj@795f527 (original) (raw)

`@@ -14,21 +14,23 @@

`

14

14

``

15

15

`import static java.lang.String.format;

`

16

16

`import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

`

``

17

`+

import static org.assertj.core.api.BDDAssertions.then;

`

17

18

`import static org.assertj.core.error.ShouldHaveMethods.shouldHaveMethods;

`

18

19

`import static org.assertj.core.error.ShouldHaveMethods.shouldNotHaveMethods;

`

19

20

`import static org.assertj.core.test.TestData.someInfo;

`

20

21

`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;

`

22

23

`import static org.assertj.core.util.FailureMessages.actualIsNull;

`

23

24

`import static org.assertj.core.util.Sets.newTreeSet;

`

``

25

`+

import static org.junit.jupiter.api.condition.JRE.JAVA_18;

`

24

26

``

25

``

`-

import java.math.BigDecimal;

`

26

27

`import java.util.SortedSet;

`

27

28

``

28

29

`import org.assertj.core.internal.ClassesBaseTest;

`

29

30

`import org.assertj.core.util.Strings;

`

30

31

`import org.junit.jupiter.api.BeforeEach;

`

31

32

`import org.junit.jupiter.api.Test;

`

``

33

`+

import org.junit.jupiter.api.condition.JRE;

`

32

34

``

33

35

`class Classes_assertHasMethods_Test extends ClassesBaseTest {

`

34

36

``

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

`

50

52

``

51

53

`@Test

`

52

54

`void should_fail_if_no_methods_are_expected_and_methods_are_available() {

`

53

``

`-

SortedSet 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 actualMethods() {

`

``

62

`+

SortedSet 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;

`

72

78

` }

`

73

79

``

74

80

`@Test

`

`@@ -94,11 +100,6 @@ void should_fail_if_expected_methods_are_missing() {

`

94

100

`newTreeSet("missingMethod")).create()));

`

95

101

` }

`

96

102

``

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

``

-

102

103

`@Test

`

103

104

`void should_pass_with_directly_inherited_default_method() {

`

104

105

`// GIVEN

`