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

com.fitbur.mockito.verification.VerificationWrapperInOrderWrapper Maven / Gradle / Ivy

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

import com.fitbur.mockito.InOrder;
import com.fitbur.mockito.exceptions.base.MockitoException;
import com.fitbur.mockito.internal.InOrderImpl;
import com.fitbur.mockito.internal.verification.InOrderWrapper;
import com.fitbur.mockito.internal.verification.VerificationModeFactory;
import com.fitbur.mockito.internal.verification.VerificationOverTimeImpl;
import com.fitbur.mockito.internal.verification.api.VerificationData;
import com.fitbur.mockito.internal.verification.api.VerificationInOrderMode;

public class VerificationWrapperInOrderWrapper implements VerificationMode {
    private final VerificationMode delegate;

    public VerificationWrapperInOrderWrapper(VerificationWrapper verificationWrapper, InOrderImpl inOrder) {
        VerificationMode verificationMode = verificationWrapper.wrappedVerification;

        VerificationMode inOrderWrappedVerificationMode = wrapInOrder(verificationWrapper, verificationMode, inOrder);

        delegate = verificationWrapper.copySelfWithNewVerificationMode(inOrderWrappedVerificationMode);
    }

    @Override
    public void verify(VerificationData data) {
        delegate.verify(data);
    }

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

    private VerificationMode wrapInOrder(VerificationWrapper verificationWrapper, VerificationMode verificationMode, InOrderImpl inOrder) {
        if (verificationMode instanceof VerificationInOrderMode) {
            final VerificationInOrderMode verificationInOrderMode = (VerificationInOrderMode)verificationMode;
            return new InOrderWrapper(verificationInOrderMode, inOrder);
        }

        if (verificationMode instanceof VerificationOverTimeImpl) {
            final VerificationOverTimeImpl verificationOverTime = (VerificationOverTimeImpl)verificationMode;
            if (verificationOverTime.isReturnOnSuccess()) {
                return new VerificationOverTimeImpl(verificationOverTime.getPollingPeriodMillis(),
                        verificationOverTime.getTimer().duration(),
                        wrapInOrder(verificationWrapper, verificationOverTime.getDelegate(), inOrder),
                        verificationOverTime.isReturnOnSuccess());
            }
        }

        throw new MockitoException(verificationMode.getClass().getSimpleName() +
                " is not implemented to work with InOrder wrapped inside a " +
                verificationWrapper.getClass().getSimpleName());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy