IN PROGRESS - BATCH-748: Fix EasyMock warnings in Infrastructure

This commit is contained in:
robokaso
2008-07-29 08:33:22 +00:00
parent 1a128e37e1
commit 4430386422
3 changed files with 24 additions and 28 deletions

View File

@@ -24,7 +24,7 @@ import java.util.List;
import junit.framework.TestCase;
import org.easymock.MockControl;
import static org.easymock.EasyMock.*;
import org.springframework.batch.repeat.RepeatContext;
import org.springframework.batch.repeat.context.RepeatContextSupport;
import org.springframework.batch.repeat.support.RepeatSynchronizationManager;
@@ -51,14 +51,12 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
private PreparedStatement ps;
private MockControl control = MockControl.createControl(PreparedStatement.class);
/*
* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
ps = (PreparedStatement) control.getMock();
ps = createMock(PreparedStatement.class);
jdbcTemplate = new JdbcTemplate() {
public Object execute(String sql, PreparedStatementCallback action) throws DataAccessException {
list.add(sql);
@@ -139,9 +137,9 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
public void testFlush() throws SQLException {
assertTrue(TransactionSynchronizationManager.hasResource(writer.getResourceKey()));
ps.addBatch(); // there is one item in the buffer to start
control.setVoidCallable();
control.expectAndReturn(ps.executeBatch(), new int[0]);
control.replay();
expectLastCall().times(1);
expect(ps.executeBatch()).andReturn(new int[0]);
replay(ps);
writer.flush();
assertFalse(TransactionSynchronizationManager.hasResource(writer.getResourceKey()));
assertEquals(2, list.size());
@@ -156,9 +154,9 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
public void testWriteAndFlush() throws Exception {
assertTrue(TransactionSynchronizationManager.hasResource(writer.getResourceKey()));
ps.addBatch();
control.setVoidCallable(2);
control.expectAndReturn(ps.executeBatch(), new int[] { 123 });
control.replay();
expectLastCall().times(2);
expect(ps.executeBatch()).andReturn(new int[] { 123 });
replay(ps);
writer.write("bar");
writer.flush();
assertFalse(TransactionSynchronizationManager.hasResource(writer.getResourceKey()));
@@ -174,9 +172,9 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
public void testWriteAndFlushWithEmptyUpdate() throws Exception {
assertTrue(TransactionSynchronizationManager.hasResource(writer.getResourceKey()));
ps.addBatch();
control.setVoidCallable(2);
control.expectAndReturn(ps.executeBatch(), new int[] { 0 });
control.replay();
expectLastCall().times(2);
expect(ps.executeBatch()).andReturn(new int[] {0});
replay(ps);
writer.write("bar");
try {
writer.flush();
@@ -200,9 +198,9 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
}
});
ps.addBatch();
control.setVoidCallable();
control.expectAndReturn(ps.executeBatch(), new int[] { 123 });
control.replay();
expectLastCall().times(1);
expect(ps.executeBatch()).andReturn(new int[] {123});
replay(ps);
writer.write("foo");
try {
writer.flush();
@@ -220,7 +218,7 @@ public class BatchSqlUpdateItemWriterTests extends TestCase {
});
writer.write("foo");
writer.flush();
control.verify();
verify(ps);
assertEquals(4, list.size());
assertTrue(list.contains("SQL"));
assertTrue(list.contains("foo"));

View File

@@ -3,6 +3,8 @@
*/
package org.springframework.batch.item.database.support;
import static org.easymock.EasyMock.*;
import java.sql.PreparedStatement;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -10,8 +12,6 @@ import java.util.Map;
import junit.framework.TestCase;
import org.easymock.MockControl;
/**
* @author Lucas Ward
*/
@@ -21,14 +21,12 @@ public class ColumnMapExecutionContextRowMapperTests extends TestCase {
private Map<String, Object> key;
private MockControl psControl = MockControl.createControl(PreparedStatement.class);
private PreparedStatement ps;
@SuppressWarnings("unchecked")
protected void setUp() throws Exception {
super.setUp();
ps = (PreparedStatement)psControl.getMock();
ps = createMock(PreparedStatement.class);
mapper = new ColumnMapItemPreparedStatementSetter();
key = new LinkedHashMap<String, Object>(2);
@@ -38,18 +36,18 @@ public class ColumnMapExecutionContextRowMapperTests extends TestCase {
public void testCreateExecutionContextFromEmptyKeys() throws Exception {
psControl.replay();
replay(ps);
mapper.setValues(new HashMap<String, Object>(), ps);
psControl.verify();
verify(ps);
}
public void testCreateSetter() throws Exception {
ps.setObject(1, new Integer(1));
ps.setObject(2, new Integer(2));
psControl.replay();
replay(ps);
mapper.setValues(key, ps);
psControl.verify();
verify(ps);
}
}

View File

@@ -19,7 +19,7 @@ import javax.sql.DataSource;
import junit.framework.TestCase;
import org.easymock.MockControl;
import static org.easymock.EasyMock.*;
import org.springframework.jdbc.support.incrementer.DB2SequenceMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.HsqlMaxValueIncrementer;
@@ -43,7 +43,7 @@ public class DefaultDataFieldMaxValueIncrementerFactoryTests extends TestCase {
protected void setUp() throws Exception {
super.setUp();
DataSource dataSource = (DataSource)MockControl.createControl(DataSource.class).getMock();
DataSource dataSource = createMock(DataSource.class);
factory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource);
}