本文整理匯總了Java中org.mockito.ArgumentMatchers類的典型用法代碼示例。如果您正苦於以下問題:Java ArgumentMatchers類的具體用法?Java ArgumentMatchers怎麽用?Java ArgumentMatchers使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ArgumentMatchers類屬於org.mockito包,在下文中一共展示了ArgumentMatchers類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: newApplicationUserSaveFail
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test(expected = UncategorizedLdapException.class)
public void newApplicationUserSaveFail() {
final LdapPluginResource resource = new LdapPluginResource();
resource.userResource = Mockito.mock(UserOrgResource.class);
Mockito.when(resource.userResource.findByIdNoCache("flast123")).thenReturn(null);
Mockito.doThrow(new UncategorizedLdapException("")).when(resource.userResource).saveOrUpdate(ArgumentMatchers.any(UserOrgEditionVo.class));
final UserOrg user = new UserOrg();
user.setMails(Collections.singletonList("[email protected]"));
user.setFirstName("First");
user.setLastName("Last123");
user.setName("secondarylogin");
user.setCompany("gfi");
resource.newApplicationUser(user);
}
示例2: findAllNotSecure
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void findAllNotSecure() {
final Map<String, UserOrg> users = new HashMap<>();
final UserOrg user1 = newUser();
users.put("wuser", user1);
final UserOrg user2 = new UserOrg();
user2.setCompany("ing");
user2.setGroups(Collections.singletonList("any"));
users.put("user2", user2);
final GroupOrg groupOrg1 = new GroupOrg("cn=DIG,ou=fonction,ou=groups,dc=sample,dc=com", "DIG", Collections.singleton("wuser"));
final Map<String, GroupOrg> groupsMap = new HashMap<>();
groupsMap.put("dig", groupOrg1);
resource.groupResource = Mockito.mock(GroupResource.class);
final CompanyOrg company = new CompanyOrg("ou=ing,ou=france,ou=people,dc=sample,dc=com", "ing");
Mockito.when(companyRepository.findByIdExpected(DEFAULT_USER, "ing")).thenReturn(company);
groupFindById(DEFAULT_USER, "dig", groupOrg1);
Mockito.when(userRepository.findAll(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(new PageImpl<>(new ArrayList<>(users.values())));
Mockito.when(resource.groupResource.getContainers()).thenReturn(new HashSet<>(groupsMap.values()));
Mockito.when(resource.groupResource.getContainersForWrite()).thenReturn(new HashSet<>(groupsMap.values()));
final List<UserOrg> data = resource.findAllNotSecure(null, null);
// Check the users
checkUser(data.get(0));
}
示例3: removeUserSync
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
/**
* Mock a managed LDAP desynchronization
*/
@Test
public void removeUserSync() {
final GroupLdapRepository groupRepository = new GroupLdapRepository() {
@Override
public GroupOrg findById(final String name) {
// The group has only the user user we want to remove
return new GroupOrg("dc=" + name, name, Collections.singleton("flast1"));
}
};
groupRepository.setLdapCacheRepository(Mockito.mock(LdapCacheRepository.class));
final LdapTemplate ldapTemplate = Mockito.mock(LdapTemplate.class);
groupRepository.setTemplate(ldapTemplate);
Mockito.doThrow(new org.springframework.ldap.AttributeInUseException(new AttributeInUseException("any"))).when(ldapTemplate)
.modifyAttributes(ArgumentMatchers.any(LdapName.class), ArgumentMatchers.any());
removeUser(groupRepository);
}
示例4: before
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Before
public void before() throws Exception {
Answer<Cancelable> runAndReturn = new Answer<Cancelable>() {
@Override
public Cancelable answer(InvocationOnMock invocation) throws Exception {
try {
Function0<Unit> block = invocation.getArgument(0);
block.invoke();
} catch (Exception e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
return canceler;
}
};
doAnswer(runAndReturn).when(mockRunner).runWithCancel(ArgumentMatchers.<Function0<Unit>>any());
doAnswer(runAndReturn).when(mockRunner).run(ArgumentMatchers.<Function0<Unit>>any());
}
示例5: sendMailPassword
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void sendMailPassword() {
final PasswordResource resource = newResource();
exOnPrepare = null;
final UserOrg user = new UserOrg();
user.setFirstName("John");
user.setLastName("Doe");
user.setId("fdauganB");
user.setMails(Collections.singletonList("[email protected]"));
resource.sendMailPassword(user, "password");
MailServicePlugin mailService = resource.servicePluginLocator.getResource("service:mail:smtp:local",
MailServicePlugin.class);
Mockito.verify(mailService, Mockito.atLeastOnce()).send(ArgumentMatchers.eq("service:mail:smtp:local"),
ArgumentMatchers.any(MimeMessagePreparator.class));
}
示例6: getEC2Keys
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
/**
* retrieve keys from AWS
*
* @throws Exception
* exception
*/
@Test
public void getEC2Keys() throws Exception {
final ProvAwsPluginResource resource = Mockito.spy(this.resource);
final CurlRequest mockRequest = new CurlRequest("GET", MOCK_URL, null);
mockRequest.setSaveResponse(true);
Mockito.doReturn(mockRequest).when(resource).newRequest(ArgumentMatchers.any(AWS4SignatureQueryBuilder.class),
ArgumentMatchers.eq(subscription));
httpServer.stubFor(
get(urlEqualTo("/mock")).willReturn(aResponse().withStatus(HttpStatus.SC_OK).withBody("<keyName>my-key</keyName>")));
httpServer.start();
final List<NamedBean<String>> keys = resource.getEC2Keys(subscription);
Assert.assertFalse(keys.isEmpty());
Assert.assertEquals(1, keys.size());
Assert.assertEquals("my-key", keys.get(0).getId());
}
示例7: findAllNotSecureByManagedGroup
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void findAllNotSecureByManagedGroup() {
final Map<String, UserOrg> users = new HashMap<>();
final UserOrg user1 = newUser();
users.put("wuser", user1);
final UserOrg user2 = new UserOrg();
user2.setCompany("ing");
user2.setGroups(Collections.singletonList("any"));
users.put("user2", user2);
final GroupOrg groupOrg1 = new GroupOrg("cn=DIG,ou=fonction,ou=groups,dc=sample,dc=com", "DIG", Collections.singleton("wuser"));
final Map<String, GroupOrg> groupsMap = new HashMap<>();
groupsMap.put("dig", groupOrg1);
resource.groupResource = Mockito.mock(GroupResource.class);
final CompanyOrg company = new CompanyOrg("ou=ing,ou=france,ou=people,dc=sample,dc=com", "ing");
Mockito.when(companyRepository.findByIdExpected(DEFAULT_USER, "ing")).thenReturn(company);
groupFindById(DEFAULT_USER, "dig", groupOrg1);
Mockito.when(userRepository.findAll(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any()))
.thenReturn(new PageImpl<>(new ArrayList<>(users.values())));
Mockito.when(resource.groupResource.getContainers()).thenReturn(new HashSet<>(groupsMap.values()));
Mockito.when(resource.groupResource.getContainersForWrite()).thenReturn(new HashSet<>(groupsMap.values()));
final List<UserOrg> data = resource.findAllNotSecure(null, "dig");
// Check the users
checkUser(data.get(0));
}
示例8: handleOutboundMessageTerminatesClientIfErrorOccursDuringSend
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void handleOutboundMessageTerminatesClientIfErrorOccursDuringSend() {
// given
ClientConnectedState target = new ClientConnectedState(client);
doThrow(IOException.class).when(mockSession).write(ArgumentMatchers.any(byte[].class));
// when
target.handleOutboundMessage(new SerializableMessage());
// then
assertThat(messageQueue.size(), is(1));
assertThat(messageQueue.get(0), is(instanceOf(ClientDisconnected.class)));
assertThat(client.getCurrentState(), is(instanceOf(ClientDisconnectedState.class)));
verify(mockSession, times(1)).write(ArgumentMatchers.any(byte[].class));
verify(mockSession, times(1)).terminate();
verifyNoMoreInteractions(mockSession);
}
示例9: testSynchronizeJira
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void testSynchronizeJira() throws Exception {
final ImportContext context = new ImportContext();
final ImportStatus result = new ImportStatus();
result.setCanSynchronizeJira(true);
final JiraImportPluginResource resource = Mockito.mock(JiraImportPluginResource.class);
Mockito.doCallRealMethod().when(resource).synchronizeJira(ArgumentMatchers.same(context), ArgumentMatchers.same(result));
Mockito.when(resource.authenticateAdmin(ArgumentMatchers.same(context), ArgumentMatchers.any(CurlProcessor.class)))
.thenReturn(true);
Mockito.when(resource.clearJiraCache(ArgumentMatchers.same(context), ArgumentMatchers.same(result),
ArgumentMatchers.any(CurlProcessor.class))).thenReturn(true);
Mockito.when(resource.reIndexProject(ArgumentMatchers.same(context), ArgumentMatchers.same(result),
ArgumentMatchers.any(CurlProcessor.class))).thenReturn(true);
resource.synchronizeJira(context, result);
Assert.assertTrue(result.getSynchronizedJira());
}
示例10: whenSendingHandshakeMessageFailsClientIsTerminated
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void whenSendingHandshakeMessageFailsClientIsTerminated() {
// given
doThrow(IOException.class).when(mockSession).write(ArgumentMatchers.any(byte[].class));
ClientHandshakeState target = new ClientHandshakeState(client);
// when
client.setState(target);
// then
assertThat(client.getCurrentState(), is(instanceOf(ClientDisconnectedState.class)));
assertThat(messageQueue.size(), is(2));
assertThat(messageQueue.get(0), is(instanceOf(ClientConnectionRefused.class)));
assertThat(((ClientConnectionRefused)messageQueue.get(0)).getReason(), Matchers.startsWith("Failed to send handshake: "));
verify(mockSession, times(1)).write(ArgumentMatchers.any(byte[].class));
verify(mockSession, times(1)).terminate();
verifyNoMoreInteractions(mockSession);
}
示例11: handleSessionClosedMakesStateTransition
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void handleSessionClosedMakesStateTransition() {
// given
doThrow(IOException.class).when(mockSession).write(ArgumentMatchers.any(byte[].class));
ClientHandshakeState target = new ClientHandshakeState(client);
// when
target.handleSessionClosed(mockSession);
// then
assertThat(client.getCurrentState(), is(instanceOf(ClientDisconnectedState.class)));
assertThat(messageQueue.size(), is(2));
assertThat(messageQueue.get(0), is(instanceOf(ClientConnectionRefused.class)));
assertThat(((ClientConnectionRefused)messageQueue.get(0)).getReason(), is("connection closed by server"));
verifyZeroInteractions(mockSession);
}
示例12: processDataReceivedTerminatesSendingMessageToClientFails
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void processDataReceivedTerminatesSendingMessageToClientFails() throws IOException, ProtocolException {
// given
doThrow(IOException.class).when(sessionMock).write(ArgumentMatchers.any(byte[].class));
Handshake handshake = new Handshake(HandshakeConstants.HANDSHAKE_MAGIC, HandshakeConstants.HANDSHAKE_PROTOCOL_VERSION);
byte[] handshakeData = new MessageSerializer(handshake).serialize();
client.processDataReceived(handshakeData);
ClientConnectedState target = new ClientConnectedState(client);
// when
target.processDataReceived();
// then
assertThat(client.getCurrentState(), is(instanceOf(ClientClosedState.class)));
verify(sessionMock, times(1)).terminate();
verify(sessionMock, times(1)).write(ArgumentMatchers.any(byte[].class));
verifyNoMoreInteractions(sessionMock);
verifyNoMoreInteractions(messageBusMock);
}
示例13: connectWhenRegisteringClientSocketThrowsException
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void connectWhenRegisteringClientSocketThrowsException() throws IOException {
// given
when(socketFactoryMock.openSocketSelector()).thenReturn(selectorMock);
when(socketFactoryMock.openClientSocket(anyString(), anyInt())).thenReturn(socketMock);
doThrow(IOException.class).when(selectorMock).register(ArgumentMatchers.any(TCPClientSocket.class), anyBoolean());
// when
boolean obtained = client.connect(HOST, PORT);
// then
assertThat(obtained, is(false));
assertThat(client.isRunning(), is(false));
// verify method calls
verify(socketFactoryMock, times(1)).openSocketSelector();
verify(socketFactoryMock, times(1)).openClientSocket(anyString(), anyInt());
verify(selectorMock, times(1)).register(any(TCPClientSocket.class), anyBoolean());
verify(selectorMock, times(1)).close();
verify(socketMock, times(1)).close();
}
示例14: closingSocketAndSelectorWhenExceptionIsThrownInClose
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@Test
public void closingSocketAndSelectorWhenExceptionIsThrownInClose() throws IOException {
// given
when(socketFactoryMock.openSocketSelector()).thenReturn(selectorMock);
when(socketFactoryMock.openClientSocket(anyString(), anyInt())).thenReturn(socketMock);
doThrow(IOException.class).when(selectorMock).register(ArgumentMatchers.any(TCPClientSocket.class), anyBoolean());
doThrow(IOException.class).when(selectorMock).close();
doThrow(IOException.class).when(socketMock).close();
// when
boolean obtained = client.connect(HOST, PORT);
// then
assertThat(obtained, is(false));
assertThat(client.isRunning(), is(false));
// verify method calls
verify(socketFactoryMock, times(1)).openSocketSelector();
verify(socketFactoryMock, times(1)).openClientSocket(anyString(), anyInt());
verify(selectorMock, times(1)).register(any(TCPClientSocket.class), anyBoolean());
verify(selectorMock, times(1)).close();
verify(socketMock, times(1)).close();
}
示例15: mockApplicationContext
import org.mockito.ArgumentMatchers; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Before
public void mockApplicationContext() {
final ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
SpringUtils.setSharedApplicationContext(applicationContext);
mockLdapResource = Mockito.mock(UserOrgResource.class);
final UserFullLdapTask mockTask = new UserFullLdapTask();
mockTask.resource = mockLdapResource;
mockTask.securityHelper = securityHelper;
final UserAtomicLdapTask mockTaskUpdate = new UserAtomicLdapTask();
mockTaskUpdate.resource = mockLdapResource;
mockTaskUpdate.securityHelper = securityHelper;
Mockito.when(applicationContext.getBean(SessionSettings.class)).thenReturn(new SessionSettings());
Mockito.when(applicationContext.getBean((Class<?>) ArgumentMatchers.any(Class.class))).thenAnswer((Answer<Object>) invocation -> {
final Class<?> requiredType = (Class<Object>) invocation.getArguments()[0];
if (requiredType == UserFullLdapTask.class) {
return mockTask;
}
if (requiredType == UserAtomicLdapTask.class) {
return mockTaskUpdate;
}
return UserBatchLdapResourceTest.super.applicationContext.getBean(requiredType);
});
mockTaskUpdate.jaxrsFactory = ServerProviderFactory.createInstance(null);
}