forked from mockito/mockito
/
MockAwareVerificationMode.java
49 lines (39 loc) · 1.44 KB
/
MockAwareVerificationMode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Copyright (c) 2007 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.verification;
import org.mockito.internal.progress.MockingProgress;
import org.mockito.internal.verification.api.VerificationData;
import org.mockito.verification.VerificationMode;
public class MockAwareVerificationMode implements VerificationMode {
private final Object mock;
private final VerificationMode mode;
private final MockingProgress mockingProgress;
public MockAwareVerificationMode(Object mock, VerificationMode mode, MockingProgress mockingProgress) {
this.mock = mock;
this.mode = mode;
this.mockingProgress = mockingProgress;
}
public void verify(VerificationData data) {
try {
mode.verify(data);
} catch (RuntimeException e) {
fireVerificationEvent( data, e);
throw e;
} catch (Error e) {
fireVerificationEvent(data, e);
throw e;
}
fireVerificationEvent(data,null);
}
private void fireVerificationEvent(VerificationData data, Throwable error) {
mockingProgress.fireVerificationEvent(new VerificationEventImpl(mock, mode, data, error));
}
public Object getMock() {
return mock;
}
public VerificationMode description(String description) {
return VerificationModeFactory.description(this, description);
}
}