本文整理汇总了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);
}