org.mockito.verification.VerificationMode Java Examples

The following examples show how to use org.mockito.verification.VerificationMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractInteropTest.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
/**
 * Wrapper around {@link Mockito#verify}, to keep log spam down on failure.
 */
private static <T> T verify(T mock, VerificationMode mode) {
  try {
    return Mockito.verify(mock, mode);
  } catch (final AssertionError e) {
    String msg = e.getMessage();
    if (msg.length() >= 256) {
      // AssertionError(String, Throwable) only present in Android API 19+
      throw new AssertionError(msg.substring(0, 256)) {
        @Override
        public synchronized Throwable getCause() {
          return e;
        }
      };
    }
    throw e;
  }
}
 
Example #2
Source File: TestZKProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Wait for the coordinator task to complete, and verify all the mocks
 * @param op the {@link Subprocedure} to use
 * @param prepare the mock prepare
 * @param commit the mock commit
 * @param cleanup the mock cleanup
 * @param finish the mock finish
 * @param opHasError the operation error state
 * @throws Exception on unexpected failure
 */
private void waitAndVerifySubproc(Subprocedure op, VerificationMode prepare,
    VerificationMode commit, VerificationMode cleanup, VerificationMode finish, boolean opHasError)
    throws Exception {
  boolean caughtError = false;
  try {
    op.waitForLocallyCompleted();
  } catch (ForeignException fe) {
    caughtError = true;
  }
  // make sure that the task called all the expected phases
  Mockito.verify(op, prepare).acquireBarrier();
  Mockito.verify(op, commit).insideBarrier();
  // We cannot guarantee that cleanup has run so we don't check it.

  assertEquals("Operation error state was unexpected", opHasError, op.getErrorCheckable()
      .hasException());
  assertEquals("Operation error state was unexpected", opHasError, caughtError);

}
 
Example #3
Source File: WindowOperatorContractTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyTriggerCallback(
		Trigger<?, TimeWindow> mockTrigger,
		VerificationMode verificationMode,
		Long time,
		TimeWindow window) throws Exception {
	if (time == null && window == null) {
		verify(mockTrigger, verificationMode).onEventTime(
				anyLong(),
				anyTimeWindow(),
				anyTriggerContext());
	} else if (time == null) {
		verify(mockTrigger, verificationMode).onEventTime(
				anyLong(),
				eq(window),
				anyTriggerContext());
	} else if (window == null) {
		verify(mockTrigger, verificationMode).onEventTime(
				eq(time),
				anyTimeWindow(),
				anyTriggerContext());
	} else {
		verify(mockTrigger, verificationMode).onEventTime(
				eq(time),
				eq(window),
				anyTriggerContext());
	}
}
 
Example #4
Source File: ProjectApiControllerTest.java    From ods-provisioning-app with Apache License 2.0 5 votes vote down vote up
public void verifyAddProjectAdapterCalls(VerificationMode times, VerificationMode confluenceTimes)
    throws IOException, CreateProjectPreconditionException {
  Mockito.verify(jenkinsPipelineAdapter, times).createPlatformProjects(isNotNull());
  // check preconditions should be always called
  Mockito.verify(bitbucketAdapter, times(1)).checkCreateProjectPreconditions(isNotNull());
  Mockito.verify(bitbucketAdapter, times).createSCMProjectForODSProject(isNotNull());
  Mockito.verify(bitbucketAdapter, times).createComponentRepositoriesForODSProject(isNotNull());
  // jira components
  Mockito.verify(jiraAdapter, times)
      .createComponentsForProjectRepositories(isNotNull(), isNotNull());

  Mockito.clearInvocations(
      jiraAdapter, confluenceAdapter, bitbucketAdapter, jenkinsPipelineAdapter);
}
 
Example #5
Source File: AbstractMockitoVerification.java    From camunda-bpm-mockito with Apache License 2.0 5 votes vote down vote up
@Override
public final ArgumentCaptor<P> executed(final VerificationMode verificationMode) {
  try {
    doVerify(verificationMode);
  } catch (final Exception e) {
    throw new RuntimeException(e);
  }
  return argumentCaptor;
}
 
Example #6
Source File: WorkflowEntryWriteToLogTest.java    From hop with Apache License 2.0 5 votes vote down vote up
private void verifyErrorMessageForParentJobLogLevel( LogLevel parentJobLogLevel, VerificationMode mode ) {
  action.setLogMessage( "TEST" );
  action.setEntryLogLevel( LogLevel.ERROR );

  doReturn( parentJobLogLevel ).when( parentWorkflow ).getLogLevel();
  action.setParentWorkflow( parentWorkflow );

  ILogChannel logChannel = spy( action.createLogChannel() );
  doReturn( logChannel ).when( action ).createLogChannel();

  action.evaluate( new Result() );
  verify( logChannel, mode ).logError( "TEST" + Const.CR );
}
 
Example #7
Source File: WindowOperatorContractTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyTriggerCallback(
		Trigger<?, TimeWindow> mockTrigger,
		VerificationMode verificationMode,
		Long time,
		TimeWindow window) throws Exception {
	if (time == null && window == null) {
		verify(mockTrigger, verificationMode).onProcessingTime(
				anyLong(),
				anyTimeWindow(),
				anyTriggerContext());
	} else if (time == null) {
		verify(mockTrigger, verificationMode).onProcessingTime(
				anyLong(),
				eq(window),
				anyTriggerContext());
	} else if (window == null) {
		verify(mockTrigger, verificationMode).onProcessingTime(
				eq(time),
				anyTimeWindow(),
				anyTriggerContext());
	} else {
		verify(mockTrigger, verificationMode).onProcessingTime(
				eq(time),
				eq(window),
				anyTriggerContext());
	}
}
 
Example #8
Source File: ErrorHandlerVerifier.java    From artio with Apache License 2.0 5 votes vote down vote up
static void verify(
    final ErrorHandler mockErrorHandler,
    final VerificationMode times,
    final Class<? extends Throwable> exception)
{
    try
    {
        Mockito.verify(mockErrorHandler, times).onError(any(exception));
    }
    finally
    {
        reset(mockErrorHandler);
    }
}
 
Example #9
Source File: MetricFilteringBoltTest.java    From monasca-thresh with Apache License 2.0 5 votes vote down vote up
private void verifyNewMetricDefinitionMessages(List<Alarm> alarms, final OutputCollector collector,
      final MetricFilteringBolt bolt, VerificationMode howMany) {
  for (final Alarm alarm : alarms) {
    for (MetricDefinitionAndTenantId mtid : alarm.getAlarmedMetrics()) {
      verify(collector, howMany)
          .emit(MetricFilteringBolt.NEW_METRIC_FOR_ALARM_DEFINITION_STREAM, new Values(mtid, alarm.getAlarmDefinitionId()));
    }
  }
}
 
Example #10
Source File: MockitoCore.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public <T> T verify(T mock, VerificationMode mode) {
    if (mock == null) {
        reporter.nullPassedToVerify();
    } else if (!mockUtil.isMock(mock)) {
        reporter.notAMockPassedToVerify(mock.getClass());
    }
    mockingProgress.verificationStarted(new MockAwareVerificationMode(mock, mode));
    return mock;
}
 
Example #11
Source File: ReplayerTest.java    From artio with Apache License 2.0 5 votes vote down vote up
private void assertSentGapFill(
    final int msgSeqNum,
    final int newSeqNo,
    final int offset,
    final VerificationMode times)
{
    verifyClaim();
    assertResultBufferHasGapFillMessage(resultBuffer.capacity() - offset, msgSeqNum, newSeqNo);
    verifyCommit(times);
}
 
Example #12
Source File: InOrderImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public <T> T verify(T mock, VerificationMode mode) {
    if (!mocksToBeVerifiedInOrder.contains(mock)) {
        reporter.inOrderRequiresFamiliarMock();
    } else if (!(mode instanceof VerificationInOrderMode)) {
        throw new MockitoException(mode.getClass().getSimpleName() + " is not implemented to work with InOrder");
    }
    return mockitoCore.verify(mock, new InOrderWrapper((VerificationInOrderMode) mode, this));
}
 
Example #13
Source File: FramerTest.java    From artio with Apache License 2.0 5 votes vote down vote up
private void verifySessionsAcquired(final SessionState state, final VerificationMode times)
{
    verify(gatewaySessions, times).acquire(
        any(),
        eq(state),
        eq(false),
        eq(HEARTBEAT_INTERVAL_IN_S),
        anyInt(),
        anyInt(),
        any(),
        any(),
        any());
}
 
Example #14
Source File: WindowOperatorContractTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void verifyTriggerCallback(
		Trigger<?, TimeWindow> mockTrigger,
		VerificationMode verificationMode,
		Long time,
		TimeWindow window) throws Exception {
	if (time == null && window == null) {
		verify(mockTrigger, verificationMode).onEventTime(
				anyLong(),
				anyTimeWindow(),
				anyTriggerContext());
	} else if (time == null) {
		verify(mockTrigger, verificationMode).onEventTime(
				anyLong(),
				eq(window),
				anyTriggerContext());
	} else if (window == null) {
		verify(mockTrigger, verificationMode).onEventTime(
				eq(time),
				anyTimeWindow(),
				anyTriggerContext());
	} else {
		verify(mockTrigger, verificationMode).onEventTime(
				eq(time),
				eq(window),
				anyTriggerContext());
	}
}
 
Example #15
Source File: ReceiverEndPointTest.java    From artio with Apache License 2.0 5 votes vote down vote up
private void savesInvalidChecksumMessage(final VerificationMode mode)
{
    verify(publication, mode).saveMessage(
        anyBuffer(),
        eq(0),
        eq(INVALID_CHECKSUM_LEN),
        eq(LIBRARY_ID),
        eq(MESSAGE_TYPE),
        anyLong(),
        anyInt(),
        eq(CONNECTION_ID),
        eq(INVALID_CHECKSUM),
        eq(0),
        eq(TIMESTAMP));
}
 
Example #16
Source File: ReceiverEndPointTest.java    From artio with Apache License 2.0 5 votes vote down vote up
private void savesInvalidMessage(
    final int length, final VerificationMode mode, final MessageStatus status, final long timestamp)
{
    verify(publication, mode).saveMessage(
        anyBuffer(), eq(0), eq(length), eq(LIBRARY_ID),
        anyLong(), anyLong(), anyInt(), eq(CONNECTION_ID),
        eq(status), eq(0), eq(timestamp));
}
 
Example #17
Source File: PushUnregisteredTest.java    From mobile-messaging-sdk-android with Apache License 2.0 5 votes vote down vote up
private void verifySeenStatusReporter(VerificationMode verificationMode) throws InterruptedException {
    String[] messageIds = {"1"};
    mobileMessagingCore.setMessagesSeen(messageIds);
    seenStatusReporter.sync();

    verify(coreBroadcaster, verificationMode).seenStatusReported(any(String[].class));
}
 
Example #18
Source File: SenderEndPointTest.java    From artio with Apache License 2.0 5 votes vote down vote up
private void byteBufferWritten(final VerificationMode times)
{
    try
    {
        verify(tcpChannel, times).write(byteBuffer);
        reset(tcpChannel);
    }
    catch (final IOException e)
    {
        LangUtil.rethrowUnchecked(e);
    }
}
 
Example #19
Source File: MockingProgressImpl.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public VerificationMode pullVerificationMode() {
    if (verificationMode == null) {
        return null;
    }
    
    VerificationMode temp = verificationMode.getObject();
    verificationMode = null;
    return temp;
}
 
Example #20
Source File: LoadBalancingProviderTest.java    From ocelli with Apache License 2.0 5 votes vote down vote up
protected Connection<String, String> assertNextConnection(SocketAddress host,
                                                          ConnectionFactory<String, String> cfMock,
                                                          ConnectionObservable<String, String> connectionObservable,
                                                          VerificationMode verificationMode) {
    Connection<String, String> c = loadBalancerRule.connect(connectionObservable);
    verify(cfMock, verificationMode).newConnection(host);
    return c;
}
 
Example #21
Source File: ReceiverEndPointTest.java    From artio with Apache License 2.0 4 votes vote down vote up
private void savesInvalidOutOfRequiredMessage(final VerificationMode mode, final long timestamp)
{
    savesInvalidMessage(TAG_SPECIFIED_OUT_OF_REQUIRED_ORDER_MESSAGE_BYTES.length, mode, INVALID, timestamp);
}
 
Example #22
Source File: AbstractSessionTest.java    From artio with Apache License 2.0 4 votes vote down vote up
public void verifyLogout(final int msgSeqNo, final VerificationMode times)
{
    verify(sessionProxy, times).sendLogout(msgSeqNo, SEQUENCE_INDEX, NO_LAST_MSG_SEQ_NUM_PROCESSED);
}
 
Example #23
Source File: SenderEndPointTest.java    From artio with Apache License 2.0 4 votes vote down vote up
private void verifySlowConsumerDisconnect(final VerificationMode times)
{
    verify(framer, times).onDisconnect(LIBRARY_ID, CONNECTION_ID, SLOW_CONSUMER);
}
 
Example #24
Source File: AbstractSessionTest.java    From artio with Apache License 2.0 4 votes vote down vote up
private void verifyNotifiesLoginListener(final VerificationMode verificationMode)
{
    verify(mockLogonListener, verificationMode).onLogon(any());
}
 
Example #25
Source File: VerificationOverTimeImpl.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
public VerificationMode getDelegate() {
    return delegate;
}
 
Example #26
Source File: RestAdminControllerTest.java    From codenjoy with GNU General Public License v3.0 4 votes vote down vote up
private void verifyNewGame(PlayerGame playerGame, VerificationMode mode) {
    verify(playerGame.getField(), mode).newGame(playerGame.getGame().getPlayer());
}
 
Example #27
Source File: WithMockito.java    From mockito-java8 with Apache License 2.0 4 votes vote down vote up
/**
 * Delegates call to {@link Mockito#calls(int)}.
 */
default VerificationMode calls(int wantedNumberOfInvocations){
    return Mockito.calls(wantedNumberOfInvocations);
}
 
Example #28
Source File: PlayerGamesMultiplayerTest.java    From codenjoy with GNU General Public License v3.0 4 votes vote down vote up
private void verifyFieldTicks(GameField field, VerificationMode count) {
    verify(field, count).quietTick();
}
 
Example #29
Source File: WithMockito.java    From mockito-java8 with Apache License 2.0 4 votes vote down vote up
/**
 * Delegates call to {@link Mockito#times(int)}.
 */
default VerificationMode times(int wantedNumberOfInvocations) {
    return Mockito.times(wantedNumberOfInvocations);
}
 
Example #30
Source File: PlayerGamesMultiplayerTest.java    From codenjoy with GNU General Public License v3.0 4 votes vote down vote up
private void verifyAllFieldsTicks(VerificationMode count) {
    getFileds.forEach(field -> verifyFieldTicks(field.get(), count));
}