Java Code Examples for org.mockito.mockito#inOrder()
The following examples show how to use
org.mockito.mockito#inOrder() .
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: DefaultVisitControllerTest.java From closure-stylesheets with Apache License 2.0 | 7 votes |
@Test public void testVisitFunctionNode() { CssDefinitionNode def = new CssDefinitionNode(new CssLiteralNode("FOO")); CssFunctionNode func = new CssFunctionNode(Function.byName("url"), null); CssStringNode argument = new CssStringNode(Type.SINGLE_QUOTED_STRING, "some_url"); func.setArguments(new CssFunctionArgumentsNode(ImmutableList.<CssValueNode>of(argument))); def.addChildToBack(func); // Visit children when(testVisitor.enterFunctionNode(any(CssFunctionNode.class))).thenReturn(true); DefaultVisitController controller = new DefaultVisitController(def, true); controller.startVisit(testVisitor); ArgumentCaptor<CssValueNode> argCaptor = ArgumentCaptor.forClass(CssValueNode.class); InOrder inOrder = Mockito.inOrder(testVisitor); inOrder.verify(testVisitor).enterDefinition(def); inOrder.verify(testVisitor).enterFunctionNode(func); inOrder.verify(testVisitor).enterArgumentNode(argCaptor.capture()); inOrder.verify(testVisitor).leaveArgumentNode(argCaptor.capture()); inOrder.verify(testVisitor).leaveFunctionNode(func); inOrder.verify(testVisitor).leaveDefinition(def); inOrder.verifyNoMoreInteractions(); assertThat(argCaptor.getValue().toString()).isEqualTo(argument.toString()); }
Example 2
Source File: CaseInstanceRestServiceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 6 votes |
@Test public void testSecondarySortingAsPost() { InOrder inOrder = Mockito.inOrder(mockedQuery); Map<String, Object> json = new HashMap<String, Object>(); json.put("sorting", OrderingBuilder.create() .orderBy("caseInstanceId").desc() .orderBy("caseDefinitionId").asc() .getJson()); given().contentType(POST_JSON_CONTENT_TYPE).body(json) .header("accept", MediaType.APPLICATION_JSON) .then().expect().statusCode(Status.OK.getStatusCode()) .when().post(CASE_INSTANCE_QUERY_URL); inOrder.verify(mockedQuery).orderByCaseInstanceId(); inOrder.verify(mockedQuery).desc(); inOrder.verify(mockedQuery).orderByCaseDefinitionId(); inOrder.verify(mockedQuery).asc(); }
Example 3
Source File: TripleCollectTest.java From metafacture-core with Apache License 2.0 | 6 votes |
@Test public void testShouldDecodeEntities() { collect.process(new Triple(REC_ID, ENTITY_NAME, Formeta.GROUP_START +NAME + Formeta.NAME_VALUE_SEPARATOR + VALUE + Formeta.ITEM_SEPARATOR + ENTITY_NAME + Formeta.GROUP_START + NAME + Formeta.NAME_VALUE_SEPARATOR + VALUE + Formeta.GROUP_END + Formeta.GROUP_END, ObjectType.ENTITY)); collect.closeStream(); final InOrder ordered = Mockito.inOrder(receiver); ordered.verify(receiver).startRecord(REC_ID); ordered.verify(receiver).startEntity(ENTITY_NAME); ordered.verify(receiver).literal(NAME, VALUE); ordered.verify(receiver).startEntity(ENTITY_NAME); ordered.verify(receiver).literal(NAME, VALUE); ordered.verify(receiver, Mockito.times(2)).endEntity(); ordered.verify(receiver).endRecord(); }
Example 4
Source File: VolumeApiServiceImplTest.java From cloudstack with Apache License 2.0 | 6 votes |
@Test public void validateConditionsToReplaceDiskOfferingOfVolumeTestEverythingWorking() { Mockito.lenient().when(volumeVoMock.getVolumeType()).thenReturn(Type.DATADISK); Mockito.when(newDiskOfferingMock.isUseLocalStorage()).thenReturn(false); Mockito.when(storagePoolMock.isShared()).thenReturn(true); Mockito.lenient().when(newDiskOfferingMock.isShared()).thenReturn(true); Mockito.when(storagePoolMock.isLocal()).thenReturn(false); Mockito.when(newDiskOfferingMock.getTags()).thenReturn("tag1"); Mockito.doReturn("tag1").when(volumeApiServiceImpl).getStoragePoolTags(storagePoolMock); volumeApiServiceImpl.validateConditionsToReplaceDiskOfferingOfVolume(volumeVoMock, newDiskOfferingMock, storagePoolMock); InOrder inOrder = Mockito.inOrder(volumeVoMock, newDiskOfferingMock, storagePoolMock, volumeApiServiceImpl); inOrder.verify(storagePoolMock).isShared(); inOrder.verify(newDiskOfferingMock).isUseLocalStorage(); inOrder.verify(storagePoolMock).isLocal(); inOrder.verify(newDiskOfferingMock, times(0)).isShared(); inOrder.verify(volumeApiServiceImpl).getStoragePoolTags(storagePoolMock); inOrder.verify(volumeVoMock).getSize(); inOrder.verify(newDiskOfferingMock).getDiskSize(); }
Example 5
Source File: ProtoWriteSupportTest.java From parquet-mr with Apache License 2.0 | 6 votes |
@Test public void testProto3RepeatedIntMessage() throws Exception { RecordConsumer readConsumerMock = Mockito.mock(RecordConsumer.class); ProtoWriteSupport instance = createReadConsumerInstance(TestProto3.RepeatedIntMessage.class, readConsumerMock); TestProto3.RepeatedIntMessage.Builder msg = TestProto3.RepeatedIntMessage.newBuilder(); msg.addRepeatedInt(1323); msg.addRepeatedInt(54469); instance.write(msg.build()); InOrder inOrder = Mockito.inOrder(readConsumerMock); inOrder.verify(readConsumerMock).startMessage(); inOrder.verify(readConsumerMock).startField("repeatedInt", 0); inOrder.verify(readConsumerMock).addInteger(1323); inOrder.verify(readConsumerMock).addInteger(54469); inOrder.verify(readConsumerMock).endField("repeatedInt", 0); inOrder.verify(readConsumerMock).endMessage(); Mockito.verifyNoMoreInteractions(readConsumerMock); }
Example 6
Source File: MetricTest.java From cloudbreak with Apache License 2.0 | 6 votes |
@Test public void testMetricsWhenAutofailSuspendsCluster() { metricService.submit(MetricType.CLUSTER_STATE_ACTIVE, 2); when(clusterRepository.findById(CLUSTER_ID)).thenReturn(Optional.of(getACluster(ClusterState.RUNNING))); when(clusterRepository.save(any())).thenAnswer(this::saveCluster); when(clusterRepository.countByStateAndAutoscalingEnabledAndPeriscopeNodeId(eq(ClusterState.RUNNING), eq(true), anyString())) .thenReturn(0); when(clusterRepository.countByStateAndAutoscalingEnabledAndPeriscopeNodeId(eq(ClusterState.SUSPENDED), eq(true), anyString())) .thenReturn(1); when(cloudbreakClient.autoscaleEndpoint()).thenReturn(autoscaleEndpoint); when(autoscaleEndpoint.get(eq(STACK_CRN))).thenReturn(getStackResponse(AVAILABLE, AVAILABLE)); ReflectionTestUtils.setField(updateFailedHandler, "updateFailures", getUpdateFailures(CLUSTER_ID)); updateFailedHandler.onApplicationEvent(new UpdateFailedEvent(CLUSTER_ID)); MultiValueMap<String, String> metrics = responseToMap(readMetricsEndpoint()); assertEquals(0.0, Double.parseDouble(metrics.get(toReportedMetricName(PERISCOPE_METRICS_CLUSTER_STATE_ACTIVE, false)).get(0)), DELTA); assertEquals(1.0, Double.parseDouble(metrics.get(toReportedMetricName(PERISCOPE_METRICS_CLUSTER_STATE_SUSPENDED, false)).get(0)), DELTA); InOrder inOrder = Mockito.inOrder(clusterRepository); inOrder.verify(clusterRepository).save(argThat(x -> x.getId() == CLUSTER_ID && !x.isRunning())); inOrder.verify(clusterRepository).countByStateAndAutoscalingEnabledAndPeriscopeNodeId(eq(ClusterState.RUNNING), eq(true), anyString()); inOrder.verify(clusterRepository).countByStateAndAutoscalingEnabledAndPeriscopeNodeId(eq(ClusterState.SUSPENDED), eq(true), anyString()); }
Example 7
Source File: ProtoWriteSupportTest.java From parquet-mr with Apache License 2.0 | 5 votes |
@Test public void testRepeatedIntMessageSpecsCompliant() throws Exception { RecordConsumer readConsumerMock = Mockito.mock(RecordConsumer.class); Configuration conf = new Configuration(); ProtoWriteSupport.setWriteSpecsCompliant(conf, true); ProtoWriteSupport instance = createReadConsumerInstance(TestProtobuf.RepeatedIntMessage.class, readConsumerMock, conf); TestProtobuf.RepeatedIntMessage.Builder msg = TestProtobuf.RepeatedIntMessage.newBuilder(); msg.addRepeatedInt(1323); msg.addRepeatedInt(54469); instance.write(msg.build()); InOrder inOrder = Mockito.inOrder(readConsumerMock); inOrder.verify(readConsumerMock).startMessage(); inOrder.verify(readConsumerMock).startField("repeatedInt", 0); inOrder.verify(readConsumerMock).startGroup(); inOrder.verify(readConsumerMock).startField("list", 0); inOrder.verify(readConsumerMock).startGroup(); inOrder.verify(readConsumerMock).startField("element", 0); inOrder.verify(readConsumerMock).addInteger(1323); inOrder.verify(readConsumerMock).endField("element", 0); inOrder.verify(readConsumerMock).endGroup(); inOrder.verify(readConsumerMock).startGroup(); inOrder.verify(readConsumerMock).startField("element", 0); inOrder.verify(readConsumerMock).addInteger(54469); inOrder.verify(readConsumerMock).endField("element", 0); inOrder.verify(readConsumerMock).endGroup(); inOrder.verify(readConsumerMock).endField("list", 0); inOrder.verify(readConsumerMock).endGroup(); inOrder.verify(readConsumerMock).endField("repeatedInt", 0); inOrder.verify(readConsumerMock).endMessage(); Mockito.verifyNoMoreInteractions(readConsumerMock); }
Example 8
Source File: Http2MultiplexedChannelPoolTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@Test public void releaseParentChannelIfReleasingLastChildChannelOnGoAwayChannel() { SocketChannel channel = new NioSocketChannel(); try { loopGroup.register(channel).awaitUninterruptibly(); ChannelPool connectionPool = mock(ChannelPool.class); ArgumentCaptor<Promise> releasePromise = ArgumentCaptor.forClass(Promise.class); when(connectionPool.release(eq(channel), releasePromise.capture())).thenAnswer(invocation -> { Promise<?> promise = releasePromise.getValue(); promise.setSuccess(null); return promise; }); MultiplexedChannelRecord record = new MultiplexedChannelRecord(channel, 8, null); Http2MultiplexedChannelPool h2Pool = new Http2MultiplexedChannelPool(connectionPool, loopGroup, Collections.singleton(record), null); h2Pool.close(); InOrder inOrder = Mockito.inOrder(connectionPool); inOrder.verify(connectionPool).release(eq(channel), isA(Promise.class)); inOrder.verify(connectionPool).close(); } finally { channel.close().awaitUninterruptibly(); } }
Example 9
Source File: CleanableHistoricCaseInstanceReportServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testGetReport() { given() .then().expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when().get(HISTORIC_REPORT_URL); InOrder inOrder = Mockito.inOrder(historicCaseInstanceReport); inOrder.verify(historicCaseInstanceReport).list(); verifyNoMoreInteractions(historicCaseInstanceReport); }
Example 10
Source File: ExecutionRestServiceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testExecutionRetrieval() { String queryKey = "key"; Response response = given().queryParam("processDefinitionKey", queryKey) .then().expect().statusCode(Status.OK.getStatusCode()) .when().get(EXECUTION_QUERY_URL); // assert query invocation InOrder inOrder = Mockito.inOrder(mockedQuery); inOrder.verify(mockedQuery).processDefinitionKey(queryKey); inOrder.verify(mockedQuery).list(); String content = response.asString(); List<String> executions = from(content).getList(""); Assert.assertEquals("There should be one execution returned.", 1, executions.size()); Assert.assertNotNull("There should be one execution returned", executions.get(0)); String returnedExecutionId = from(content).getString("[0].id"); Boolean returnedIsEnded = from(content).getBoolean("[0].ended"); String returnedProcessInstanceId = from(content).getString("[0].processInstanceId"); String returnedTenantId = from(content).getString("[0].tenantId"); Assert.assertEquals(MockProvider.EXAMPLE_EXECUTION_ID, returnedExecutionId); Assert.assertEquals(MockProvider.EXAMPLE_EXECUTION_IS_ENDED, returnedIsEnded); Assert.assertEquals(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID, returnedProcessInstanceId); Assert.assertEquals(MockProvider.EXAMPLE_TENANT_ID, returnedTenantId); }
Example 11
Source File: AcceptanceTest.java From rdp4j with MIT License | 5 votes |
@Before public void testFixture() throws Exception { directoryMock = Mockito.mock(PolledDirectory.class); listenerMock = Mockito.mock(AbstractRdp4jListener.class); inOrder = Mockito.inOrder(listenerMock); builder = DirectoryPoller.newBuilder(); }
Example 12
Source File: ProtoWriteSupportTest.java From parquet-mr with Apache License 2.0 | 5 votes |
@Test public void testProto3MapIntMessageEmpty() throws Exception { RecordConsumer readConsumerMock = Mockito.mock(RecordConsumer.class); ProtoWriteSupport instance = createReadConsumerInstance(TestProto3.MapIntMessage.class, readConsumerMock); TestProto3.MapIntMessage.Builder msg = TestProto3.MapIntMessage.newBuilder(); instance.write(msg.build()); InOrder inOrder = Mockito.inOrder(readConsumerMock); inOrder.verify(readConsumerMock).startMessage(); inOrder.verify(readConsumerMock).endMessage(); Mockito.verifyNoMoreInteractions(readConsumerMock); }
Example 13
Source File: HistoricActivityStatisticsRestServiceQueryTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testProcessInstanceIdInFilter() { given() .pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID) .queryParam("processInstanceIdIn", "foo,bar") .then().expect() .statusCode(Status.OK.getStatusCode()) .when().get(HISTORIC_ACTIVITY_STATISTICS_URL); InOrder inOrder = Mockito.inOrder(historicActivityStatisticsQuery); inOrder.verify(historicActivityStatisticsQuery).processInstanceIdIn(new String[] {"foo", "bar"}); inOrder.verify(historicActivityStatisticsQuery).unlimitedList(); inOrder.verifyNoMoreInteractions(); }
Example 14
Source File: RemoteWebDriverUnitTest.java From selenium with Apache License 2.0 | 5 votes |
private void verifyCommands(CommandExecutor executor, SessionId sid, CommandPayload... commands) throws IOException { InOrder inOrder = Mockito.inOrder(executor); inOrder.verify(executor).execute(argThat( command -> command.getName().equals(DriverCommand.NEW_SESSION))); for (CommandPayload target : commands) { int x = target instanceof MultiCommandPayload ? ((MultiCommandPayload) target).getTimes() : 1; inOrder.verify(executor, times(x)).execute(argThat( cmd -> cmd.getSessionId().equals(sid) && cmd.getName().equals(target.getName()) && areEqual(cmd.getParameters(), target.getParameters()))); } verifyNoMoreInteractions(executor); }
Example 15
Source File: DatastoreTemplateTests.java From spring-cloud-gcp with Apache License 2.0 | 5 votes |
private void verifyBeforeAndAfterEvents(ApplicationEvent expectedBefore, ApplicationEvent expectedAfter, Runnable operation, Consumer<InOrder> verifyOperation) { ApplicationEventPublisher mockPublisher = mock(ApplicationEventPublisher.class); ApplicationEventPublisher mockBeforePublisher = mock(ApplicationEventPublisher.class); ApplicationEventPublisher mockAfterPublisher = mock(ApplicationEventPublisher.class); InOrder inOrder = Mockito.inOrder(mockBeforePublisher, this.datastore, mockAfterPublisher); doAnswer((invocationOnMock) -> { ApplicationEvent event = invocationOnMock.getArgument(0); if (expectedBefore != null && event.getClass().equals(expectedBefore.getClass())) { mockBeforePublisher.publishEvent(event); } else if (expectedAfter != null && event.getClass().equals(expectedAfter.getClass())) { mockAfterPublisher.publishEvent(event); } return null; }).when(mockPublisher).publishEvent(any()); this.datastoreTemplate.setApplicationEventPublisher(mockPublisher); operation.run(); if (expectedBefore != null) { inOrder.verify(mockBeforePublisher, times(1)).publishEvent(eq(expectedBefore)); } verifyOperation.accept(inOrder); if (expectedAfter != null) { inOrder.verify(mockAfterPublisher, times(1)).publishEvent(eq(expectedAfter)); } }
Example 16
Source File: SegmentOutputStreamTest.java From pravega with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testFlushDuringTransactionAbort() throws Exception { UUID cid = UUID.randomUUID(); PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT); MockConnectionFactoryImpl cf = new MockConnectionFactoryImpl(); cf.setExecutor(executorService()); MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true); ClientConnection connection = mock(ClientConnection.class); cf.provideConnection(uri, connection); InOrder order = Mockito.inOrder(connection); SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(TXN_SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken()); output.reconnect(); order.verify(connection).send(new SetupAppend(output.getRequestId(), cid, TXN_SEGMENT, "")); cf.getProcessor(uri).appendSetup(new AppendSetup(output.getRequestId(), TXN_SEGMENT, cid, 0)); ByteBuffer data = getBuffer("test"); // Write an Event. CompletableFuture<Void> ack = new CompletableFuture<>(); output.write(PendingEvent.withoutHeader(null, data, ack)); order.verify(connection).send(new Append(TXN_SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId())); assertFalse(ack.isDone()); //writer is not complete until a response from Segment Store is received. // Validate that flush() is blocking until there is a response from Segment Store. AssertExtensions.assertBlocks(() -> { // A flush() should throw a SegmentSealedException. AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }, () -> { // Simulate a NoSuchSegment response from SegmentStore due to a Transaction abort. cf.getProcessor(uri).noSuchSegment(new WireCommands.NoSuchSegment(output.getRequestId(), TXN_SEGMENT, "SomeException", -1L)); }); AssertExtensions.assertThrows(SegmentSealedException.class, () -> output.flush()); }
Example 17
Source File: CleanableHistoricDecisionInstanceReportServiceTest.java From camunda-bpm-platform with Apache License 2.0 | 5 votes |
@Test public void testGetReport() { given() .then().expect() .statusCode(Status.OK.getStatusCode()) .contentType(ContentType.JSON) .when().get(HISTORIC_REPORT_URL); InOrder inOrder = Mockito.inOrder(historicDecisionInstanceReport); inOrder.verify(historicDecisionInstanceReport).list(); verifyNoMoreInteractions(historicDecisionInstanceReport); }
Example 18
Source File: CrossDomainFilterTest.java From micro-server with Apache License 2.0 | 4 votes |
@Test public void testFilter() throws IOException, ServletException { ServletRequest request = mock(ServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); FilterChain filterChain = mock(FilterChain.class); crossDomainFilter.doFilter(request, response, filterChain); InOrder inOrder = Mockito.inOrder(response, filterChain); inOrder.verify(response, times(1)).addHeader("Access-Control-Allow-Origin", "*"); inOrder.verify(response, times(1)).addHeader("Access-Control-Allow-Methods", "GET, POST, DELETE, PUT"); inOrder.verify(response, times(1)).addHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, X-Codingpedia"); inOrder.verify(filterChain, times(1)).doFilter(request, response); }
Example 19
Source File: SegmentOutputStreamTest.java From pravega with Apache License 2.0 | 4 votes |
@Test(timeout = 10000) public void testReconnectOnMissedAcks() throws ConnectionFailedException, SegmentSealedException { UUID cid = UUID.randomUUID(); PravegaNodeUri uri = new PravegaNodeUri("endpoint", SERVICE_PORT); MockConnectionFactoryImpl cf = spy(new MockConnectionFactoryImpl()); ScheduledExecutorService executor = mock(ScheduledExecutorService.class); implementAsDirectExecutor(executor); // Ensure task submitted to executor is run inline. cf.setExecutor(executor); MockController controller = new MockController(uri.getEndpoint(), uri.getPort(), cf, true); ClientConnection connection = mock(ClientConnection.class); cf.provideConnection(uri, connection); InOrder order = Mockito.inOrder(connection); SegmentOutputStreamImpl output = new SegmentOutputStreamImpl(SEGMENT, true, controller, cf, cid, segmentSealedCallback, RETRY_SCHEDULE, DelegationTokenProviderFactory.createWithEmptyToken()); output.reconnect(); order.verify(connection).send(new SetupAppend(output.getRequestId(), cid, SEGMENT, "")); cf.getProcessor(uri).appendSetup(new AppendSetup(1, SEGMENT, cid, 0)); ByteBuffer data = getBuffer("test"); CompletableFuture<Void> acked1 = new CompletableFuture<>(); output.write(PendingEvent.withoutHeader(null, data, acked1)); order.verify(connection).send(new Append(SEGMENT, cid, 1, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId())); assertEquals(false, acked1.isDone()); AssertExtensions.assertBlocks(() -> output.flush(), () -> cf.getProcessor(uri).dataAppended(new WireCommands.DataAppended(output.getRequestId(), cid, 1, 0, -1))); assertEquals(false, acked1.isCompletedExceptionally()); assertEquals(true, acked1.isDone()); order.verify(connection).send(new WireCommands.KeepAlive()); //simulate missed ack CompletableFuture<Void> acked2 = new CompletableFuture<>(); output.write(PendingEvent.withoutHeader(null, data, acked2)); order.verify(connection).send(new Append(SEGMENT, cid, 2, 1, Unpooled.wrappedBuffer(data), null, output.getRequestId())); assertEquals(false, acked2.isDone()); cf.getProcessor(uri).dataAppended(new WireCommands.DataAppended(output.getRequestId(), cid, 3, 2L, -1)); // check that client reconnected verify(cf, times(2)).establishConnection(any(), any()); }
Example 20
Source File: SFTPClientTest.java From davos with MIT License | 3 votes |
@Test public void sessionFromInitialConnectionNeedsConfigAndPasswordSettingBeforeConnecting() throws JSchException { Session mockSession = mockJsch.getSession("user", "host", 999); InOrder inOrder = Mockito.inOrder(mockSession); SFTPClient.connect(); inOrder.verify(mockSession).setConfig("StrictHostKeyChecking", "no"); inOrder.verify(mockSession).setPassword("password"); inOrder.verify(mockSession).connect(); }