• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hazendaz / jmockit1 / 496

15 Nov 2025 05:33PM UTC coverage: 72.192% (-0.008%) from 72.2%
496

push

github

web-flow
Merge pull request #412 from hazendaz/renovate/major-spring-core

Update spring core to v7 (major)

5677 of 8360 branches covered (67.91%)

Branch coverage included in aggregate %.

11922 of 16018 relevant lines covered (74.43%)

0.74 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.9
/main/src/main/java/mockit/internal/expectations/OrderedVerificationPhase.java
1
/*
2
 * MIT License
3
 * Copyright (c) 2006-2025 JMockit developers
4
 * See LICENSE file for full license text.
5
 */
6
package mockit.internal.expectations;
7

8
import static java.util.Collections.emptyList;
9

10
import edu.umd.cs.findbugs.annotations.NonNull;
11
import edu.umd.cs.findbugs.annotations.Nullable;
12

13
import java.util.Collections;
14
import java.util.List;
15

16
import mockit.internal.expectations.invocation.ExpectedInvocation;
17

18
import org.checkerframework.checker.index.qual.NonNegative;
19

20
final class OrderedVerificationPhase extends BaseVerificationPhase {
21
    @NonNegative
22
    private final int expectationCount;
23
    @NonNegative
24
    private int indexIncrement;
25

26
    OrderedVerificationPhase(@NonNull ReplayPhase replayPhase) {
27
        super(replayPhase);
1✔
28
        discardExpectationsAndArgumentsAlreadyVerified(replayPhase.invocations);
1✔
29
        expectationCount = replayPhase.invocations.size();
1✔
30
        indexIncrement = 1;
1✔
31
    }
1✔
32

33
    private void discardExpectationsAndArgumentsAlreadyVerified(List<Expectation> expectationsInReplayOrder) {
34
        for (VerifiedExpectation verified : executionState.verifiedExpectations) {
1✔
35
            int i = expectationsInReplayOrder.indexOf(verified.expectation);
1✔
36

37
            if (i >= 0) {
1!
38
                expectationsInReplayOrder.set(i, null);
1✔
39
            }
40
        }
1✔
41
    }
1✔
42

43
    @NonNull
44
    @Override
45
    List<ExpectedInvocation> findExpectation(@Nullable Object mock, @NonNull String mockClassDesc,
46
            @NonNull String mockNameAndDesc, @NonNull Object[] args) {
47
        Expectation expectation = currentVerification;
1✔
48
        int i = replayIndex;
1✔
49

50
        while (i >= 0 && i < expectationCount) {
1!
51
            Expectation replayExpectation = replayPhase.invocations.get(i);
1✔
52
            Object replayInstance = replayPhase.invocationInstances.get(i);
1✔
53
            Object[] replayArgs = replayPhase.invocationArguments.get(i);
1✔
54

55
            i += indexIncrement;
1✔
56

57
            if (replayExpectation == null) {
1✔
58
                continue;
1✔
59
            }
60

61
            if (!matchInstance && executionState.isToBeMatchedOnInstance(mock, mockNameAndDesc)) {
1✔
62
                matchInstance = true;
1✔
63
            }
64

65
            if (matches(mock, mockClassDesc, mockNameAndDesc, args, replayExpectation, replayInstance, replayArgs)) {
1✔
66
                currentExpectation = replayExpectation;
1✔
67
                i += 1 - indexIncrement;
1✔
68
                indexIncrement = 1;
1✔
69
                replayIndex = i;
1✔
70

71
                if (expectation != null) {
1!
72
                    expectation.constraints.invocationCount++;
1✔
73
                }
74

75
                break;
76
            }
77
        }
1✔
78

79
        return emptyList();
1✔
80
    }
81

82
    @Override
83
    void addVerifiedExpectation(@NonNull Expectation expectation, @NonNull Object[] args) {
84
        VerifiedExpectation verifiedExpectation = new VerifiedExpectation(expectation, args, argMatchers, replayIndex);
1✔
85
        addVerifiedExpectation(verifiedExpectation);
1✔
86
    }
1✔
87

88
    @Override
89
    @SuppressWarnings("OverlyComplexMethod")
90
    void handleInvocationCountConstraint(int minInvocations, int maxInvocations) {
91
        Error errorThrown = pendingError;
1✔
92
        pendingError = null;
1✔
93

94
        if (errorThrown != null && minInvocations > 0) {
1✔
95
            throw errorThrown;
1✔
96
        }
97

98
        Expectation verifying = currentVerification;
1✔
99

100
        if (verifying == null) {
1!
101
            return;
×
102
        }
103

104
        ExpectedInvocation invocation = verifying.invocation;
1✔
105
        argMatchers = invocation.arguments.getMatchers();
1✔
106
        int invocationCount = 1;
1✔
107

108
        while (replayIndex < expectationCount) {
1✔
109
            Expectation replayExpectation = replayPhase.invocations.get(replayIndex);
1✔
110

111
            if (replayExpectation != null && matchesCurrentVerification(invocation, replayExpectation)) {
1✔
112
                invocationCount++;
1✔
113
                verifying.constraints.invocationCount++;
1✔
114

115
                if (invocationCount > maxInvocations) {
1✔
116
                    if (maxInvocations >= 0) {
1✔
117
                        throw replayExpectation.invocation.errorForUnexpectedInvocation();
1✔
118
                    }
119

120
                    break;
121
                }
122
            } else if (invocationCount >= minInvocations) {
1✔
123
                break;
1✔
124
            }
125

126
            replayIndex++;
1✔
127
        }
1✔
128

129
        argMatchers = null;
1✔
130

131
        int n = minInvocations - invocationCount;
1✔
132

133
        if (n > 0) {
1✔
134
            throw invocation.errorForMissingInvocations(n, Collections.<ExpectedInvocation> emptyList());
1✔
135
        }
136

137
        verifyMaxInvocations(verifying, maxInvocations);
1✔
138
    }
1✔
139

140
    private boolean matchesCurrentVerification(@NonNull ExpectedInvocation invocation,
141
            @NonNull Expectation replayExpectation) {
142
        Object mock = invocation.instance;
1✔
143
        String mockClassDesc = invocation.getClassDesc();
1✔
144
        String mockNameAndDesc = invocation.getMethodNameAndDescription();
1✔
145
        Object[] args = invocation.arguments.getValues();
1✔
146
        matchInstance = invocation.matchInstance;
1✔
147

148
        if (executionState.isToBeMatchedOnInstance(mock, mockNameAndDesc)) {
1✔
149
            matchInstance = true;
1✔
150
        }
151

152
        Object replayInstance = replayPhase.invocationInstances.get(replayIndex);
1✔
153
        Object[] replayArgs = replayPhase.invocationArguments.get(replayIndex);
1✔
154

155
        return matches(mock, mockClassDesc, mockNameAndDesc, args, replayExpectation, replayInstance, replayArgs);
1✔
156
    }
157

158
    private void verifyMaxInvocations(@NonNull Expectation verifying, int maxInvocations) {
159
        if (maxInvocations >= 0) {
1✔
160
            int n = verifying.constraints.invocationCount - maxInvocations;
1✔
161

162
            if (n > 0) {
1✔
163
                Object[] replayArgs = replayPhase.invocationArguments.get(replayIndex - 1);
1✔
164
                throw verifying.invocation.errorForUnexpectedInvocations(replayArgs, n);
1✔
165
            }
166
        }
167
    }
1✔
168
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc