本文整理汇总了Java中org.mockito.ArgumentMatcher类的典型用法代码示例。如果您正苦于以下问题:Java ArgumentMatcher类的具体用法?Java ArgumentMatcher怎么用?Java ArgumentMatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ArgumentMatcher类属于org.mockito包,在下文中一共展示了ArgumentMatcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRequest
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void testRequest() throws Throwable {
createServerApiMock();
createTestScheduler();
App.setObjectGraph(ObjectGraph.create(new MainPresenterTestModule()));
MainPresenter presenter = new MainPresenter();
presenter.onCreate(null);
presenter.request(FIRST_NAME + " " + LAST_NAME);
MainActivity mainActivity = mock(MainActivity.class);
presenter.takeView(mainActivity);
testScheduler.triggerActions();
verify(serverAPIMock).getItems(FIRST_NAME, LAST_NAME);
verify(mainActivity).onItems(argThat(new ArgumentMatcher<ServerAPI.Item[]>() {
@Override
public boolean matches(Object argument) {
return ((ServerAPI.Item[])argument)[0].text.equals(TEST_TEXT);
}
}), anyString());
}
示例2: senses
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void senses() throws Exception {
final MetricRecorder recorder = new StubRecorder();
final Sensor sensor1 = mock(Sensor.class);
final Sensor sensor2 = mock(Sensor.class);
when(sensor1.addContext(any(TypedMap.class))).then(invocation -> invocation.getArgument(0));
when(sensor2.addContext(any(TypedMap.class))).then(invocation -> invocation.getArgument(0));
List<Sensor> sensors = new ArrayList<>();
sensors.add(sensor1);
sensors.add(sensor2);
MXBeanPoller poller = new MXBeanPoller(recorder, 1, sensors);
Thread.sleep(1500); // wait for a poll to occur
poller.shutdown();
final ArgumentMatcher<TypedMap> dataMatch = new DataMatcher();
verify(sensor1).addContext(argThat(dataMatch));
verify(sensor2).addContext(argThat(dataMatch));
verify(sensor1, atLeastOnce()).sense(any(MetricRecorder.Context.class));
verify(sensor2, atLeastOnce()).sense(any(MetricRecorder.Context.class));
}
示例3: examineResolve
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void examineResolve() throws Exception {
final Credential credential = mock(Credential.class);
when(credential.getId()).thenReturn("input");
final PrincipalResolver resolver1 = mock(PrincipalResolver.class);
when(resolver1.supports(eq(credential))).thenReturn(true);
when(resolver1.resolve((eq(credential)))).thenReturn(principalFactory.createPrincipal("output"));
final PrincipalResolver resolver2 = mock(PrincipalResolver.class);
when(resolver2.supports(any(Credential.class))).thenReturn(false);
when(resolver2.resolve(argThat(new ArgumentMatcher<Credential>() {
@Override
public boolean matches(final Object o) {
return "output".equals(((Credential) o).getId());
}
}))).thenReturn(principalFactory.createPrincipal("final", Collections.<String, Object>singletonMap("mail", "[email protected]")));
final ChainingPrincipalResolver resolver = new ChainingPrincipalResolver();
resolver.setChain(Arrays.asList(resolver1, resolver2));
final Principal principal = resolver.resolve(credential);
assertEquals("final", principal.getId());
assertEquals("[email protected]", principal.getAttributes().get("mail"));
}
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:25,代码来源:ChainingPrincipalResolverTest.java
示例4: getArgMatcher
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
protected ArgumentMatcher<SearchParameters> getArgMatcher()
{
return new ArgumentMatcher<SearchParameters>()
{
@Override
public boolean matches(Object argument)
{
if (argument instanceof SearchParameters)
{
String matchingString = getMatchingString();
if (matchingString != null && argument.toString().contains(matchingString))
{
return true;
}
}
return false;
}
};
}
示例5: testResolve
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void testResolve() throws Exception {
final Credential credential = mock(Credential.class);
when(credential.getId()).thenReturn("input");
final PrincipalResolver resolver1 = mock(PrincipalResolver.class);
when(resolver1.supports(eq(credential))).thenReturn(true);
when(resolver1.resolve((eq(credential)))).thenReturn(new SimplePrincipal("output"));
final PrincipalResolver resolver2 = mock(PrincipalResolver.class);
when(resolver2.supports(any(Credential.class))).thenReturn(false);
when(resolver2.resolve(argThat(new ArgumentMatcher<Credential>() {
@Override
public boolean matches(final Object o) {
return ((Credential) o).getId().equals("output");
}
}))).thenReturn(
new SimplePrincipal("final", Collections.<String, Object>singletonMap("mail", "[email protected]")));
final ChainingPrincipalResolver resolver = new ChainingPrincipalResolver();
resolver.setChain(Arrays.asList(resolver1, resolver2));
final Principal principal = resolver.resolve(credential);
assertEquals("final", principal.getId());
assertEquals("[email protected]", principal.getAttributes().get("mail"));
}
示例6: includeVat_grossAmount
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void includeVat_grossAmount() {
// given
doReturn(BigDecimal.ONE).when(vatForCustomer).getTotalCosts();
// when
bean.includeVat(billingDetails, billingInput, billingResult,
overallCosts);
// then
OverallCostsType overallCostsType = billingDetails.getOverallCosts();
verify(overallCostsType).setGrossAmount(
argThat(new ArgumentMatcher<BigDecimal>() {
@Override
public boolean matches(Object argument) {
BigDecimal b = (BigDecimal) argument;
BigDecimalAsserts.checkEquals(BigDecimal.ONE, b);
return true;
}
}));
}
示例7: testReadConfiguration
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void testReadConfiguration() {
final int DB_CONNECTIONS = 15;
final String SERVICE_NAME = "abc";
when(configurationMock.getDbConnectionThreads()).thenReturn(DB_CONNECTIONS);
ArgumentMatcher<DataSourceConfig> dataSourceConfigMatcher = new LambdaArgumentMatcher<DataSourceConfig>(
(Object input) -> DB_CONNECTIONS == ((DataSourceConfig) input).getPoolConfig().getMaxTotal());
when(springCloudMock.getServiceConnector(eq(SERVICE_NAME), eq(DataSource.class), argThat(dataSourceConfigMatcher)))
.thenReturn(createdDataSource);
testedFactory.setDefaultDataSource(defaultDataSource);
testedFactory.setServiceName(SERVICE_NAME);
testedFactory.afterPropertiesSet();
verify(springCloudMock, atLeastOnce()).getServiceConnector(any(), any(), any());
assertEquals(testedFactory.getObject(), createdDataSource);
}
示例8: testPostAdd
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
public void testPostAdd() throws FrameworkException, ApplicationExceptions {
User user = new User();
StaticContext.initialize(user);
assertNotNull(user.getFlexBean());
UOW mockUow = Mockito.mock(UOW.class);
user.setUOW(mockUow);
user.setId("1234");
// flexbean should not have been updated since the values haven't changed
user.postAdd();
verify(mockUow, never()).add(new Object());
user.getFlexBean().set("reinstateDate", new Date());
user.postAdd();
// the flextfield for the date should have attempted to "add" in the uow
verify(mockUow).add(argThat(new ArgumentMatcher<FlexField>() {
@Override
public boolean matches(Object emp) {
return ((FlexField) emp).getFieldName().equals("reinstateDate");
}
}));
}
示例9: listSpecificTrigger
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void listSpecificTrigger() throws Exception {
when(mockSchedulingService.getTriggerByKey(any(NameAndGroup.class))).thenReturn(immediateTrigger);
mockMvc.perform(get("/triggers?name=test&group=group"))
.andExpect(status().isOk())
.andExpect(result -> assertEquals("application/json;charset=UTF-8", result.getResponse().getContentType()))
.andExpect(result -> {
String responseBody = result.getResponse().getContentAsString();
TriggerDefinition trigger = mapper.readValue(responseBody, TriggerDefinition.class);
assertTriggers(immediateTrigger, trigger);
});
verify(mockSchedulingService).getTriggerByKey(argThat(new ArgumentMatcher<NameAndGroup>() {
@Override
public boolean matches(Object o) {
return (o instanceof NameAndGroup) &&
((NameAndGroup) o).getName().equals("test") &&
((NameAndGroup) o).getGroup().equals("group");
}
}));
}
示例10: listTriggersForSpecificJob
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void listTriggersForSpecificJob() throws Exception {
when(mockSchedulingService.getTriggersForJob(any(NameAndGroup.class))).thenReturn(singletonList(cronTrigger));
mockMvc.perform(get("/triggers/job?name=job&group=jobGroup"))
.andExpect(status().isOk())
.andExpect(result -> assertEquals("application/json;charset=UTF-8", result.getResponse().getContentType()))
.andExpect(result -> {
String responseBody = result.getResponse().getContentAsString();
List<TriggerDefinition> triggers = Arrays.asList(mapper.readValue(responseBody, TriggerDefinition[].class));
assertEquals(1, triggers.size());
assertTriggers(cronTrigger, triggers.get(0));
});
verify(mockSchedulingService).getTriggersForJob(argThat(new ArgumentMatcher<NameAndGroup>() {
@Override
public boolean matches(Object o) {
return (o instanceof NameAndGroup) &&
((NameAndGroup) o).getName().equals("job") &&
((NameAndGroup) o).getGroup().equals("jobGroup");
}
}));
}
示例11: triggerAJob
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void triggerAJob() throws Exception {
when(mockSchedulingService.triggerNow(any(NameAndGroup.class))).thenReturn(immediateTrigger);
mockMvc.perform(post("/triggers/start?name=test&group=group"))
.andExpect(status().isOk())
.andExpect(result -> assertEquals("application/json;charset=UTF-8", result.getResponse().getContentType()))
.andExpect(result -> {
String responseBody = result.getResponse().getContentAsString();
TriggerDefinition trigger = mapper.readValue(responseBody, TriggerDefinition.class);
assertTriggers(immediateTrigger, trigger);
});
verify(mockSchedulingService).triggerNow(argThat(new ArgumentMatcher<NameAndGroup>() {
@Override
public boolean matches(Object o) {
return (o instanceof NameAndGroup) &&
((NameAndGroup) o).getName().equals("test") &&
((NameAndGroup) o).getGroup().equals("group");
}
}));
}
示例12: triggerANewImmediateTrigger
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void triggerANewImmediateTrigger() throws Exception {
mockMvc.perform(post("/triggers/new/immediate").content(mapper.writeValueAsString(immediateTrigger)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
verify(mockSchedulingService).saveOrUpdateTrigger(argThat(new ArgumentMatcher<TriggerDefinition>() {
@Override
public boolean matches(Object o) {
return (o instanceof Immediate) &&
((Immediate) o).getTriggerKey().getName().equals("test") &&
((Immediate) o).getTriggerKey().getGroup().equals("group") &&
((Immediate) o).getJobKey().getName().equals("job") &&
((Immediate) o).getJobKey().getGroup().equals("jobGroup") &&
((Immediate) o).getTriggerData().get("key1").equals("value") &&
((Immediate) o).getTriggerData().get("key2").equals(5) &&
((Immediate) o).getMisfireInstruction() == MisfireInstruction.DROP;
}
}));
}
示例13: createImmediateTrigger
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void createImmediateTrigger() throws Exception {
mockMvc.perform(post("/triggers/new").content(mapper.writeValueAsString(immediateTrigger)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
verify(mockSchedulingService).saveOrUpdateTrigger(argThat(new ArgumentMatcher<TriggerDefinition>() {
@Override
public boolean matches(Object o) {
return (o instanceof Immediate) &&
((Immediate) o).getTriggerKey().getName().equals("test") &&
((Immediate) o).getTriggerKey().getGroup().equals("group") &&
((Immediate) o).getJobKey().getName().equals("job") &&
((Immediate) o).getJobKey().getGroup().equals("jobGroup") &&
((Immediate) o).getTriggerData().get("key1").equals("value") &&
((Immediate) o).getTriggerData().get("key2").equals(5) &&
((Immediate) o).getMisfireInstruction() == MisfireInstruction.DROP;
}
}));
}
示例14: createCronTrigger
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void createCronTrigger() throws Exception {
mockMvc.perform(post("/triggers/new").content(mapper.writeValueAsString(cronTrigger)).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk());
verify(mockSchedulingService).saveOrUpdateTrigger(argThat(new ArgumentMatcher<TriggerDefinition>() {
@Override
public boolean matches(Object o) {
return (o instanceof Cron) &&
((Cron) o).getTriggerKey().getName().equals("test") &&
((Cron) o).getTriggerKey().getGroup().equals("group") &&
((Cron) o).getJobKey().getName().equals("job") &&
((Cron) o).getJobKey().getGroup().equals("jobGroup") &&
((Cron) o).getTriggerData().get("key1").equals("value") &&
((Cron) o).getTriggerData().get("key2").equals(5) &&
((Cron) o).getCronExpression().equals("0 0/1 * 1/1 * ? *") &&
((Cron) o).getMisfireInstruction() == Cron.MisfireInstruction.FIRE_ONCE;
}
}));
}
示例15: listSpecificJob
import org.mockito.ArgumentMatcher; //导入依赖的package包/类
@Test
public void listSpecificJob() throws Exception {
when(mockSchedulingService.getJobByKey(any(NameAndGroup.class))).thenReturn(jobDefinition);
mockMvc.perform(get("/jobs/?name=test&group=group"))
.andExpect(status().isOk())
.andExpect(result -> assertEquals("application/json;charset=UTF-8", result.getResponse()
.getContentType()))
.andExpect(result -> {
String responseBody = result.getResponse().getContentAsString();
JobDefinition job = mapper.readValue(responseBody, JobDefinition.class);
assertJobs(jobDefinition, job);
});
verify(mockSchedulingService).getJobByKey(argThat(new ArgumentMatcher<NameAndGroup>() {
@Override
public boolean matches(Object o) {
return (o instanceof NameAndGroup) &&
((NameAndGroup) o).getName().equals("test") &&
((NameAndGroup) o).getGroup().equals("group");
}
}));
}