/
Description.java
48 lines (42 loc) · 1.59 KB
/
Description.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
/*
* Copyright (c) 2016 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.verification;
import org.mockito.exceptions.base.MockitoAssertionError;
import org.mockito.internal.verification.api.VerificationData;
import org.mockito.verification.VerificationMode;
/**
* Description verification mode wraps an existing verification mode and prepends
* a custom message to the assertion error if verification fails.
* @author Geoff.Schoeman
* @since 2.1.0
*/
public class Description implements VerificationMode {
private final VerificationMode verification;
private final String description;
/**
* Constructs a verification mode which wraps the given verification mode.
* @param verification The implementation to use for verification
* @param description The failure message to prepend if verification fails
*/
public Description(VerificationMode verification, String description) {
this.verification = verification;
this.description = description;
}
/**
* Performs verification using the wrapped verification mode implementation.
* Prepends the custom failure message if verification fails.
* @param data the data to be verified
*/
@Override
public void verify(VerificationData data) {
try {
verification.verify(data);
} catch (MockitoAssertionError e) {
throw new MockitoAssertionError(e, description);
} catch (AssertionError e) {
throw new MockitoAssertionError(e, description);
}
}
}