IN PROGRESS - BATCH-748: Fix EasyMock warnings in Infrastructure
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package org.springframework.batch.item.database;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.classic.Session;
|
||||
@@ -21,32 +21,28 @@ public class HibernateCursorItemReaderStatefulIntegrationTests extends Hibernate
|
||||
//Ensure close is called on the stateful session correctly.
|
||||
public void testStatfulClose(){
|
||||
|
||||
MockControl<SessionFactory> sessionFactoryControl = MockControl.createControl(SessionFactory.class);
|
||||
SessionFactory sessionFactory = sessionFactoryControl.getMock();
|
||||
MockControl<Session> sessionControl = MockControl.createControl(Session.class);
|
||||
Session session = sessionControl.getMock();
|
||||
MockControl<Query> resultsControl = MockControl.createNiceControl(Query.class);
|
||||
Query scrollableResults = resultsControl.getMock();
|
||||
SessionFactory sessionFactory = createMock(SessionFactory.class);
|
||||
Session session = createMock(Session.class);
|
||||
Query scrollableResults = createNiceMock(Query.class);
|
||||
HibernateCursorItemReader<Foo> itemReader = new HibernateCursorItemReader<Foo>();
|
||||
itemReader.setSessionFactory(sessionFactory);
|
||||
itemReader.setQueryString("testQuery");
|
||||
itemReader.setUseStatelessSession(false);
|
||||
|
||||
sessionFactory.openSession();
|
||||
sessionFactoryControl.setReturnValue(session);
|
||||
session.createQuery("testQuery");
|
||||
sessionControl.setReturnValue(scrollableResults);
|
||||
scrollableResults.setFetchSize(0);
|
||||
resultsControl.setReturnValue(scrollableResults);
|
||||
session.close();
|
||||
sessionControl.setReturnValue(null);
|
||||
sessionFactoryControl.replay();
|
||||
sessionControl.replay();
|
||||
resultsControl.replay();
|
||||
expect(sessionFactory.openSession()).andReturn(session);
|
||||
expect(session.createQuery("testQuery")).andReturn(scrollableResults);
|
||||
expect(scrollableResults.setFetchSize(0)).andReturn(scrollableResults);
|
||||
expect(session.close()).andReturn(null);
|
||||
|
||||
replay(sessionFactory);
|
||||
replay(session);
|
||||
replay(scrollableResults);
|
||||
|
||||
itemReader.open(new ExecutionContext());
|
||||
itemReader.close(new ExecutionContext());
|
||||
sessionFactoryControl.verify();
|
||||
sessionControl.verify();
|
||||
|
||||
verify(sessionFactory);
|
||||
verify(session);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import org.springframework.orm.ibatis.SqlMapClientFactoryBean;
|
||||
|
||||
import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class IbatisItemReaderCommonTests extends CommonDatabaseItemStreamItemReaderTests {
|
||||
|
||||
protected ItemReader<Foo> getItemReader() throws Exception {
|
||||
|
||||
@@ -13,6 +13,7 @@ import com.ibatis.sqlmap.client.SqlMapClient;
|
||||
*
|
||||
* @author Robert Kasanicky
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class IbatisItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests {
|
||||
|
||||
protected ItemReader<Foo> createItemReader() throws Exception {
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
|
||||
/**
|
||||
@@ -22,31 +22,30 @@ public class CompositeItemWriterTests extends TestCase {
|
||||
* Regular usage scenario.
|
||||
* All injected processors should be called.
|
||||
*/
|
||||
|
||||
public void testProcess() throws Exception {
|
||||
|
||||
final int NUMBER_OF_WRITERS = 10;
|
||||
Object data = new Object();
|
||||
|
||||
List<MockControl> controls = new ArrayList<MockControl>(NUMBER_OF_WRITERS);
|
||||
List<ItemWriter<Object>> writers = new ArrayList<ItemWriter<Object>>(NUMBER_OF_WRITERS);
|
||||
|
||||
for (int i = 0; i < NUMBER_OF_WRITERS; i++) {
|
||||
MockControl control = MockControl.createStrictControl(ItemWriter.class);
|
||||
ItemWriter writer = (ItemWriter) control.getMock();
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemWriter<Object> writer = createStrictMock(ItemWriter.class);
|
||||
|
||||
writer.write(data);
|
||||
control.setVoidCallable();
|
||||
control.replay();
|
||||
expectLastCall().once();
|
||||
replay(writer);
|
||||
|
||||
writers.add(writer);
|
||||
controls.add(control);
|
||||
}
|
||||
|
||||
itemProcessor.setDelegates(writers);
|
||||
itemProcessor.write(data);
|
||||
|
||||
for (MockControl control : controls) {
|
||||
control.verify();
|
||||
for (ItemWriter<Object> writer : writers) {
|
||||
verify(writer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,77 +17,83 @@ package org.springframework.batch.item.support;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.DelegatingItemWriter;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class DelegatingItemWriterTests extends TestCase {
|
||||
|
||||
MockControl<ItemWriter> writerControl = MockControl.createControl(ItemWriter.class);
|
||||
ItemWriter<Object> itemWriter;
|
||||
@SuppressWarnings("unchecked")
|
||||
ItemWriter<Object> itemWriter = createMock(ItemWriter.class);
|
||||
|
||||
DelegatingItemWriter<Object, Object> delegatingWriter;
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
*/
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
itemWriter = writerControl.getMock();
|
||||
|
||||
delegatingWriter = new DelegatingItemWriter<Object, Object>();
|
||||
delegatingWriter.setDelegate(itemWriter);
|
||||
}
|
||||
|
||||
public void testFlush() throws Exception{
|
||||
public void testFlush() throws Exception {
|
||||
itemWriter.flush();
|
||||
writerControl.replay();
|
||||
expectLastCall().once();
|
||||
replay(itemWriter);
|
||||
delegatingWriter.flush();
|
||||
writerControl.verify();
|
||||
verify(itemWriter);
|
||||
}
|
||||
|
||||
public void testClear() throws Exception{
|
||||
|
||||
public void testClear() throws Exception {
|
||||
itemWriter.clear();
|
||||
writerControl.replay();
|
||||
expectLastCall().once();
|
||||
replay(itemWriter);
|
||||
delegatingWriter.clear();
|
||||
writerControl.verify();
|
||||
verify(itemWriter);
|
||||
}
|
||||
|
||||
public void testCreation() throws Exception{
|
||||
try{
|
||||
|
||||
public void testCreation() throws Exception {
|
||||
try {
|
||||
delegatingWriter.setDelegate(null);
|
||||
delegatingWriter.afterPropertiesSet();
|
||||
fail();
|
||||
}
|
||||
catch(IllegalArgumentException ex){
|
||||
//expected
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testWrite() throws Exception{
|
||||
|
||||
|
||||
public void testWrite() throws Exception {
|
||||
|
||||
ProcessingWriter<Object, Object> writer = new ProcessingWriter<Object, Object>();
|
||||
writer.setDelegate(itemWriter);
|
||||
Object item = new Object();
|
||||
itemWriter.write(item);
|
||||
writerControl.replay();
|
||||
expectLastCall().once();
|
||||
replay(itemWriter);
|
||||
writer.write(item);
|
||||
writerControl.verify();
|
||||
verify(itemWriter);
|
||||
assertTrue(writer.isDoProcessCalled());
|
||||
}
|
||||
|
||||
private class ProcessingWriter<I,O> extends DelegatingItemWriter<I,O>{
|
||||
|
||||
|
||||
private class ProcessingWriter<I, O> extends DelegatingItemWriter<I, O> {
|
||||
|
||||
boolean doProcessCalled = false;
|
||||
|
||||
|
||||
protected O doProcess(I item) throws Exception {
|
||||
doProcessCalled = true;
|
||||
return super.doProcess(item);
|
||||
}
|
||||
|
||||
|
||||
public boolean isDoProcessCalled() {
|
||||
return doProcessCalled;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.batch.item.validator;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.easymock.MockControl;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.support.AbstractItemReader;
|
||||
|
||||
@@ -30,7 +30,6 @@ public class ValidatingItemReaderTests extends TestCase {
|
||||
ItemReader<Object> inputSource;
|
||||
ValidatingItemReader<Object> itemProvider;
|
||||
Validator validator;
|
||||
MockControl validatorControl = MockControl.createControl(Validator.class);
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see junit.framework.TestCase#setUp()
|
||||
@@ -39,7 +38,7 @@ public class ValidatingItemReaderTests extends TestCase {
|
||||
super.setUp();
|
||||
|
||||
inputSource = new MockItemReader(this);
|
||||
validator = (Validator)validatorControl.getMock();
|
||||
validator = createMock(Validator.class);
|
||||
itemProvider = new ValidatingItemReader<Object>();
|
||||
itemProvider.setItemReader(inputSource);
|
||||
itemProvider.setValidator(validator);
|
||||
@@ -72,16 +71,17 @@ public class ValidatingItemReaderTests extends TestCase {
|
||||
public void testValidation() throws Exception{
|
||||
|
||||
validator.validate(this);
|
||||
validatorControl.replay();
|
||||
expectLastCall().once();
|
||||
replay(validator);
|
||||
assertEquals(itemProvider.read(), this);
|
||||
validatorControl.verify();
|
||||
verify(validator);
|
||||
}
|
||||
|
||||
public void testValidationException() throws Exception{
|
||||
|
||||
validator.validate(this);
|
||||
validatorControl.setThrowable(new ValidationException(""));
|
||||
validatorControl.replay();
|
||||
expectLastCall().andThrow(new ValidationException(""));
|
||||
replay(validator);
|
||||
try{
|
||||
itemProvider.read();
|
||||
fail();
|
||||
@@ -91,11 +91,11 @@ public class ValidatingItemReaderTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testNullInput() throws Exception{
|
||||
validatorControl.replay();
|
||||
replay(validator);
|
||||
itemProvider.setItemReader(new MockItemReader(null));
|
||||
assertNull(itemProvider.read());
|
||||
//assert validator wasn't called.
|
||||
validatorControl.verify();
|
||||
verify(validator);
|
||||
}
|
||||
|
||||
private static class MockItemReader extends AbstractItemReader<Object> {
|
||||
|
||||
Reference in New Issue
Block a user