org.easymock.EasyMock.isA()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(14.6k)|赞(0)|评价(0)|浏览(151)

本文整理了Java中org.easymock.EasyMock.isA()方法的一些代码示例,展示了EasyMock.isA()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.isA()方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:isA

EasyMock.isA介绍

[英]Expects an object implementing the given class. For details, see the EasyMock documentation.
[中]需要一个实现给定类的对象。有关详细信息,请参阅EasyMock文档。

代码示例

代码示例来源:origin: apache/shiro

@Test(expected= AuthenticationException.class)
public void testGetAuthenticationInfoNamingException() throws NamingException {
  realm.setUserDnTemplate("uid={0},ou=users,dc=mycompany,dc=com");
  LdapContextFactory factory = createMock(LdapContextFactory.class);
  realm.setContextFactory(factory);
  expect(factory.getLdapContext(isA(Object.class), isA(Object.class)))
      .andThrow(new NamingException("Communication error."));
  replay(factory);
  realm.getAuthenticationInfo(new UsernamePasswordToken("jsmith", "secret") );
}

代码示例来源:origin: apache/shiro

@SuppressWarnings({"unchecked"})
@Test
public void testSubmitRunnable() {
  ExecutorService mockExecutorService = createNiceMock(ExecutorService.class);
  expect(mockExecutorService.submit(isA(SubjectRunnable.class))).andReturn(new DummyFuture());
  replay(mockExecutorService);
  final SubjectAwareExecutorService executor = new SubjectAwareExecutorService(mockExecutorService);
  Runnable testRunnable = new Runnable() {
    public void run() {
      System.out.println("Hello World");
    }
  };
  executor.submit(testRunnable);
  verify(mockExecutorService);
}

代码示例来源:origin: apache/shiro

@Test
  public void testExecute() {
    Executor targetMockExecutor = createNiceMock(Executor.class);
    //* ensure the target Executor receives a SubjectRunnable instance that retains the subject identity:
    //(this is what verifies the test is valid):
    targetMockExecutor.execute(isA(SubjectRunnable.class));
    replay(targetMockExecutor);

    final SubjectAwareExecutor executor = new SubjectAwareExecutor(targetMockExecutor);

    Runnable work = new Runnable() {
      public void run() {
        System.out.println("Hello World");
      }
    };
    executor.execute(work);

    verify(targetMockExecutor);
  }
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

public void testBuildOfferListForOrder() throws Exception {
  EasyMock.expect(customerOfferDaoMock.readCustomerOffersByCustomer(EasyMock.isA(Customer.class))).andReturn(new ArrayList<CustomerOffer>());
  EasyMock.expect(offerDaoMock.readOffersByAutomaticDeliveryType()).andReturn(dataProvider.createCustomerBasedOffer(null, dataProvider.yesterday(), dataProvider.tomorrow(), OfferDiscountType.PERCENT_OFF));
  replay();
  Order order = dataProvider.createBasicPromotableOrder().getOrder();
  List<Offer> offers = offerService.buildOfferListForOrder(order);
  assertTrue(offers.size() == 1);
  verify();
}

代码示例来源:origin: apache/httpcomponents-client

protected IExpectationSetters<ClassicHttpResponse> backendExpectsAnyRequest() throws Exception {
  final ClassicHttpResponse resp = mockExecChain.proceed(
      EasyMock.isA(ClassicHttpRequest.class),
      EasyMock.isA(ExecChain.Scope.class));
  return EasyMock.expect(resp);
}

代码示例来源:origin: apache/shiro

@Test
public void testUserDnTemplateSubstitution() throws NamingException {
  realm.setUserDnTemplate("uid={0},ou=users,dc=mycompany,dc=com");
  LdapContextFactory factory = createMock(LdapContextFactory.class);
  realm.setContextFactory(factory);
  Object expectedPrincipal = "uid=jsmith,ou=users,dc=mycompany,dc=com";
  expect(factory.getLdapContext(eq(expectedPrincipal), isA(Object.class))).andReturn(createNiceMock(LdapContext.class));
  replay(factory);
  realm.getAuthenticationInfo(new UsernamePasswordToken("jsmith", "secret") );
  verify(factory);
}

代码示例来源:origin: apache/shiro

@Test(expected= AuthenticationException.class)
public void testGetAuthenticationInfoNamingAuthenticationException() throws NamingException {
  realm.setUserDnTemplate("uid={0},ou=users,dc=mycompany,dc=com");
  LdapContextFactory factory = createMock(LdapContextFactory.class);
  realm.setContextFactory(factory);
  expect(factory.getLdapContext(isA(Object.class), isA(Object.class)))
      .andThrow(new javax.naming.AuthenticationException("LDAP Authentication failed."));
  replay(factory);
  realm.getAuthenticationInfo(new UsernamePasswordToken("jsmith", "secret") );
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

public void testApplyAllFulfillmentGroupOffers() {
  EasyMock.expect(offerServiceUtilitiesMock.orderMeetsQualifyingSubtotalRequirements(EasyMock.isA(PromotableOrder.class), EasyMock.isA(Offer.class), EasyMock.isA(HashMap.class))).andReturn(true).anyTimes();
  EasyMock.expect(offerServiceUtilitiesMock.orderMeetsSubtotalRequirements(EasyMock.isA(PromotableOrder.class), EasyMock.isA(Offer.class))).andReturn(true).anyTimes();
  replay();
  PromotableOrder order = dataProvider.createBasicPromotableOrder();
  List<PromotableCandidateFulfillmentGroupOffer> qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
  List<Offer> offers = dataProvider.createFGBasedOffer("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF);
  fgProcessor.filterFulfillmentGroupLevelOffer(order, qualifiedOffers, offers.get(0));
  boolean offerApplied = fgProcessor.applyAllFulfillmentGroupOffers(qualifiedOffers, order);
  assertTrue(offerApplied);
  order = dataProvider.createBasicPromotableOrder();
  qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
  offers = dataProvider.createFGBasedOffer("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF);
  offers.addAll(dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))"));
  offers.get(1).setName("secondOffer");
  fgProcessor.filterFulfillmentGroupLevelOffer(order, qualifiedOffers, offers.get(0));
  fgProcessor.filterFulfillmentGroupLevelOffer(order, qualifiedOffers, offers.get(1));
  offerApplied = fgProcessor.applyAllFulfillmentGroupOffers(qualifiedOffers, order);
  //the first offer applies to both fulfillment groups, but the second offer only applies to one of the fulfillment groups
  assertTrue(offerApplied);
  int fgAdjustmentCount = 0;
  for (PromotableFulfillmentGroup fg : order.getFulfillmentGroups()) {
    fgAdjustmentCount += fg.getCandidateFulfillmentGroupAdjustments().size();
  }
  assertTrue(fgAdjustmentCount == 3);
  verify();
}

代码示例来源:origin: apache/httpcomponents-client

protected IExpectationSetters<ClassicHttpResponse> backendExpectsAnyRequestAndThrows(
  final Throwable throwable) throws Exception {
  final ClassicHttpResponse resp = mockExecChain.proceed(
    EasyMock.isA(ClassicHttpRequest.class), EasyMock.isA(ExecChain.Scope.class));
  return EasyMock.expect(resp).andThrow(throwable);
}

代码示例来源:origin: apache/shiro

/**
 * This test simulates that if a non-String principal (i.e. not a username) is passed as the LDAP principal, that
 * it is not altered into a User DN and is passed as-is.  This will allow principals to be things like X.509
 * certificates as well instead of only strings.
 *
 * @throws NamingException not thrown
 */
@Test
public void testGetAuthenticationInfoNonSimpleToken() throws NamingException {
  realm.setUserDnTemplate("uid={0},ou=users,dc=mycompany,dc=com");
  LdapContextFactory factory = createMock(LdapContextFactory.class);
  realm.setContextFactory(factory);
  final UUID userId = UUID.randomUUID();
  //ensure the userId is passed as-is:
  expect(factory.getLdapContext(eq(userId), isA(Object.class))).andReturn(createNiceMock(LdapContext.class));
  replay(factory);
  realm.getAuthenticationInfo(new AuthenticationToken() {
    public Object getPrincipal() {
      return userId;
    }
    public Object getCredentials() {
      return "secret";
    }
  });
  verify(factory);
}

代码示例来源:origin: apache/httpcomponents-client

protected IExpectationSetters<ClassicHttpResponse> backendExpectsAnyRequestAndReturn(
    final ClassicHttpResponse response) throws Exception {
  final ClassicHttpResponse resp = mockExecChain.proceed(
      EasyMock.isA(ClassicHttpRequest.class),
      EasyMock.isA(ExecChain.Scope.class));
  return EasyMock.expect(resp).andReturn(response);
}

代码示例来源:origin: BroadleafCommerce/BroadleafCommerce

public void replay() throws Exception {
  EasyMock.expect(orderItemDaoMock.createOrderItemPriceDetail()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAnswer()).anyTimes();
  EasyMock.expect(orderItemDaoMock.createOrderItemQualifier()).andAnswer(OfferDataItemProvider.getCreateOrderItemQualifierAnswer()).anyTimes();
  EasyMock.expect(offerDaoMock.createOrderItemPriceDetailAdjustment()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAdjustmentAnswer()).anyTimes();
  EasyMock.expect(fgServiceMock.addItemToFulfillmentGroup(EasyMock.isA(FulfillmentGroupItemRequest.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getAddItemToFulfillmentGroupAnswer()).anyTimes();
  EasyMock.expect(orderServiceMock.removeItem(EasyMock.isA(Long.class), EasyMock.isA(Long.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getRemoveItemFromOrderAnswer()).anyTimes();
  EasyMock.expect(orderServiceMock.save(EasyMock.isA(Order.class), EasyMock.isA(Boolean.class))).andAnswer(OfferDataItemProvider.getSaveOrderAnswer()).anyTimes();
  EasyMock.expect(orderServiceMock.getAutomaticallyMergeLikeItems()).andReturn(true).anyTimes();
  EasyMock.expect(orderItemServiceMock.saveOrderItem(EasyMock.isA(OrderItem.class))).andAnswer(OfferDataItemProvider.getSaveOrderItemAnswer()).anyTimes();
  EasyMock.expect(fgItemDaoMock.save(EasyMock.isA(FulfillmentGroupItem.class))).andAnswer(OfferDataItemProvider.getSaveFulfillmentGroupItemAnswer()).anyTimes();
  EasyMock.expect(multishipOptionServiceMock.findOrderMultishipOptions(EasyMock.isA(Long.class))).andAnswer(new IAnswer<List<OrderMultishipOption>>() {
  multishipOptionServiceMock.deleteAllOrderMultishipOptions(EasyMock.isA(Order.class));
  EasyMock.expectLastCall().anyTimes();
  EasyMock.expect(fgServiceMock.collapseToOneShippableFulfillmentGroup(EasyMock.isA(Order.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getSameOrderAnswer()).anyTimes();
  EasyMock.expect(fgItemDaoMock.create()).andAnswer(OfferDataItemProvider.getCreateFulfillmentGroupItemAnswer()).anyTimes();
  fgItemDaoMock.delete(EasyMock.isA(FulfillmentGroupItem.class));
  EasyMock.expectLastCall().anyTimes();
  EasyMock.expect(offerTimeZoneProcessorMock.getTimeZone(EasyMock.isA(OfferImpl.class))).andReturn(TimeZone.getTimeZone("CST")).anyTimes();

代码示例来源:origin: apache/httpcomponents-client

private IExpectationSetters<ClassicHttpResponse> backendExpectsAnyRequestAndReturn(
  final ClassicHttpResponse response) throws Exception {
  final ClassicHttpResponse resp = mockExecChain.proceed(
    EasyMock.isA(ClassicHttpRequest.class), EasyMock.isA(ExecChain.Scope.class));
  return EasyMock.expect(resp).andReturn(response);
}

代码示例来源:origin: geoserver/geoserver

@Test
public void testAppend() throws Exception {
  SimpleFeatureType type =
  expect(fs.addFeatures(isA(FeatureCollection.class)))
      .andReturn(Collections.singletonList((FeatureId) (new FeatureIdImpl("trees.105"))));
  replay(fs);
  expect(ds.getTypeNames()).andReturn(new String[] {"trees"}).anyTimes();
  expect(ds.getSchema("trees")).andReturn(type).anyTimes();
  expect(ds.getFeatureSource("trees")).andReturn(fs);
  replay(ds);

代码示例来源:origin: apache/httpcomponents-client

private IExpectationSetters<ClassicHttpResponse> implExpectsAnyRequestAndReturn(
    final ClassicHttpResponse response) throws Exception {
  final ClassicHttpResponse resp = impl.callBackend(
      same(host),
      isA(ClassicHttpRequest.class),
      isA(ExecChain.Scope.class),
      isA(ExecChain.class));
  return EasyMock.expect(resp).andReturn(response);
}

代码示例来源:origin: geoserver/geoserver

@Test
public void testAppend() throws Exception {
  SimpleFeatureType type =
  expect(fs.addFeatures(isA(FeatureCollection.class)))
      .andReturn(Collections.singletonList((FeatureId) (new FeatureIdImpl("trees.105"))));
  replay(fs);
  expect(ds.getTypeNames()).andReturn(new String[] {"trees"}).anyTimes();
  expect(ds.getSchema("trees")).andReturn(type).anyTimes();
  expect(ds.getFeatureSource("trees")).andReturn(fs);
  replay(ds);

代码示例来源:origin: apache/httpcomponents-client

private void handleBackendResponseReturnsResponse(final ClassicHttpRequest request, final ClassicHttpResponse response)
    throws IOException {
  expect(
      impl.handleBackendResponse(
          same(host),
          same(request),
          same(scope),
          isA(Date.class),
          isA(Date.class),
          isA(ClassicHttpResponse.class))).andReturn(response);
}

代码示例来源:origin: linkedin/cruise-control

@Test
public void testDelayedCheck() throws InterruptedException {
 LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
 KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);
 EasyMock.expect(mockAnomalyNotifier.onBrokerFailure(EasyMock.isA(BrokerFailures.class)))
     .andReturn(AnomalyNotificationResult.check(1000L));
 EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
                              EasyMock.anyLong(),
                              EasyMock.eq(3000L),
                              EasyMock.eq(TimeUnit.MILLISECONDS)))
     .andReturn(null);
 EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockMetricAnomalyDetector),
                              EasyMock.anyLong(),
                              EasyMock.eq(3000L),
                              EasyMock.eq(TimeUnit.MILLISECONDS)))
   .andReturn(null);
 EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
     .andDelegateTo(executorService);
 EasyMock.expect(mockDetectorScheduler.schedule(EasyMock.isA(Runnable.class),
                         EasyMock.eq(1000L),
                         EasyMock.eq(TimeUnit.MILLISECONDS)))

代码示例来源:origin: apache/httpcomponents-client

protected IExpectationSetters<ClassicHttpResponse> backendCaptureRequestAndReturn(
    final Capture<ClassicHttpRequest> cap, final ClassicHttpResponse response) throws Exception {
  final ClassicHttpResponse resp = mockExecChain.proceed(
    EasyMock.capture(cap), EasyMock.isA(ExecChain.Scope.class));
  return EasyMock.expect(resp).andReturn(response);
}

代码示例来源:origin: linkedin/cruise-control

@Test
public void testExecutionInProgress() throws InterruptedException {
 LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
 EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
                              EasyMock.anyLong(),
                              EasyMock.eq(3000L),
                              EasyMock.eq(TimeUnit.MILLISECONDS)))
     .andReturn(null);
 EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockMetricAnomalyDetector),
                              EasyMock.anyLong(),
                              EasyMock.eq(3000L),
                              EasyMock.eq(TimeUnit.MILLISECONDS)))
   .andReturn(null);
 EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
     .andDelegateTo(executorService);
 EasyMock.expect(mockKafkaCruiseControl.state(EasyMock.anyObject(), EasyMock.anyObject()))
     .andReturn(new CruiseControlState(
       ExecutorState.replicaMovementInProgress(1,
                           Collections.emptySet(),

相关文章