All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.fitbur.mockito.internal.verification.Description Maven / Gradle / Ivy

There is a newer version: 1.0.0
Show newest version
package com.fitbur.mockito.internal.verification;

import com.fitbur.mockito.exceptions.base.MockitoAssertionError;
import com.fitbur.mockito.internal.verification.api.VerificationData;
import com.fitbur.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.0.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 
     */
    @Override
    public void verify(VerificationData data) {
        try {
            verification.verify(data);
            
        } catch (MockitoAssertionError e) {
            throw new MockitoAssertionError(e, description);
        }
    } 

    @Override
    public VerificationMode description(String description) {
        return VerificationModeFactory.description(this, description);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy