Package org.mockito.internal.junit
Class VerificationCollectorImpl
- java.lang.Object
-
- org.mockito.internal.junit.VerificationCollectorImpl
-
- All Implemented Interfaces:
org.junit.rules.TestRule
,VerificationCollector
public class VerificationCollectorImpl extends java.lang.Object implements VerificationCollector
Mockito implementation of VerificationCollector.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
VerificationCollectorImpl.VerificationWrapper
-
Field Summary
Fields Modifier and Type Field Description private java.lang.StringBuilder
builder
private int
numberOfFailures
-
Constructor Summary
Constructors Constructor Description VerificationCollectorImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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()
-
-
-
Method Detail
-
apply
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base, org.junit.runner.Description description)
- Specified by:
apply
in interfaceorg.junit.rules.TestRule
-
collectAndReport
public void collectAndReport() throws MockitoAssertionError
Description copied from interface:VerificationCollector
Collect all lazily verified behaviour. If there were failed verifications, it will throw a MockitoAssertionError containing all messages indicating the failed verifications.Normally, 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 }
- Specified by:
collectAndReport
in interfaceVerificationCollector
- Throws:
MockitoAssertionError
- If there were failed verifications
-
assertLazily
public VerificationCollector assertLazily()
Description copied from interface:VerificationCollector
Enforce all verifications are performed lazily. This method is automatically called when used as JUnitRule and normally users don't need to use it.You 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(); }
- Specified by:
assertLazily
in interfaceVerificationCollector
- Returns:
- this
-
resetBuilder
private void resetBuilder()
-
append
private void append(java.lang.String message)
-
-