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

The following are Jave code examples for showing how to use checkOrder() 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.
Example 1
Project: kafka-connect-fs   File: FsSourceTaskTestBase.java   Source Code and License Vote up 5 votes
@Test
public void exceptionExecutingPolicy() throws InterruptedException, IOException, IllegalAccessException {
    Map<String, String> props = new HashMap<>(taskConfig);
    task.start(props);

    Policy policy = EasyMock.createNiceMock(Policy.class);
    EasyMock.expect(policy.hasEnded()).andReturn(Boolean.FALSE);
    EasyMock.expect(policy.execute()).andThrow(new ConnectException("Exception from mock"));
    EasyMock.expect(policy.getURIs()).andReturn(null);
    EasyMock.checkOrder(policy, false);
    EasyMock.replay(policy);
    MemberModifier.field(FsSourceTask.class, "policy").set(task, policy);

    assertEquals(0, task.poll().size());
}
 
Example 2
Project: kafka-connect-fs   File: FsSourceTaskTestBase.java   Source Code and License Vote up 4 votes
@Before
public void initTask() {
    task = new FsSourceTask();
    taskConfig = new HashMap<String, String>() {{
        String uris[] = directories.stream().map(dir -> dir.toString())
                .toArray(size -> new String[size]);
        put(FsSourceTaskConfig.FS_URIS, String.join(",", uris));
        put(FsSourceTaskConfig.TOPIC, "topic_test");
        put(FsSourceTaskConfig.POLICY_CLASS, SimplePolicy.class.getName());
        put(FsSourceTaskConfig.FILE_READER_CLASS, TextFileReader.class.getName());
        put(FsSourceTaskConfig.POLICY_REGEXP, "^[0-9]*\\.txt$");
    }};

    //Mock initialization
    taskContext = PowerMock.createMock(SourceTaskContext.class);
    offsetStorageReader = PowerMock.createMock(OffsetStorageReader.class);

    EasyMock.expect(taskContext.offsetStorageReader())
            .andReturn(offsetStorageReader);

    EasyMock.expect(taskContext.offsetStorageReader())
            .andReturn(offsetStorageReader);

    EasyMock.expect(offsetStorageReader.offset(EasyMock.anyObject()))
            .andReturn(new HashMap<String, Object>() {{
                put("offset", 5L);
            }});
    EasyMock.expect(offsetStorageReader.offset(EasyMock.anyObject()))
            .andReturn(new HashMap<String, Object>() {{
                put("offset", 5L);
            }});

    EasyMock.checkOrder(taskContext, false);
    EasyMock.replay(taskContext);

    EasyMock.checkOrder(offsetStorageReader, false);
    EasyMock.replay(offsetStorageReader);

    task.initialize(taskContext);

}