Java Code Examples for org.easymock.EasyMock.verify()

The following are Jave code examples for showing how to use verify() of the org.easymock.EasyMock class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: kafka-0.11.0.0-src-with-comment   File: FileRecordsTest.java   View Source Code Vote up 6 votes
/**
 * Expect a KafkaException if targetSize is bigger than the size of
 * the FileRecords.
 */
@Test
public void testTruncateNotCalledIfSizeIsBiggerThanTargetSize() throws IOException {
    FileChannel channelMock = EasyMock.createMock(FileChannel.class);

    EasyMock.expect(channelMock.size()).andReturn(42L).atLeastOnce();
    EasyMock.expect(channelMock.position(42L)).andReturn(null);
    EasyMock.replay(channelMock);

    FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false);

    try {
        fileRecords.truncateTo(43);
        fail("Should throw KafkaException");
    } catch (KafkaException e) {
        // expected
    }

    EasyMock.verify(channelMock);
}
 
Example 2
Project: intellij-deps-ini4j   File: IniParserTest.java   View Source Code Vote up 6 votes
@Test public void testEmptyOption() throws Exception
{
    IniParser parser = new IniParser();
    IniHandler handler = EasyMock.createMock(IniHandler.class);

    handler.startIni();
    handler.startSection(SECTION);
    handler.handleOption(OPTION, null);
    handler.endSection();
    handler.endIni();
    EasyMock.replay(handler);
    Config cfg = new Config();

    cfg.setEmptyOption(true);
    parser.setConfig(cfg);
    parser.parse(new StringReader(CFG_EMPTY_OPTION), handler);
    EasyMock.verify(handler);
}
 
Example 3
Project: uPortal-start   File: PersonDirAuthenticationHandlerTest.java   View Source Code Vote up 6 votes
@Test
public void testInvalidSHA256Password() throws Exception {
    final UserPasswordDao userPasswordDao = EasyMock.createMock(UserPasswordDao.class);
    EasyMock.expect(userPasswordDao.getPasswordHash("student"))
            .andReturn("(SHA256)KwAQC001SoPq/CjHMLSz2o0aAqx7WrKeRFgWOeM2GEyLXGZd+1/XkA==");

    final PersonDirAuthenticationHandler authenticationHandler =
            new PersonDirAuthenticationHandler();
    authenticationHandler.setUserPasswordDao(userPasswordDao);

    final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials();
    credentials.setUsername("student");
    credentials.setPassword("student");

    EasyMock.replay(userPasswordDao);

    final boolean auth =
            authenticationHandler.authenticateUsernamePasswordInternal(credentials);

    EasyMock.verify(userPasswordDao);

    assertFalse(auth);
}
 
Example 4
Project: kafka-0.11.0.0-src-with-comment   File: FileRecordsTest.java   View Source Code Vote up 5 votes
/**
 * see #testTruncateNotCalledIfSizeIsSameAsTargetSize
 */
@Test
public void testTruncateIfSizeIsDifferentToTargetSize() throws IOException {
    FileChannel channelMock = EasyMock.createMock(FileChannel.class);

    EasyMock.expect(channelMock.size()).andReturn(42L).atLeastOnce();
    EasyMock.expect(channelMock.position(42L)).andReturn(null).once();
    EasyMock.expect(channelMock.truncate(23L)).andReturn(null).once();
    EasyMock.replay(channelMock);

    FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false);
    fileRecords.truncateTo(23);

    EasyMock.verify(channelMock);
}
 
Example 5
Project: kafka-0.11.0.0-src-with-comment   File: UtilsTest.java   View Source Code Vote up 5 votes
/**
 * Tests that `readFullyOrFail` behaves correctly if multiple `FileChannel.read` operations are required to fill
 * the destination buffer.
 */
@Test
public void testReadFullyOrFailWithPartialFileChannelReads() throws IOException {
    FileChannel channelMock = EasyMock.createMock(FileChannel.class);
    final int bufferSize = 100;
    ByteBuffer buffer = ByteBuffer.allocate(bufferSize);
    StringBuilder expectedBufferContent = new StringBuilder();
    fileChannelMockExpectReadWithRandomBytes(channelMock, expectedBufferContent, bufferSize);
    EasyMock.replay(channelMock);
    Utils.readFullyOrFail(channelMock, buffer, 0L, "test");
    assertEquals("The buffer should be populated correctly", expectedBufferContent.toString(),
            new String(buffer.array()));
    assertFalse("The buffer should be filled", buffer.hasRemaining());
    EasyMock.verify(channelMock);
}
 
Example 6
Project: ms-gs-plugins   File: BoundsUpdateTransactionListenerTest.java   View Source Code Vote up 5 votes
@Test
public void testDataStoreChangeDoesNotPropagateExceptions() {
    TransactionEvent event = EasyMock.createNiceMock(TransactionEvent.class);
    EasyMock.expect(event.getSource()).andStubThrow(new RuntimeException("This exception should be eaten to prevent the transaction from failing"));
    EasyMock.replay(catalog, featureType1, featureType2, event);
    
    listener.dataStoreChange(event);
    
    EasyMock.verify(catalog, featureType1, featureType2, event);
}
 
Example 7
Project: ms-gs-plugins   File: BoundsUpdateTransactionListenerTest.java   View Source Code Vote up 5 votes
@Test
public void testAfterTransactionUncommitted() {
    TransactionType request = EasyMock.createNiceMock(TransactionType.class);
    EasyMock.replay(catalog, featureType1, featureType2, request);
    TransactionResponseType result = EasyMock.createNiceMock(TransactionResponseType.class);
    boolean committed = false;
    
    listener.afterTransaction(request, result, committed);
    
    EasyMock.verify(catalog, featureType1, featureType2, request);
}
 
Example 8
Project: kafka-0.11.0.0-src-with-comment   File: KafkaProducerTest.java   View Source Code Vote up 5 votes
@PrepareOnlyThisForTest(Metadata.class)
@Test
public void testInterceptorPartitionSetOnTooLargeRecord() throws Exception {
    Properties props = new Properties();
    props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
    props.setProperty(ProducerConfig.MAX_REQUEST_SIZE_CONFIG, "1");
    String topic = "topic";
    ProducerRecord<String, String> record = new ProducerRecord<>(topic, "value");
    
    KafkaProducer<String, String> producer = new KafkaProducer<>(props, new StringSerializer(),
            new StringSerializer());
    Metadata metadata = PowerMock.createNiceMock(Metadata.class);
    MemberModifier.field(KafkaProducer.class, "metadata").set(producer, metadata);
    final Cluster cluster = new Cluster(
        "dummy",
        Collections.singletonList(new Node(0, "host1", 1000)),
        Arrays.asList(new PartitionInfo(topic, 0, null, null, null)),
        Collections.<String>emptySet(),
        Collections.<String>emptySet());
    EasyMock.expect(metadata.fetch()).andReturn(cluster).once();
    
    // Mock interceptors field
    ProducerInterceptors interceptors = PowerMock.createMock(ProducerInterceptors.class);
    EasyMock.expect(interceptors.onSend(record)).andReturn(record);
    interceptors.onSendError(EasyMock.eq(record), EasyMock.<TopicPartition>notNull(), EasyMock.<Exception>notNull());
    EasyMock.expectLastCall();
    MemberModifier.field(KafkaProducer.class, "interceptors").set(producer, interceptors);
    
    PowerMock.replay(metadata);
    EasyMock.replay(interceptors);
    producer.send(record);
    
    EasyMock.verify(interceptors);
    
}
 
Example 9
Project: cruise-control   File: AnomalyDetectorTest.java   View Source Code Vote up 4 votes
@Test
public void testExecutionInProgress() throws InterruptedException, KafkaCruiseControlException {
  LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
  AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
  BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
  GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
  ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
  ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
  KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);

  // Starting periodic goal violation detection.
  EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
                                                            EasyMock.anyLong(),
                                                            EasyMock.eq(3000L),
                                                            EasyMock.eq(TimeUnit.MILLISECONDS)))
          .andReturn(null);

  // Starting anomaly handler
  EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
          .andDelegateTo(executorService);
  // For detector shutdown.
  mockDetectorScheduler.shutdown();
  EasyMock.expectLastCall().andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
  EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);

  // The following state are used to test the delayed check when executor is busy.
  EasyMock.expect(mockKafkaCruiseControl.state())
          .andReturn(new KafkaCruiseControlState(
              ExecutorState.replicaMovementInProgress(1, Collections.emptySet(), Collections.emptySet(),
                                                      1, 1),
              null, null));

  EasyMock.replay(mockAnomalyNotifier);
  EasyMock.replay(mockBrokerFailureDetector);
  EasyMock.replay(mockGoalViolationDetector);
  EasyMock.replay(mockDetectorScheduler);
  EasyMock.replay(mockKafkaCruiseControl);

  AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
                                                        mockGoalViolationDetector, mockBrokerFailureDetector,
                                                        mockDetectorScheduler);

  try {
    anomalyDetector.startDetection();
    anomalies.add(new GoalViolations());
    while (!anomalies.isEmpty()) {
      // Just wait for the anomalies to be drained.
    }
    anomalyDetector.shutdown();
    assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));

    EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
  } finally {
    executorService.shutdown();
  }
}
 
Example 10
Project: EatDubbo   File: FailbackClusterInvokerTest.java   View Source Code Vote up 4 votes
@After
public void tearDown() {
    EasyMock.verify(invoker, dic);

}
 
Example 11
Project: EatDubbo   File: FailfastClusterInvokerTest.java   View Source Code Vote up 4 votes
@After
public void tearDown(){
    EasyMock.verify(invoker1,dic);
    
}
 
Example 12
Project: dubbocloud   File: FailfastClusterInvokerTest.java   View Source Code Vote up 4 votes
@After
public void tearDown(){
    EasyMock.verify(invoker1,dic);
    
}
 
Example 13
Project: ms-gs-plugins   File: BoundsUpdateTransactionListenerTest.java   View Source Code Vote up 4 votes
@Test
public void testAfterTransactionLayerGroupRecursive() throws Exception {
    Map<Object, Object> extendedProperties = new HashMap<Object, Object>();
    ReferencedEnvelope affectedBounds1 = new ReferencedEnvelope(-180, 0, 0, 90, WGS84);
    ReferencedEnvelope affectedBounds2 = new ReferencedEnvelope(0, 180, 0, 90, WGS84);
    ReferencedEnvelope oldBounds = new ReferencedEnvelope(-90, 0, 0, 45, WGS84);
    ReferencedEnvelope newBounds = new ReferencedEnvelope(oldBounds);
    newBounds.expandToInclude(affectedBounds1);
    newBounds.expandToInclude(affectedBounds2);
    
    EasyMock.expect(catalog.getFeatureTypeByName(featureTypeName1)).andStubReturn(featureType1);
    EasyMock.expect(featureType1.getNativeBoundingBox()).andStubReturn(oldBounds);
    
    LayerInfo layer = mockLayer(featureType1, "layer");
    LayerInfo otherLayer = mockLayer(featureType2, "otherLayer");
    
    List<LayerGroupInfo> groups = new ArrayList<>();
    
    LayerGroupInfo direct = mockGroup("direct", oldBounds, otherLayer, layer);
    direct.setBounds(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(direct);EasyMock.expectLastCall().once();
    groups.add(direct);
    
    LayerGroupInfo indirect1 = mockGroup("indirect1", oldBounds, otherLayer, direct);
    indirect1.setBounds(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(indirect1);EasyMock.expectLastCall().once();
    groups.add(indirect1);
    
    LayerGroupInfo indirect2 = mockGroup("indirect2", oldBounds, otherLayer, indirect1);
    indirect2.setBounds(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(indirect2);EasyMock.expectLastCall().once();
    groups.add(indirect2);
    
    mockLayerGroupList(groups);
    
    // Verify the FT is updated
    featureType1.setNativeBoundingBox(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(featureType1);EasyMock.expectLastCall().once();

    
    EasyMock.replay(catalog, featureType1, featureType2, layer, otherLayer);
    groups.forEach(EasyMock::replay);
    
    issueInsert(extendedProperties, affectedBounds1);
    
    issueInsert(extendedProperties, affectedBounds2);
    
    TransactionType request = EasyMock.createNiceMock(TransactionType.class);
    TransactionResponseType result = EasyMock.createNiceMock(TransactionResponseType.class);
    EasyMock.expect(request.getExtendedProperties()).andReturn(extendedProperties);
    EasyMock.replay(request, result);
    
    listener.afterTransaction(request, result, true);
    
    ReferencedEnvelope expectedEnv = new ReferencedEnvelope(affectedBounds1);
    expectedEnv.expandToInclude(affectedBounds2);
    
    EasyMock.verify(catalog, featureType1, featureType2, request, result, layer, otherLayer);
    groups.forEach(EasyMock::verify);
    
}
 
Example 14
Project: dubbocloud   File: ForkingClusterInvokerTest.java   View Source Code Vote up 4 votes
@After
public void tearDown() {
    EasyMock.verify(invoker1, dic);

}
 
Example 15
Project: dubbo2   File: FailfastClusterInvokerTest.java   View Source Code Vote up 4 votes
@After
public void tearDown(){
    EasyMock.verify(invoker1,dic);
    
}
 
Example 16
Project: dubbocloud   File: FailbackClusterInvokerTest.java   View Source Code Vote up 4 votes
@After
public void tearDown() {
    EasyMock.verify(invoker, dic);

}
 
Example 17
Project: dubbox-hystrix   File: ForkingClusterInvokerTest.java   View Source Code Vote up 4 votes
@After
public void tearDown() {
    EasyMock.verify(invoker1, dic);

}
 
Example 18
Project: dubbox-hystrix   File: FailbackClusterInvokerTest.java   View Source Code Vote up 4 votes
@After
public void tearDown() {
    EasyMock.verify(invoker, dic);

}
 
Example 19
Project: ms-gs-plugins   File: BoundsUpdateTransactionListenerTest.java   View Source Code Vote up 4 votes
@Test
public void testAfterTransaction() throws Exception {
    Map<Object, Object> extendedProperties = new HashMap<Object, Object>();
    ReferencedEnvelope affectedBounds1 = new ReferencedEnvelope(-180, 0, 0, 90, WGS84);
    ReferencedEnvelope affectedBounds2 = new ReferencedEnvelope(0, 180, 0, 90, WGS84);
    ReferencedEnvelope oldBounds = new ReferencedEnvelope(-90, 0, 0, 45, WGS84);
    ReferencedEnvelope newBounds = new ReferencedEnvelope(oldBounds);
    newBounds.expandToInclude(affectedBounds1);
    newBounds.expandToInclude(affectedBounds2);
    
    LayerInfo layer = mockLayer(featureType1, "layer");
    
    EasyMock.expect(catalog.getFeatureTypeByName(featureTypeName1)).andStubReturn(featureType1);
    EasyMock.expect(featureType1.getNativeBoundingBox()).andStubReturn(oldBounds);
    
    // Verify the FT is updated
    featureType1.setNativeBoundingBox(EasyMock.eq(newBounds));EasyMock.expectLastCall().once(); 
    catalog.save(featureType1);EasyMock.expectLastCall().once();
    
    EasyMock.expect(catalog.list(EasyMock.eq(LayerGroupInfo.class), EasyMock.anyObject()))
        .andStubAnswer(()-> new CloseableIteratorAdapter<LayerGroupInfo>(
                Collections.emptyListIterator()));
    
    EasyMock.replay(catalog, featureType1, featureType2, layer);
    
    issueInsert(extendedProperties, affectedBounds1);
    
    issueInsert(extendedProperties, affectedBounds2);
    
    TransactionType request = EasyMock.createNiceMock(TransactionType.class);
    TransactionResponseType result = EasyMock.createNiceMock(TransactionResponseType.class);
    EasyMock.expect(request.getExtendedProperties()).andReturn(extendedProperties);
    EasyMock.replay(request, result);
    
    listener.afterTransaction(request, result, true);
    
    ReferencedEnvelope expectedEnv = new ReferencedEnvelope(affectedBounds1);
    expectedEnv.expandToInclude(affectedBounds2);
    
    EasyMock.verify(catalog, featureType1, featureType2, request, result, layer);
    
}
 
Example 20
Project: github-test   File: FailfastClusterInvokerTest.java   View Source Code Vote up 4 votes
@After
public void tearDown() {
    EasyMock.verify(invoker1, dic);

}