Refine search
@Test public void dontThrottleMethodsReturningVoid() { when( clock.millis() ).thenReturn( 100L ); proxy.returnVoid(); proxy.returnVoid(); verify( target, times( 2 ) ).returnVoid(); verifyNoMoreInteractions( target ); }
public void verifyNoMoreInteractionsInOrder(List<Object> mocks, InOrderContext inOrderContext) { mockingProgress().validateState(); VerificationDataInOrder data = new VerificationDataInOrderImpl(inOrderContext, VerifiableInvocationsFinder.find(mocks), null); VerificationModeFactory.noMoreInteractions().verifyInOrder(data); }
public static VerificationMode atLeastOnce() { return atLeast(1); }
@Test public void shouldNotFailWhenUnableToDeserialize() throws Exception { NotificationQueueDto dto1 = mock(NotificationQueueDto.class); when(dto1.toNotification()).thenThrow(new InvalidClassException("Pouet")); List<NotificationQueueDto> dtos = Arrays.asList(dto1); when(notificationQueueDao.selectOldest(1)).thenReturn(dtos); underTest = spy(underTest); assertThat(underTest.getFromQueue()).isNull(); assertThat(underTest.getFromQueue()).isNull(); verify(underTest, times(1)).logDeserializationIssue(); }
@Test public void handleOverpassQuota() throws InterruptedException Provider provider = mock(Provider.class); when(provider.get()).thenReturn(mock(OverpassMapDataParser.class)); OsmConnection osm = mock(OsmConnection.class); when(osm.makeRequest(eq("status"), any())).thenReturn(status); when(osm.makeRequest(eq("interpreter"), eq("POST"), eq(false), any(), any())) .thenThrow(OsmTooManyRequestsException.class); verify(osm, times(1)).makeRequest(eq("interpreter"), eq("POST"), eq(false), any(), any()); verify(osm, times(1)).makeRequest(eq("status"), any()); verify(osm, times(2)).makeRequest(eq("interpreter"), eq("POST"), eq(false), any(), any()); verify(osm, times(2)).makeRequest(eq("status"), any());
@Test public void testOnePortAndSearchArchivedIsTrueAndFileOffsetIs1() throws IOException { LogviewerLogSearchHandler handler = getStubbedSearchHandler(); handler.deepSearchLogsForTopology("", null, "search", "20", "6700", "1", "0", true, null, null); ArgumentCaptor<List> files = ArgumentCaptor.forClass(List.class); ArgumentCaptor<Integer> numMatches = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Integer> fileOffset = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Integer> offset = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<String> search = ArgumentCaptor.forClass(String.class); verify(handler, times(1)).findNMatches(files.capture(), numMatches.capture(), fileOffset.capture(), offset.capture(), search.capture()); verify(handler, times(2)).logsForPort(isNull(), any(File.class)); assertEquals(logFiles, files.getAllValues().get(0)); assertEquals(Integer.valueOf(20), numMatches.getAllValues().get(0)); assertEquals(Integer.valueOf(1), fileOffset.getAllValues().get(0)); assertEquals(Integer.valueOf(0), offset.getAllValues().get(0)); assertEquals("search", search.getAllValues().get(0)); }
.build(mContext); when(holder.getRootComponent()).thenReturn(component); when(LayoutState.resolveNestedTree(mContext, holder, 100, 100)).thenCallRealMethod(); when(LayoutState.createAndMeasureTreeForComponent(mContext, component, holder, 100, 100, null)) .thenReturn(resolved); PowerMockito.verifyStatic(times(1)); LayoutState.createAndMeasureTreeForComponent(mContext, component, holder, 100, 100, null); PowerMockito.verifyStatic(times(1)); LayoutState.remeasureTree(resolved, 100, 100);
@Test void getIfAbsentPut_Supplier() { final Function0<Value> supplier = mock( Function0.class ); doReturn( intValue( 10 ), intValue( 11 ), intValue( 12 ) ).when( supplier ).value(); assertEquals( intValue( 10 ), map.getIfAbsentPut( 0, supplier ) ); assertEquals( intValue( 11 ), map.getIfAbsentPut( 1, supplier ) ); assertEquals( intValue( 12 ), map.getIfAbsentPut( 2, supplier ) ); verify( supplier, times( 3 ) ).value(); assertEquals( intValue( 10 ), map.getIfAbsentPut( 0, supplier ) ); assertEquals( intValue( 11 ), map.getIfAbsentPut( 1, supplier ) ); assertEquals( intValue( 12 ), map.getIfAbsentPut( 2, supplier ) ); verifyNoMoreInteractions( supplier ); }
@Test public void onAuthenticationFailure() throws Exception { AuthenticationException exception = mock(AuthenticationException.class); uaaAuthenticationFailureHandler.onAuthenticationFailure(request, response, exception); verify(failureHandler, times(1)).onAuthenticationFailure(same(request), same(response), same(exception)); validateCookie(); }
@Test public void getOrCreateGraphState_useCollectionsFactory() { final GraphStateImpl graphState = state.getOrCreateGraphState(); graphState.addProperty( 2, stringValue( "foo" ) ); graphState.removeProperty( 3 ); graphState.changeProperty( 4, stringValue( "bar" ) ); verify( collectionsFactory, times( 2 ) ).newValuesMap(); verify( collectionsFactory, times( 1 ) ).newLongSet(); verifyNoMoreInteractions( collectionsFactory ); }
/** * Tests that the rpc scheduler is called when requests arrive. */ @Test public void testRpcScheduler() throws IOException, ServiceException, InterruptedException { RpcScheduler scheduler = spy(new FifoRpcScheduler(CONF, 1)); RpcServer rpcServer = createRpcServer(null, "testRpcServer", Lists.newArrayList(new RpcServer.BlockingServiceAndInterface( SERVICE, null)), new InetSocketAddress("localhost", 0), CONF, scheduler); verify(scheduler).init((RpcScheduler.Context) anyObject()); try (AbstractRpcClient<?> client = createRpcClient(CONF)) { rpcServer.start(); verify(scheduler).start(); BlockingInterface stub = newBlockingStub(client, rpcServer.getListenerAddress()); EchoRequestProto param = EchoRequestProto.newBuilder().setMessage("hello").build(); for (int i = 0; i < 10; i++) { stub.echo(null, param); } verify(scheduler, times(10)).dispatch((CallRunner) anyObject()); } finally { rpcServer.stop(); verify(scheduler).stop(); } }
/** * Allows verifying exact number of invocations. E.g: * <pre class="code"><code class="java"> * verify(mock, times(2)).someMethod("some arg"); * </code></pre> * * See examples in javadoc for {@link Mockito} class * * @param wantedNumberOfInvocations wanted number of invocations * * @return verification mode */ public static VerificationMode times(int wantedNumberOfInvocations) { return VerificationModeFactory.times(wantedNumberOfInvocations); }
/** * Allows at-least-once verification. E.g: * <pre class="code"><code class="java"> * verify(mock, atLeastOnce()).someMethod("some arg"); * </code></pre> * Alias to <code>atLeast(1)</code>. * <p> * See examples in javadoc for {@link Mockito} class * * @return verification mode */ public static VerificationMode atLeastOnce() { return VerificationModeFactory.atLeastOnce(); }
@Test public void testOnePortAndSearchArchivedIsTrueAndNotFileOffset() throws IOException { LogviewerLogSearchHandler handler = getStubbedSearchHandler(); handler.deepSearchLogsForTopology("", null, "search", "20", "6700", "0", "0", true, null, null); ArgumentCaptor<List> files = ArgumentCaptor.forClass(List.class); ArgumentCaptor<Integer> numMatches = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Integer> fileOffset = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<Integer> offset = ArgumentCaptor.forClass(Integer.class); ArgumentCaptor<String> search = ArgumentCaptor.forClass(String.class); verify(handler, times(1)).findNMatches(files.capture(), numMatches.capture(), fileOffset.capture(), offset.capture(), search.capture()); verify(handler, times(2)).logsForPort(isNull(), any(File.class)); assertEquals(logFiles, files.getAllValues().get(0)); assertEquals(Integer.valueOf(20), numMatches.getAllValues().get(0)); assertEquals(Integer.valueOf(0), fileOffset.getAllValues().get(0)); assertEquals(Integer.valueOf(0), offset.getAllValues().get(0)); assertEquals("search", search.getAllValues().get(0)); }
.build(mContext); when(holder.getRootComponent()).thenReturn(component); when(LayoutState.resolveNestedTree(mContext, holder, 100, 100)).thenCallRealMethod(); when(LayoutState.createAndMeasureTreeForComponent(mContext, component, holder, 100, 100, null)) .thenReturn(resolved); PowerMockito.verifyStatic(times(2)); LayoutState.createAndMeasureTreeForComponent(mContext, component, holder, 100, 100, null);
private void lockUnlockThenDestroy(int lockTimes) { mockLockProvider = Mockito.mock(LockProvider.class, Answers.RETURNS_DEEP_STUBS.get()); InstanceLockGroup instanceLockGroup = new InstanceLockGroup(mockLockProvider); for (int i = 0; i < lockTimes; i++) { instanceLockGroup.lock("lockId"); } instanceLockGroup.unlock("lockId"); Mockito.verify(mockLockProvider, VerificationModeFactory.times(1)).createLock("lockId"); }
@Test public void getOrCreateNodeState_props_useCollectionsFactory() { final NodeStateImpl nodeState = state.getOrCreateNodeState( 1 ); nodeState.addProperty( 2, stringValue( "foo" ) ); nodeState.removeProperty( 3 ); nodeState.changeProperty( 4, stringValue( "bar" ) ); verify( collectionsFactory, times( 2 ) ).newValuesMap(); verify( collectionsFactory, times( 1 ) ).newLongSet(); verifyNoMoreInteractions( collectionsFactory ); }
@Test public void testResumeXaTransactionIfAvailableWithTx() throws Exception { assertThat(tc.getTransaction(), nullValue()); tc.resumeXaTransactionIfAvailable(); TestTransaction tx = spy(new TestTransaction(muleContext)); tx.setXA(true); tc.bindTransaction(tx); tc.suspendCurrentTransaction(); tc.resumeXaTransactionIfAvailable(); verify(tx, times(1)).suspend(); verify(tx, times(1)).resume(); }
public VerificationMode times(int wantedNumberOfInvocations) { return copySelfWithNewVerificationMode(VerificationModeFactory.times(wantedNumberOfInvocations)); }
public VerificationMode atLeastOnce() { return copySelfWithNewVerificationMode(VerificationModeFactory.atLeastOnce()); }