OPEN - issue BATCH-771: Refactor Listeners for chunk changes
Favour collections over arrays in the composite listeners
This commit is contained in:
@@ -15,12 +15,15 @@
|
||||
*/
|
||||
package org.springframework.batch.core.listener;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.ItemReadListener;
|
||||
import org.springframework.batch.core.listener.CompositeItemReadListener;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
@@ -28,14 +31,14 @@ import org.springframework.batch.core.listener.CompositeItemReadListener;
|
||||
*/
|
||||
public class CompositeItemReadListenerTests {
|
||||
|
||||
ItemReadListener listener;
|
||||
CompositeItemReadListener compositeListener;
|
||||
ItemReadListener<Object> listener;
|
||||
CompositeItemReadListener<Object> compositeListener;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
listener = createMock(ItemReadListener.class);
|
||||
compositeListener = new CompositeItemReadListener();
|
||||
compositeListener = new CompositeItemReadListener<Object>();
|
||||
compositeListener.register(listener);
|
||||
}
|
||||
|
||||
@@ -68,8 +71,12 @@ public class CompositeItemReadListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetListners() throws Exception {
|
||||
compositeListener.setListeners(new ItemReadListener[] {listener});
|
||||
public void testSetListeners() throws Exception {
|
||||
compositeListener.setListeners(new ArrayList<ItemReadListener<? super Object>>() {
|
||||
{
|
||||
add(listener);
|
||||
}
|
||||
});
|
||||
listener.beforeRead();
|
||||
replay(listener);
|
||||
compositeListener.beforeRead();
|
||||
|
||||
@@ -74,7 +74,7 @@ public class CompositeItemWriteListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetListners() throws Exception {
|
||||
public void testSetListeners() throws Exception {
|
||||
compositeListener.setListeners(new ArrayList<ItemWriteListener<? super Object>>() {
|
||||
{
|
||||
add(listener);
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
package org.springframework.batch.core.listener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobExecutionListener;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
|
||||
/**
|
||||
@@ -36,10 +36,10 @@ public class CompositeJobExecutionListenerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.CompositeExecutionJobListener#setListeners(org.springframework.batch.core.JobExecutionListener[])}.
|
||||
* {@link org.springframework.batch.core.listener.CompositeExecutionJobListener#setListeners(List)}
|
||||
*/
|
||||
public void testSetListeners() {
|
||||
listener.setListeners(new JobExecutionListener[] { new JobExecutionListenerSupport() {
|
||||
listener.setListeners(Arrays.asList(new JobExecutionListenerSupport() {
|
||||
public void afterJob(JobExecution jobExecution) {
|
||||
list.add("fail");
|
||||
}
|
||||
@@ -47,14 +47,15 @@ public class CompositeJobExecutionListenerTests extends TestCase {
|
||||
public void afterJob(JobExecution jobExecution) {
|
||||
list.add("continue");
|
||||
}
|
||||
} });
|
||||
}));
|
||||
listener.afterJob(null);
|
||||
assertEquals(2, list.size());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.CompositeExecutionJobListener#register(org.springframework.batch.core.JobExecutionListener)}.
|
||||
* {@link org.springframework.batch.core.listener.CompositeExecutionJobListener#register(org.springframework.batch.core.JobExecutionListener)}
|
||||
* .
|
||||
*/
|
||||
public void testSetListener() {
|
||||
listener.register(new JobExecutionListenerSupport() {
|
||||
@@ -68,7 +69,8 @@ public class CompositeJobExecutionListenerTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.CompositeExecutionJobListener#beforeJob(JobExecution)}.
|
||||
* {@link org.springframework.batch.core.listener.CompositeExecutionJobListener#beforeJob(JobExecution)}
|
||||
* .
|
||||
*/
|
||||
public void testOpen() {
|
||||
listener.register(new JobExecutionListenerSupport() {
|
||||
|
||||
@@ -18,12 +18,12 @@ package org.springframework.batch.core.listener;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.StepListener;
|
||||
import org.springframework.batch.repeat.ExitStatus;
|
||||
|
||||
/**
|
||||
@@ -32,7 +32,7 @@ import org.springframework.batch.repeat.ExitStatus;
|
||||
*/
|
||||
public class MulticasterBatchListenerTests {
|
||||
|
||||
private MulticasterBatchListener<String> multicast = new MulticasterBatchListener<String>();
|
||||
private MulticasterBatchListener<Integer, String> multicast = new MulticasterBatchListener<Integer, String>();
|
||||
|
||||
private int count = 0;
|
||||
|
||||
@@ -43,20 +43,15 @@ public class MulticasterBatchListenerTests {
|
||||
multicast.register(new CountingStepListenerSupport());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.listener.MulticasterBatchListener#setListeners(org.springframework.batch.core.StepListener[])}
|
||||
* .
|
||||
*/
|
||||
@Test
|
||||
public void testSetListeners() {
|
||||
multicast.setListeners(new StepListener[] { new StepListenerSupport<String>() {
|
||||
multicast.setListeners(Arrays.asList(new StepListenerSupport<Integer, String>() {
|
||||
@Override
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
count++;
|
||||
return super.afterStep(stepExecution);
|
||||
}
|
||||
} });
|
||||
}));
|
||||
multicast.afterStep(null);
|
||||
// setListeners is cumulative (should be OK if used for DI)
|
||||
assertEquals(2, count);
|
||||
@@ -69,7 +64,7 @@ public class MulticasterBatchListenerTests {
|
||||
*/
|
||||
@Test
|
||||
public void testRegister() {
|
||||
multicast.register(new StepListenerSupport<String>() {
|
||||
multicast.register(new StepListenerSupport<Integer, String>() {
|
||||
@Override
|
||||
public ExitStatus afterStep(StepExecution stepExecution) {
|
||||
count++;
|
||||
@@ -502,7 +497,7 @@ public class MulticasterBatchListenerTests {
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
private final class CountingStepListenerSupport extends StepListenerSupport<String> {
|
||||
private final class CountingStepListenerSupport extends StepListenerSupport<Integer, String> {
|
||||
@Override
|
||||
public void onReadError(Exception ex) {
|
||||
count++;
|
||||
@@ -536,7 +531,7 @@ public class MulticasterBatchListenerTests {
|
||||
* (java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void afterRead(Object item) {
|
||||
public void afterRead(Integer item) {
|
||||
count++;
|
||||
if (error) {
|
||||
throw new RuntimeException("listener error");
|
||||
|
||||
@@ -134,7 +134,7 @@ public class SimpleStepFactoryBeanTests {
|
||||
throw new RuntimeException("Error!");
|
||||
}
|
||||
});
|
||||
factory.setListeners(new StepListener[] { new ItemListenerSupport<String>() {
|
||||
factory.setListeners(new StepListener[] { new ItemListenerSupport<String,String>() {
|
||||
@Override
|
||||
public void onReadError(Exception ex) {
|
||||
listened.add(ex);
|
||||
|
||||
Reference in New Issue
Block a user