diff --git a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/DelegatingItemWriter.java b/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/DelegatingItemWriter.java deleted file mode 100644 index f5d960c96..000000000 --- a/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/DelegatingItemWriter.java +++ /dev/null @@ -1,87 +0,0 @@ -package org.springframework.batch.item.support; - -import org.springframework.batch.item.ClearFailedException; -import org.springframework.batch.item.FlushFailedException; -import org.springframework.batch.item.ItemWriter; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.util.Assert; - -/** - * Simple wrapper around {@link ItemWriter}. - * - * The implementation is thread-safe if the delegate is thread-safe. - * - * I is the type of item expected as input, O it the - * type of item after transformation that is passed to - * {@link #setDelegate(ItemWriter)}. - * - * @author Dave Syer - * @author Robert Kasanicky - */ -public class DelegatingItemWriter implements ItemWriter, InitializingBean { - - private ItemWriter delegate; - - /** - * Default constructor. - */ - public DelegatingItemWriter() { - super(); - } - - /** - * @param itemWriter - */ - public DelegatingItemWriter(ItemWriter itemWriter) { - this(); - this.delegate = itemWriter; - } - - /** - * Calls {@link #doProcess(Object)} and then writes the result to the - * delegate {@link ItemWriter}. - * @throws Exception - * - * @see ItemWriter#write(Object) - */ - public void write(I item) throws Exception { - O result = doProcess(item); - delegate.write(result); - } - - /** - * By default returns the argument. This method is an extension point meant - * to be overridden by subclasses that implement processing logic. - * @throws Exception - */ - @SuppressWarnings("unchecked") - protected O doProcess(I item) throws Exception { - return (O) item; - } - - /** - * Setter for {@link ItemWriter}. - */ - public void setDelegate(ItemWriter writer) { - this.delegate = writer; - } - - public void afterPropertiesSet() throws Exception { - Assert.notNull(delegate); - } - - /** - * Delegates to {@link ItemWriter#clear()} - */ - public void clear() throws ClearFailedException { - delegate.clear(); - } - - /** - * Delegates to {@link ItemWriter#flush()} - */ - public void flush() throws FlushFailedException { - delegate.flush(); - } - -} diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/DelegatingItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/DelegatingItemWriterTests.java deleted file mode 100644 index 8d620dd9f..000000000 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/DelegatingItemWriterTests.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright 2006-2008 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.batch.item.support; - -import junit.framework.TestCase; - -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 { - - @SuppressWarnings("unchecked") - ItemWriter itemWriter = createMock(ItemWriter.class); - - DelegatingItemWriter delegatingWriter; - - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - - protected void setUp() throws Exception { - super.setUp(); - - delegatingWriter = new DelegatingItemWriter(); - delegatingWriter.setDelegate(itemWriter); - } - - public void testFlush() throws Exception { - itemWriter.flush(); - expectLastCall().once(); - replay(itemWriter); - delegatingWriter.flush(); - verify(itemWriter); - } - - public void testClear() throws Exception { - itemWriter.clear(); - expectLastCall().once(); - replay(itemWriter); - delegatingWriter.clear(); - verify(itemWriter); - } - - public void testCreation() throws Exception { - try { - delegatingWriter.setDelegate(null); - delegatingWriter.afterPropertiesSet(); - fail(); - } - catch (IllegalArgumentException ex) { - // expected - } - } - - public void testWrite() throws Exception { - - ProcessingWriter writer = new ProcessingWriter(); - writer.setDelegate(itemWriter); - Object item = new Object(); - itemWriter.write(item); - expectLastCall().once(); - replay(itemWriter); - writer.write(item); - verify(itemWriter); - assertTrue(writer.isDoProcessCalled()); - } - - private class ProcessingWriter extends DelegatingItemWriter { - - boolean doProcessCalled = false; - - protected O doProcess(I item) throws Exception { - doProcessCalled = true; - return super.doProcess(item); - } - - public boolean isDoProcessCalled() { - return doProcessCalled; - } - } - -}