Replace ExpectedException in MissingInvocationInOrderCheckerTest (#2511) · mockito/mockito@b91bd29 (original) (raw)

`@@ -7,13 +7,13 @@

`

7

7

`import static java.util.Arrays.asList;

`

8

8

``

9

9

`import static org.mockito.internal.verification.checkers.MissingInvocationChecker.checkMissingInvocation;

`

``

10

`+

import static org.assertj.core.api.Assertions.assertThatThrownBy;

`

10

11

``

11

12

`import java.util.List;

`

12

13

``

13

14

`import org.junit.Before;

`

14

15

`import org.junit.Rule;

`

15

16

`import org.junit.Test;

`

16

``

`-

import org.junit.rules.ExpectedException;

`

17

17

`import org.mockito.Mock;

`

18

18

`import org.mockito.exceptions.verification.VerificationInOrderFailure;

`

19

19

`import org.mockito.exceptions.verification.WantedButNotInvoked;

`

`@@ -34,8 +34,6 @@ public class MissingInvocationInOrderCheckerTest {

`

34

34

``

35

35

`@Mock private IMethods mock;

`

36

36

``

37

``

`-

@Rule public ExpectedException exception = ExpectedException.none();

`

38

``

-

39

37

`@Rule public MockitoRule mockitoRule = MockitoJUnit.rule();

`

40

38

``

41

39

`private InOrderContext context = new InOrderContextImpl();

`

`@@ -57,26 +55,29 @@ public void shouldReportWantedButNotInvoked() throws Exception {

`

57

55

`invocations = asList(buildDifferentMethod().toInvocation());

`

58

56

`wanted = buildSimpleMethod().toInvocationMatcher();

`

59

57

``

60

``

`-

exception.expect(WantedButNotInvoked.class);

`

61

``

`-

exception.expectMessage("Wanted but not invoked:");

`

62

``

`-

exception.expectMessage("mock.simpleMethod()");

`

63

``

-

64

``

`-

checkMissingInvocation(invocations, wanted, context);

`

``

58

`+

assertThatThrownBy(

`

``

59

`+

() -> {

`

``

60

`+

checkMissingInvocation(invocations, wanted, context);

`

``

61

`+

})

`

``

62

`+

.isInstanceOf(WantedButNotInvoked.class)

`

``

63

`+

.hasMessageContainingAll("Wanted but not invoked:", "mock.simpleMethod()");

`

65

64

` }

`

66

65

``

67

66

`@Test

`

68

67

`public void shouldReportArgumentsAreDifferent() throws Exception {

`

69

68

`invocations = asList(buildIntArgMethod().arg(1111).toInvocation());

`

70

69

`wanted = buildIntArgMethod().arg(2222).toInvocationMatcher();

`

71

70

``

72

``

`-

exception.expect(ArgumentsAreDifferent.class);

`

73

``

-

74

``

`-

exception.expectMessage("Argument(s) are different! Wanted:");

`

75

``

`-

exception.expectMessage("mock.intArgumentMethod(2222);");

`

76

``

`-

exception.expectMessage("Actual invocations have different arguments:");

`

77

``

`-

exception.expectMessage("mock.intArgumentMethod(1111);");

`

78

``

-

79

``

`-

checkMissingInvocation(invocations, wanted, context);

`

``

71

`+

assertThatThrownBy(

`

``

72

`+

() -> {

`

``

73

`+

checkMissingInvocation(invocations, wanted, context);

`

``

74

`+

})

`

``

75

`+

.isInstanceOf(ArgumentsAreDifferent.class)

`

``

76

`+

.hasMessageContainingAll(

`

``

77

`+

"Argument(s) are different! Wanted:",

`

``

78

`+

"mock.intArgumentMethod(2222);",

`

``

79

`+

"Actual invocations have different arguments:",

`

``

80

`+

"mock.intArgumentMethod(1111);");

`

80

81

` }

`

81

82

``

82

83

`@Test

`

`@@ -89,15 +90,17 @@ public void shouldReportWantedDiffersFromActual() throws Exception {

`

89

90

`invocations = asList(invocation1, invocation2);

`

90

91

`wanted = buildIntArgMethod().arg(2222).toInvocationMatcher();

`

91

92

``

92

``

`-

exception.expect(VerificationInOrderFailure.class);

`

93

``

-

94

``

`-

exception.expectMessage("Verification in order failure");

`

95

``

`-

exception.expectMessage("Wanted but not invoked:");

`

96

``

`-

exception.expectMessage("mock.intArgumentMethod(2222);");

`

97

``

`-

exception.expectMessage("Wanted anywhere AFTER following interaction:");

`

98

``

`-

exception.expectMessage("mock.intArgumentMethod(2222);");

`

99

``

-

100

``

`-

checkMissingInvocation(invocations, wanted, context);

`

``

93

`+

assertThatThrownBy(

`

``

94

`+

() -> {

`

``

95

`+

checkMissingInvocation(invocations, wanted, context);

`

``

96

`+

})

`

``

97

`+

.isInstanceOf(VerificationInOrderFailure.class)

`

``

98

`+

.hasMessageContainingAll(

`

``

99

`+

"Verification in order failure",

`

``

100

`+

"Wanted but not invoked:",

`

``

101

`+

"mock.intArgumentMethod(2222);",

`

``

102

`+

"Wanted anywhere AFTER following interaction:",

`

``

103

`+

"mock.intArgumentMethod(2222);");

`

101

104

` }

`

102

105

``

103

106

`private InvocationBuilder buildIntArgMethod() {

`