当前位置: 首页>>代码示例>>Java>>正文


Java ArgumentMatcher类代码示例

本文整理汇总了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());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:MainPresenterTest.java

示例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));
}
 
开发者ID:awslabs,项目名称:swage,代码行数:24,代码来源:MXBeanPollerTest.java

示例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;
        }
    };
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:20,代码来源:VirtualizationIntegrationTest.java

示例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"));
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:26,代码来源:ChainingPrincipalResolverTest.java

示例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;
                }
            }));
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:23,代码来源:RevenueCalculatorBeanVatTest.java

示例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);
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:21,代码来源:CloudDataSourceFactoryBeanTest.java

示例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");
        }
    }));
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:26,代码来源:FlexFieldsTest.java

示例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");
        }
    }));
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:21,代码来源:SchedulingServiceRestControllerTest.java

示例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");
        }
    }));
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:22,代码来源:SchedulingServiceRestControllerTest.java

示例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");
        }
    }));
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:21,代码来源:SchedulingServiceRestControllerTest.java

示例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;
        }
    }));
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:19,代码来源:SchedulingServiceRestControllerTest.java

示例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;
        }
    }));
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:19,代码来源:SchedulingServiceRestControllerTest.java

示例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;
        }
    }));
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:20,代码来源:SchedulingServiceRestControllerTest.java

示例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");
        }
    }));
}
 
开发者ID:taboola,项目名称:taboola-cronyx,代码行数:22,代码来源:JobServiceRestControllerTest.java


注:本文中的org.mockito.ArgumentMatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。