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

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

There is a newer version: 1.0.0
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package com.fitbur.mockito.internal.verification;

import static com.fitbur.mockito.exceptions.Reporter.noMoreInteractionsWanted;
import static com.fitbur.mockito.exceptions.Reporter.wantedButNotInvoked;
import static com.fitbur.mockito.internal.invocation.InvocationMarker.markVerified;

import java.util.List;

import com.fitbur.mockito.internal.invocation.InvocationMatcher;
import com.fitbur.mockito.internal.invocation.InvocationsFinder;
import com.fitbur.mockito.internal.verification.api.VerificationData;
import com.fitbur.mockito.invocation.Invocation;
import com.fitbur.mockito.verification.VerificationMode;

public class Only implements VerificationMode {

    private final InvocationsFinder finder = new InvocationsFinder();

    @SuppressWarnings("unchecked")
    public void verify(VerificationData data) {
        InvocationMatcher wantedMatcher = data.getWanted();
        List invocations = data.getAllInvocations();
        List chunk = finder.findInvocations(invocations,wantedMatcher);
        if (invocations.size() != 1 && chunk.size() > 0) {            
            Invocation unverified = finder.findFirstUnverified(invocations);
            throw noMoreInteractionsWanted(unverified, (List) invocations);
        } 
        if (invocations.size() != 1 || chunk.size() == 0) {
            throw wantedButNotInvoked(wantedMatcher);
        }
        markVerified(chunk.get(0), wantedMatcher);
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy