Search in sources :

Example 16 with VerificationMode

use of org.mockito.verification.VerificationMode in project riposte by Nike-Inc.

the class NonblockingEndpointExecutionHandlerTest method doChannelRead_performs_endpoint_timing_span_annotations_depending_on_tracing_config.

@UseDataProvider("endpointTimingScenarioDataProvider")
@Test
public void doChannelRead_performs_endpoint_timing_span_annotations_depending_on_tracing_config(EndpointTimingScenario scenario) {
    // given
    Span spanMock = mock(Span.class);
    Tracer.getInstance().registerWithThread(new ArrayDeque<>(Collections.singleton(spanMock)));
    assertThat(Tracer.getInstance().getCurrentSpan()).isEqualTo(spanMock);
    // Internal Tracer stuff
    verify(spanMock).getTraceId();
    TracingState tracingStateForTest = TracingState.getCurrentThreadTracingState();
    doReturn(tracingStateForTest.getLeft()).when(stateMock).getDistributedTraceStack();
    doReturn(tracingStateForTest.getRight()).when(stateMock).getLoggerMdcContextMap();
    doReturn(scenario.addStartAnnotation).when(taggingStrategySpy).shouldAddEndpointStartAnnotation();
    doReturn(scenario.startAnnotationName).when(taggingStrategySpy).endpointStartAnnotationName();
    doReturn(scenario.addFinishAnnotation).when(taggingStrategySpy).shouldAddEndpointFinishAnnotation();
    doReturn(scenario.finishAnnotationName).when(taggingStrategySpy).endpointFinishAnnotationName();
    // when
    handlerSpy.doChannelRead(ctxMock, msg);
    // then
    {
        VerificationMode startAnnotationVerification = (scenario.addStartAnnotation) ? times(1) : never();
        verify(spanMock, startAnnotationVerification).addTimestampedAnnotationForCurrentTime(scenario.startAnnotationName);
        // Internal Tracer stuff
        verify(spanMock, atLeastOnce()).getTraceId();
        verifyNoMoreInteractions(spanMock);
    }
    // and when
    futureThatWillBeAttachedToSpy.complete(mock(ResponseInfo.class));
    // then
    {
        VerificationMode finishAnnotationVerification = (scenario.addFinishAnnotation) ? times(1) : never();
        verify(spanMock, finishAnnotationVerification).addTimestampedAnnotationForCurrentTime(scenario.finishAnnotationName);
        verifyNoMoreInteractions(spanMock);
    }
}
Also used : ResponseInfo(com.nike.riposte.server.http.ResponseInfo) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo) Span(com.nike.wingtips.Span) VerificationMode(org.mockito.verification.VerificationMode) TracingState(com.nike.wingtips.util.TracingState) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 17 with VerificationMode

use of org.mockito.verification.VerificationMode in project robozonky by RoboZonky.

the class SellingTest method saleMade.

private void saleMade(final boolean isDryRun) {
    final Investment i = mockInvestment();
    final Zonky zonky = mockApi();
    final Portfolio portfolio = new Portfolio(Collections.singleton(i), mockBalance(zonky));
    new Selling(ALL_ACCEPTING, isDryRun).accept(portfolio, mockAuthentication(zonky));
    final List<Event> e = getNewEvents();
    assertThat(e).hasSize(5);
    assertSoftly(softly -> {
        softly.assertThat(e.get(0)).isInstanceOf(SellingStartedEvent.class);
        softly.assertThat(e.get(1)).isInstanceOf(SaleRecommendedEvent.class);
        softly.assertThat(e.get(2)).isInstanceOf(SaleRequestedEvent.class);
        softly.assertThat(e.get(3)).isInstanceOf(SaleOfferedEvent.class);
        softly.assertThat(e.get(4)).isInstanceOf(SellingCompletedEvent.class);
    });
    final VerificationMode m = isDryRun ? never() : times(1);
    assertThat(i.isOnSmp()).isTrue();
    verify(zonky, m).sell(argThat(inv -> i.getLoanId() == inv.getLoanId()));
}
Also used : InvestmentStatus(com.github.robozonky.api.remote.enums.InvestmentStatus) SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) SoftAssertions(org.assertj.core.api.SoftAssertions) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) Wallet(com.github.robozonky.api.remote.entities.Wallet) Zonky(com.github.robozonky.common.remote.Zonky) Supplier(java.util.function.Supplier) SaleRequestedEvent(com.github.robozonky.api.notifications.SaleRequestedEvent) Event(com.github.robozonky.api.notifications.Event) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) Test(org.junit.jupiter.api.Test) VerificationMode(org.mockito.verification.VerificationMode) BigDecimal(java.math.BigDecimal) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Optional(java.util.Optional) Assertions(org.assertj.core.api.Assertions) AbstractZonkyLeveragingTest(com.github.robozonky.app.AbstractZonkyLeveragingTest) Collections(java.util.Collections) SellStrategy(com.github.robozonky.api.strategies.SellStrategy) SaleRecommendedEvent(com.github.robozonky.api.notifications.SaleRecommendedEvent) SaleRequestedEvent(com.github.robozonky.api.notifications.SaleRequestedEvent) Event(com.github.robozonky.api.notifications.Event) SellingCompletedEvent(com.github.robozonky.api.notifications.SellingCompletedEvent) SellingStartedEvent(com.github.robozonky.api.notifications.SellingStartedEvent) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) VerificationMode(org.mockito.verification.VerificationMode) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) Zonky(com.github.robozonky.common.remote.Zonky)

Example 18 with VerificationMode

use of org.mockito.verification.VerificationMode in project motech by motech.

the class TaskServiceImplTest method captureTask.

private Task captureTask(boolean fromUpdate, VerificationMode verificationMode) {
    VerificationMode mode = (verificationMode == null) ? times(1) : verificationMode;
    ArgumentCaptor<Task> taskCaptor = ArgumentCaptor.forClass(Task.class);
    if (fromUpdate) {
        verify(tasksDataService, mode).update(taskCaptor.capture());
    } else {
        verify(tasksDataService, mode).create(taskCaptor.capture());
    }
    return taskCaptor.getValue();
}
Also used : Task(org.motechproject.tasks.domain.mds.task.Task) VerificationMode(org.mockito.verification.VerificationMode)

Example 19 with VerificationMode

use of org.mockito.verification.VerificationMode in project kie-wb-common by kiegroup.

the class FormEditorPresenterTest method testOnSyncPalette.

private void testOnSyncPalette(boolean noContext) {
    loadContent();
    VerificationMode count = times(1);
    if (noContext) {
        when(editorHelper.getContent()).thenReturn(null);
        count = never();
    }
    FormEditorPresenter presenterSpy = spy(presenter);
    String formId = presenterSpy.getFormDefinition().getId();
    presenterSpy.onSyncPalette(formId);
    Collection<FieldDefinition> availableFieldsValues = editorHelper.getAvailableFields().values();
    verify(presenterSpy, count).removeAllDraggableGroupComponent(presenter.getFormDefinition().getFields());
    verify(presenterSpy, count).removeAllDraggableGroupComponent(availableFieldsValues);
    verify(presenterSpy, count).addAllDraggableGroupComponent(availableFieldsValues);
}
Also used : FieldDefinition(org.kie.workbench.common.forms.model.FieldDefinition) TextBoxFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textBox.definition.TextBoxFieldDefinition) TextAreaFieldDefinition(org.kie.workbench.common.forms.fields.shared.fieldTypes.basic.textArea.definition.TextAreaFieldDefinition) VerificationMode(org.mockito.verification.VerificationMode)

Example 20 with VerificationMode

use of org.mockito.verification.VerificationMode in project mockito by mockito.

the class VerificationListenerCallBackTest method should_call_single_listener_on_verify.

@Test
public void should_call_single_listener_on_verify() throws NoSuchMethodException {
    // given
    RememberingListener listener = new RememberingListener();
    MockitoFramework mockitoFramework = Mockito.framework();
    mockitoFramework.addListener(listener);
    Method invocationWanted = Foo.class.getDeclaredMethod("doSomething", String.class);
    Foo foo = mock(Foo.class);
    // when
    VerificationMode never = never();
    verify(foo, never).doSomething("");
    // then
    assertThat(listener).is(notifiedFor(foo, never, invocationWanted));
}
Also used : MockitoFramework(org.mockito.MockitoFramework) Method(java.lang.reflect.Method) VerificationMode(org.mockito.verification.VerificationMode) Test(org.junit.Test)

Aggregations

VerificationMode (org.mockito.verification.VerificationMode)31 Test (org.junit.Test)18 DummyVerificationMode (org.mockito.internal.verification.DummyVerificationMode)5 MockAwareVerificationMode (org.mockito.internal.verification.MockAwareVerificationMode)3 SnapshotPolicyVO (com.cloud.storage.SnapshotPolicyVO)2 StoragePoolType (com.cloud.storage.Storage.StoragePoolType)2 IntervalType (com.cloud.utils.DateUtil.IntervalType)2 Method (java.lang.reflect.Method)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 AcknowledgeCheckpoint (org.apache.flink.runtime.messages.checkpoint.AcknowledgeCheckpoint)2 DeclineCheckpoint (org.apache.flink.runtime.messages.checkpoint.DeclineCheckpoint)2 OperatorStreamStateHandle (org.apache.flink.runtime.state.OperatorStreamStateHandle)2 PlaceholderStreamStateHandle (org.apache.flink.runtime.state.PlaceholderStreamStateHandle)2 StateHandleID (org.apache.flink.runtime.state.StateHandleID)2 StreamStateHandle (org.apache.flink.runtime.state.StreamStateHandle)2 TestingStreamStateHandle (org.apache.flink.runtime.state.TestingStreamStateHandle)2 ByteStreamStateHandle (org.apache.flink.runtime.state.memory.ByteStreamStateHandle)2