當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。