public <T> T verify(T mock) { return this.verify(mock, VerificationModeFactory.times(1)); }
public VerificationMode times(int wantedNumberOfInvocations) { return copySelfWithNewVerificationMode(VerificationModeFactory.times(wantedNumberOfInvocations)); }
/** * 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 */ @CheckReturnValue public static VerificationMode times(int wantedNumberOfInvocations) { return VerificationModeFactory.times(wantedNumberOfInvocations); }
public <T> T verify(T mock) { return this.verify(mock, VerificationModeFactory.times(1)); }
/** * See the javadoc for {@link VerificationWithTimeout} */ public VerificationMode never() { return new Timeout(impl.getTreshhold(), impl.getTimeout(), VerificationModeFactory.times(0)); }
/** * See the javadoc for {@link VerificationWithTimeout} */ public VerificationMode times(int wantedNumberOfInvocations) { return new Timeout(impl.getTreshhold(), impl.getTimeout(), VerificationModeFactory.times(wantedNumberOfInvocations)); } }
@Test public void dontThrottleMethodsReturningVoid() { when( clock.millis() ).thenReturn( 100L ); proxy.returnVoid(); proxy.returnVoid(); verify( target, times( 2 ) ).returnVoid(); verifyNoMoreInteractions( target ); }
@Test public void closeMustCloseAll() { // when // ... all close successful fusionIndexAccessor.close(); // then for ( IndexAccessor accessor : aliveAccessors ) { verify( accessor, times( 1 ) ).close(); } }
@Test public void dropMustDropAll() { // when // ... all drop successful fusionIndexAccessor.drop(); // then for ( IndexAccessor accessor : aliveAccessors ) { verify( accessor, times( 1 ) ).drop(); } verify( dropAction ).drop( indexId ); }
@Test public void dontThrottleMethodsWithArgs() { when( clock.millis() ).thenReturn( 100L ); proxy.notGetter( 1 ); proxy.notGetter( 2 ); verify( target, times( 2 ) ).notGetter( anyLong() ); verifyNoMoreInteractions( target ); }
@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 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 ); }
@Test public void first_call_to_getById_triggers_call_to_db_and_any_subsequent_get_or_find_call_does_not() { underTest.getById(AB_RULE.getId()); verify(ruleDao, times(1)).selectAll(any(DbSession.class), eq(ORGANIZATION_UUID)); verifyNoMethodCallTriggersCallToDB(); }
@Test public void first_call_to_findById_triggers_call_to_db_and_any_subsequent_get_or_find_call_does_not() { underTest.findById(AB_RULE.getId()); verify(ruleDao, times(1)).selectAll(any(DbSession.class), eq(ORGANIZATION_UUID)); verifyNoMethodCallTriggersCallToDB(); }
@Test public void first_call_to_getByKey_triggers_call_to_db_and_any_subsequent_get_or_find_call_does_not() { underTest.getByKey(AB_RULE.getKey()); verify(ruleDao, times(1)).selectAll(any(DbSession.class), eq(ORGANIZATION_UUID)); verifyNoMethodCallTriggersCallToDB(); }
@Test public void first_call_to_findByKey_triggers_call_to_db_and_any_subsequent_get_or_find_call_does_not() { underTest.findByKey(AB_RULE.getKey()); verify(ruleDao, times(1)).selectAll(any(DbSession.class), eq(ORGANIZATION_UUID)); verifyNoMethodCallTriggersCallToDB(); }
@Test public void getOrCreateLabelStateNodeDiffSets_useCollectionsFactory() { final MutableLongDiffSets diffSets = state.getOrCreateLabelStateNodeDiffSets(1); diffSets.add( 1 ); diffSets.remove( 2 ); verify( collectionsFactory, times( 2 ) ).newLongSet(); verifyNoMoreInteractions( collectionsFactory ); }
@Test public void testOnePortAndSearchArchivedIsTrueAndFileOffsetIs1AndByteOffsetIs100() throws IOException { LogviewerLogSearchHandler handler = getStubbedSearchHandler(); handler.deepSearchLogsForTopology("", null, "search", "20", "6700", "1", "100", true, null, null); verify(handler, times(1)).findNMatches(anyList(), anyInt(), anyInt(), anyInt(), anyString()); verify(handler, times(2)).logsForPort(isNull(), any(File.class)); }
@Test public void getOrCreateIndexUpdatesForSeek_useCollectionsFactory() { final MutableLongDiffSets diffSets = state.getOrCreateIndexUpdatesForSeek( new HashMap<>(), ValueTuple.of( stringValue( "test" ) ) ); diffSets.add( 1 ); diffSets.remove( 2 ); verify( collectionsFactory, times( 2 ) ).newLongSet(); verifyNoMoreInteractions( collectionsFactory ); }
@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 ); }