private void resetAndMockUserDatabase(String userId, UaaUser user) { reset(userDatabase); when(userDatabase.retrieveUserById(eq(userId))).thenReturn(user); when(userDatabase.retrieveUserById(not(eq(userId)))).thenThrow(new UsernameNotFoundException("mock")); }
@Test public void testReplacingNonNullItemWithNonNullItemUpdatesSize() { String key = getKey(); Object initialValue = new Object(); cache.put(key, initialValue); cache.put(key, new Object()); for (int i = 0; i < SIZE - 1; i++) { cache.put(getKey(), new Object()); } verify(listener).onItemRemoved(initialValue); verify(listener, never()).onItemRemoved(not(eq(initialValue))); }
@Test public void setsEventOldValueToExistingRegionEntryValue_ifOldValueIsGatewaySenderEvent() { givenExistingRegionEntry(); GatewaySenderEventImpl oldValue = new GatewaySenderEventImpl(); when(existingRegionEntry.getValue()).thenReturn(oldValue); doPut(); verify(event, times(1)).setOldValue(same(oldValue), eq(true)); verify(event, never()).setOldValue(not(same(oldValue)), eq(true)); }
@Test public void setsEventOldValueToExistingRegionEntryValue_ifOperationGuaranteesOldValue() { givenExistingRegionEntry(); givenAnOperationThatGuaranteesOldValue(); Object oldValue = new Object(); when(existingRegionEntry.getValueOffHeapOrDiskWithoutFaultIn(same(internalRegion))) .thenReturn(oldValue); doPut(); verify(event, times(1)).setOldValue(same(oldValue), eq(true)); verify(event, never()).setOldValue(not(same(oldValue)), eq(true)); }
@Test public void setsEventOldValueToExistingRegionEntryValue_ifIsRequiredOldValueAndOperationDoesNotGuaranteeOldValue() { this.requireOldValue = true; givenExistingRegionEntry(); givenAnOperationThatDoesNotGuaranteeOldValue(); Object oldValue = new Object(); when(existingRegionEntry.getValueRetain(same(internalRegion), eq(true))).thenReturn(oldValue); doPut(); verify(event, times(1)).setOldValue(same(oldValue)); verify(event, never()).setOldValue(not(same(oldValue))); }
@Test public void setsEventOldValueToExistingRegionEntryValue_ifIsCacheWriteAndOperationDoesNotGuaranteeOldValue() { givenExistingRegionEntry(); givenAnOperationThatDoesNotGuaranteeOldValue(); givenPutNeedsToDoCacheWrite(); Object oldValue = new Object(); when(existingRegionEntry.getValueRetain(same(internalRegion), eq(true))).thenReturn(oldValue); doPut(); verify(event, times(1)).setOldValue(same(oldValue)); verify(event, never()).setOldValue(not(same(oldValue))); }
any(), anyDrawableTarget(), not(eq(DataSource.MEMORY_CACHE)), anyBoolean());
when(googleAuthenticator.activeUserCredentialExists(anyString(), anyString())).thenReturn(true); when(googleAuthenticator.isValidCode(any(), eq(123456))).thenReturn(true); when(googleAuthenticator.isValidCode(any(), not(eq(123456)))).thenReturn(false); when(googleAuthenticator.getUserGoogleMfaCredentials(anyString(), anyString())).thenReturn(mock(UserGoogleMfaCredentials.class)); grantTypes = new HashSet<>(Arrays.asList("password"));
any(), anyDrawableTarget(), not(eq(DataSource.MEMORY_CACHE)), anyBoolean());
/** * Delegates call to {@link AdditionalMatchers#not(float)}. */ default float not(float first) { return AdditionalMatchers.not(first); }
/** * Delegates call to {@link AdditionalMatchers#not(byte)}. */ default byte not(byte first) { return AdditionalMatchers.not(first); }
/** * Delegates call to {@link AdditionalMatchers#not(long)}. */ default long not(long first) { return AdditionalMatchers.not(first); }
/** * Delegates call to {@link AdditionalMatchers#not(long)}. */ default long not(long first) { return AdditionalMatchers.not(first); }
/** * Delegates call to {@link AdditionalMatchers#not(double)}. */ default double not(double first) { return AdditionalMatchers.not(first); }
/** * Delegates call to {@link AdditionalMatchers#not(short)}. */ default short not(short first) { return AdditionalMatchers.not(first); }
/** * Delegates call to {@link AdditionalMatchers#not(int)}. */ default int not(int first) { return AdditionalMatchers.not(first); }
/** * Delegates call to {@link AdditionalMatchers#not(char)}. */ default char not(char first) { return AdditionalMatchers.not(first); }
/** * Delegates call to {@link AdditionalMatchers#not(boolean)}. */ default boolean not(boolean first) { return AdditionalMatchers.not(first); }
/** * Delegates call to {@link AdditionalMatchers#not(char)}. */ default char not(char first) { return AdditionalMatchers.not(first); }
private IUserRoleListService getUserRoleListServiceMock( String userName, String[] roles ) { IUserRoleListService mockUserRoleListService = mock( IUserRoleListService.class ); List<String> noRoles = new ArrayList<String>(); List<String> allRoles = new ArrayList<String>( Arrays.asList( roles ) ); when( mockUserRoleListService.getRolesForUser( Matchers.<ITenant>any(), eq( userName ) ) ).thenReturn( allRoles ); when( mockUserRoleListService.getRolesForUser( Matchers.<ITenant>any(), AdditionalMatchers.not( eq( userName ) ) ) ) .thenReturn( noRoles ); return mockUserRoleListService; } }