diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java index 360e82b83..1b86efef1 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/AbstractMethodInvokingDelegator.java @@ -31,7 +31,7 @@ import org.springframework.util.MethodInvoker; * * @author Robert Kasanicky */ -public class AbstractMethodInvokingDelegator implements InitializingBean { +public class AbstractMethodInvokingDelegator implements InitializingBean { private Object targetObject; @@ -44,7 +44,7 @@ public class AbstractMethodInvokingDelegator implements InitializingBean { * @return object returned by invoked method * @throws DynamicMethodInvocationException if the {@link MethodInvoker} used throws exception */ - protected Object invokeDelegateMethod() { + protected T invokeDelegateMethod() { MethodInvoker invoker = createMethodInvoker(targetObject, targetMethod); invoker.setArguments(arguments); return doInvoke(invoker); @@ -56,7 +56,7 @@ public class AbstractMethodInvokingDelegator implements InitializingBean { * @return object returned by target method * @throws DynamicMethodInvocationException if the {@link MethodInvoker} used throws exception */ - protected Object invokeDelegateMethodWithArgument(Object object) { + protected T invokeDelegateMethodWithArgument(Object object) { MethodInvoker invoker = createMethodInvoker(targetObject, targetMethod); invoker.setArguments(new Object[]{object}); return doInvoke(invoker); @@ -68,7 +68,7 @@ public class AbstractMethodInvokingDelegator implements InitializingBean { * @return object returned by invoked method * @throws DynamicMethodInvocationException if the {@link MethodInvoker} used throws exception */ - protected Object invokeDelegateMethodWithArguments(Object[] args) { + protected T invokeDelegateMethodWithArguments(Object[] args) { MethodInvoker invoker = createMethodInvoker(targetObject, targetMethod); invoker.setArguments(args); return doInvoke(invoker); @@ -90,7 +90,8 @@ public class AbstractMethodInvokingDelegator implements InitializingBean { * @param invoker configured invoker * @return return value of the invoked method */ - private Object doInvoke(MethodInvoker invoker) { + @SuppressWarnings("unchecked") + private T doInvoke(MethodInvoker invoker) { try { invoker.prepare(); } @@ -102,7 +103,7 @@ public class AbstractMethodInvokingDelegator implements InitializingBean { } try { - return invoker.invoke(); + return (T) invoker.invoke(); } catch (InvocationTargetException e) { throw new DynamicMethodInvocationException(e); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemReaderAdapter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemReaderAdapter.java index 491a63fd6..a6fb858fc 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemReaderAdapter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemReaderAdapter.java @@ -26,12 +26,12 @@ import org.springframework.batch.item.ResetFailedException; * * @author Robert Kasanicky */ -public class ItemReaderAdapter extends AbstractMethodInvokingDelegator implements ItemReader { +public class ItemReaderAdapter extends AbstractMethodInvokingDelegator implements ItemReader { /** * @return return value of the target method. */ - public Object read() throws Exception { + public T read() throws Exception { return invokeDelegateMethod(); } diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemWriterAdapter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemWriterAdapter.java index d4f22e134..25a9960aa 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemWriterAdapter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/ItemWriterAdapter.java @@ -29,7 +29,7 @@ import org.springframework.batch.item.ItemWriter; * * @author Robert Kasanicky */ -public class ItemWriterAdapter extends AbstractMethodInvokingDelegator implements ItemWriter { +public class ItemWriterAdapter extends AbstractMethodInvokingDelegator implements ItemWriter { public void write(Object item) throws Exception { invokeDelegateMethodWithArgument(item); diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java index 9aa88b734..27e0f37ab 100644 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java +++ b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/adapter/PropertyExtractingDelegatingItemWriter.java @@ -31,7 +31,7 @@ import org.springframework.util.Assert; * * @author Robert Kasanicky */ -public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvokingDelegator implements ItemWriter { +public class PropertyExtractingDelegatingItemWriter extends AbstractMethodInvokingDelegator implements ItemWriter { private String[] fieldsUsedAsTargetMethodArguments; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java index 871b22923..7823e65d1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java @@ -15,10 +15,10 @@ import org.springframework.util.Assert; */ public class AbstractDelegatorTests extends TestCase { - private static class ConcreteDelegator extends AbstractMethodInvokingDelegator { + private static class ConcreteDelegator extends AbstractMethodInvokingDelegator { } - private AbstractMethodInvokingDelegator delegator = new ConcreteDelegator(); + private AbstractMethodInvokingDelegator delegator = new ConcreteDelegator(); private Foo foo = new Foo(0, "foo", 1); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/ItemReaderAdapterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/ItemReaderAdapterTests.java index 757cc944e..7b0a1616c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/ItemReaderAdapterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/ItemReaderAdapterTests.java @@ -14,7 +14,7 @@ import org.springframework.test.AbstractDependencyInjectionSpringContextTests; */ public class ItemReaderAdapterTests extends AbstractDependencyInjectionSpringContextTests { - private ItemReaderAdapter provider; + private ItemReaderAdapter provider; private FooService fooService; @@ -41,7 +41,7 @@ public class ItemReaderAdapterTests extends AbstractDependencyInjectionSpringCon } } - public void setProvider(ItemReaderAdapter provider) { + public void setProvider(ItemReaderAdapter provider) { this.provider = provider; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java index 902b1af48..f9e3e34a0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java @@ -2,12 +2,13 @@ package org.springframework.batch.item.database; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; +import org.springframework.batch.item.sample.Foo; public class JdbcCursorItemReaderCommonTests extends CommonDatabaseItemStreamItemReaderTests { - protected ItemReader getItemReader() throws Exception { + protected ItemReader getItemReader() throws Exception { - JdbcCursorItemReader result = new JdbcCursorItemReader(); + JdbcCursorItemReader result = new JdbcCursorItemReader(); result.setDataSource(getDataSource()); result.setSql("select ID, NAME, VALUE from T_FOOS"); result.setIgnoreWarnings(true); @@ -25,14 +26,14 @@ public class JdbcCursorItemReaderCommonTests extends CommonDatabaseItemStreamIte public void testRestartWithDriverSupportsAbsolute() throws Exception { tested = getItemReader(); - ((JdbcCursorItemReader) tested).setDriverSupportsAbsolute(true); + ((JdbcCursorItemReader) tested).setDriverSupportsAbsolute(true); testedAsStream().open(executionContext); testRestart(); } - protected void pointToEmptyInput(ItemReader tested) throws Exception { - JdbcCursorItemReader reader = (JdbcCursorItemReader) tested; + protected void pointToEmptyInput(ItemReader tested) throws Exception { + JdbcCursorItemReader reader = (JdbcCursorItemReader) tested; reader.close(new ExecutionContext()); reader.setSql("select ID from T_FOOS where ID < 0"); reader.afterPropertiesSet(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderIntegrationTests.java index 33ac8be6f..544ba084c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderIntegrationTests.java @@ -1,6 +1,7 @@ package org.springframework.batch.item.database; import org.springframework.batch.item.ItemReader; +import org.springframework.batch.item.sample.Foo; /** * Tests for {@link JdbcCursorItemReader} @@ -9,8 +10,8 @@ import org.springframework.batch.item.ItemReader; */ public class JdbcCursorItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests { - protected ItemReader createItemReader() throws Exception { - JdbcCursorItemReader result = new JdbcCursorItemReader(); + protected ItemReader createItemReader() throws Exception { + JdbcCursorItemReader result = new JdbcCursorItemReader(); result.setDataSource(super.getJdbcTemplate().getDataSource()); result.setSql("select ID, NAME, VALUE from T_FOOS"); result.setIgnoreWarnings(true);