public class VerificationCollectorImpl extends java.lang.Object implements VerificationCollector
| Modifier and Type | Class and Description |
|---|---|
private class |
VerificationCollectorImpl.VerificationWrapper |
| Modifier and Type | Field and Description |
|---|---|
private java.lang.StringBuilder |
builder |
private int |
numberOfFailures |
| Constructor and Description |
|---|
VerificationCollectorImpl() |
| Modifier and Type | Method and Description |
|---|---|
private void |
append(java.lang.String message) |
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
VerificationCollector |
assertLazily()
Enforce all verifications are performed lazily.
|
void |
collectAndReport()
Collect all lazily verified behaviour.
|
private void |
resetBuilder() |
private java.lang.StringBuilder builder
private int numberOfFailures
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description)
apply in interface org.junit.rules.TestRulepublic void collectAndReport()
throws MockitoAssertionError
VerificationCollectorNormally, users don't need to call this method because it is automatically invoked when test finishes (part of the JUnit Rule behavior). However, in some circumstances and edge cases, it might be useful to collect and report verification errors in the middle of the test (for example: some scenario tests or during debugging).
@Rule
public VerificationCollector collector = MockitoJUnit.collector();
@Test
public void should_fail() {
IMethods methods = mock(IMethods.class);
verify(methods).byteReturningMethod();
verify(methods).simpleMethod();
//report all verification errors now:
collector.collectAndReport();
//some other test code
}
collectAndReport in interface VerificationCollectorMockitoAssertionError - If there were failed verificationspublic VerificationCollector assertLazily()
VerificationCollectorYou should only use this method if you are using a VerificationCollector inside a method where only this method should be verified lazily. The other methods can still be verified directly.
@Test
public void should_verify_lazily() {
VerificationCollector collector = MockitoJUnit.collector().assertLazily();
verify(methods).byteReturningMethod();
verify(methods).simpleMethod();
collector.collectAndReport();
}
assertLazily in interface VerificationCollectorprivate void resetBuilder()
private void append(java.lang.String message)