Refine contribution #3934
* Add default methods in all listener interfaces * Remove usage of newly deprecated support classes Issue #3924
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2021 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.
|
||||
@@ -23,6 +23,7 @@ package org.springframework.batch.repeat;
|
||||
* framework provides callbacks at key points in the processing.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
public interface RepeatListener {
|
||||
@@ -32,7 +33,8 @@ public interface RepeatListener {
|
||||
*
|
||||
* @param context the current batch context.
|
||||
*/
|
||||
void before(RepeatContext context);
|
||||
default void before(RepeatContext context) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the framework after each item has been processed, unless the
|
||||
@@ -42,7 +44,8 @@ public interface RepeatListener {
|
||||
* @param context the current batch context
|
||||
* @param result the result of the callback
|
||||
*/
|
||||
void after(RepeatContext context, RepeatStatus result);
|
||||
default void after(RepeatContext context, RepeatStatus result) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called once at the start of a complete batch, before any items are
|
||||
@@ -54,7 +57,8 @@ public interface RepeatListener {
|
||||
*
|
||||
* @param context the current batch context
|
||||
*/
|
||||
void open(RepeatContext context);
|
||||
default void open(RepeatContext context) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a repeat callback fails by throwing an exception. There will
|
||||
@@ -67,7 +71,8 @@ public interface RepeatListener {
|
||||
* @param context the current batch context
|
||||
* @param e the error that was encountered in an item callback.
|
||||
*/
|
||||
void onError(RepeatContext context, Throwable e);
|
||||
default void onError(RepeatContext context, Throwable e) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Called once at the end of a complete batch, after normal or abnormal
|
||||
@@ -76,5 +81,6 @@ public interface RepeatListener {
|
||||
*
|
||||
* @param context the current batch context.
|
||||
*/
|
||||
void close(RepeatContext context);
|
||||
default void close(RepeatContext context) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2021 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.
|
||||
@@ -24,8 +24,11 @@ import org.springframework.batch.repeat.RepeatListener;
|
||||
* Empty method implementation of {@link RepeatListener}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
* @deprecated as of v5.0 in favor of the default methods in {@link RepeatListener}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class RepeatListenerSupport implements RepeatListener {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2021 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.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.batch.repeat.context.RepeatContextSupport;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
public class CompositeRepeatListenerTests extends TestCase {
|
||||
@@ -39,12 +40,12 @@ public class CompositeRepeatListenerTests extends TestCase {
|
||||
* Test method for {@link CompositeRepeatListener#setListeners(RepeatListener[])}.
|
||||
*/
|
||||
public void testSetListeners() {
|
||||
listener.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
listener.setListeners(new RepeatListener[] { new RepeatListener() {
|
||||
@Override
|
||||
public void open(RepeatContext context) {
|
||||
list.add("fail");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
}, new RepeatListener() {
|
||||
@Override
|
||||
public void open(RepeatContext context) {
|
||||
list.add("continue");
|
||||
@@ -59,7 +60,7 @@ public class CompositeRepeatListenerTests extends TestCase {
|
||||
* {@link CompositeRepeatListener#register(RepeatListener)}.
|
||||
*/
|
||||
public void testSetListener() {
|
||||
listener.register(new RepeatListenerSupport() {
|
||||
listener.register(new RepeatListener() {
|
||||
@Override
|
||||
public void before(RepeatContext context) {
|
||||
list.add("fail");
|
||||
@@ -70,7 +71,7 @@ public class CompositeRepeatListenerTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testClose() {
|
||||
listener.register(new RepeatListenerSupport() {
|
||||
listener.register(new RepeatListener() {
|
||||
@Override
|
||||
public void close(RepeatContext context) {
|
||||
list.add("foo");
|
||||
@@ -81,7 +82,7 @@ public class CompositeRepeatListenerTests extends TestCase {
|
||||
}
|
||||
|
||||
public void testOnError() {
|
||||
listener.register(new RepeatListenerSupport() {
|
||||
listener.register(new RepeatListener() {
|
||||
@Override
|
||||
public void onError(RepeatContext context, Throwable e) {
|
||||
list.add(e);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2021 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.
|
||||
@@ -36,12 +36,12 @@ public class RepeatListenerTests extends TestCase {
|
||||
public void testBeforeInterceptors() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
template.setListeners(new RepeatListener[] { new RepeatListener() {
|
||||
@Override
|
||||
public void before(RepeatContext context) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
}, new RepeatListener() {
|
||||
@Override
|
||||
public void before(RepeatContext context) {
|
||||
calls.add("2");
|
||||
@@ -65,7 +65,7 @@ public class RepeatListenerTests extends TestCase {
|
||||
public void testBeforeInterceptorCanVeto() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<>();
|
||||
template.registerListener(new RepeatListenerSupport() {
|
||||
template.registerListener(new RepeatListener() {
|
||||
@Override
|
||||
public void before(RepeatContext context) {
|
||||
calls.add("1");
|
||||
@@ -87,12 +87,12 @@ public class RepeatListenerTests extends TestCase {
|
||||
public void testAfterInterceptors() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
template.setListeners(new RepeatListener[] { new RepeatListener() {
|
||||
@Override
|
||||
public void after(RepeatContext context, RepeatStatus result) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
}, new RepeatListener() {
|
||||
@Override
|
||||
public void after(RepeatContext context, RepeatStatus result) {
|
||||
calls.add("2");
|
||||
@@ -114,12 +114,12 @@ public class RepeatListenerTests extends TestCase {
|
||||
public void testOpenInterceptors() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
template.setListeners(new RepeatListener[] { new RepeatListener() {
|
||||
@Override
|
||||
public void open(RepeatContext context) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
}, new RepeatListener() {
|
||||
@Override
|
||||
public void open(RepeatContext context) {
|
||||
calls.add("2");
|
||||
@@ -140,7 +140,7 @@ public class RepeatListenerTests extends TestCase {
|
||||
public void testSingleOpenInterceptor() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<>();
|
||||
template.registerListener(new RepeatListenerSupport() {
|
||||
template.registerListener(new RepeatListener() {
|
||||
@Override
|
||||
public void open(RepeatContext context) {
|
||||
calls.add("1");
|
||||
@@ -161,12 +161,12 @@ public class RepeatListenerTests extends TestCase {
|
||||
public void testCloseInterceptors() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
template.setListeners(new RepeatListener[] { new RepeatListener() {
|
||||
@Override
|
||||
public void close(RepeatContext context) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
}, new RepeatListener() {
|
||||
@Override
|
||||
public void close(RepeatContext context) {
|
||||
calls.add("2");
|
||||
@@ -189,12 +189,12 @@ public class RepeatListenerTests extends TestCase {
|
||||
public void testOnErrorInterceptors() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
template.setListeners(new RepeatListener[] { new RepeatListener() {
|
||||
@Override
|
||||
public void onError(RepeatContext context, Throwable t) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
}, new RepeatListener() {
|
||||
@Override
|
||||
public void onError(RepeatContext context, Throwable t) {
|
||||
calls.add("2");
|
||||
@@ -219,12 +219,12 @@ public class RepeatListenerTests extends TestCase {
|
||||
public void testOnErrorInterceptorsPrecedence() throws Exception {
|
||||
RepeatTemplate template = new RepeatTemplate();
|
||||
final List<Object> calls = new ArrayList<>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
template.setListeners(new RepeatListener[] { new RepeatListener() {
|
||||
@Override
|
||||
public void after(RepeatContext context, RepeatStatus result) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
}, new RepeatListener() {
|
||||
@Override
|
||||
public void onError(RepeatContext context, Throwable t) {
|
||||
calls.add("2");
|
||||
@@ -252,12 +252,12 @@ public class RepeatListenerTests extends TestCase {
|
||||
template.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
final List<Object> calls = new ArrayList<>();
|
||||
final List<Object> fails = new ArrayList<>();
|
||||
template.setListeners(new RepeatListener[] { new RepeatListenerSupport() {
|
||||
template.setListeners(new RepeatListener[] { new RepeatListener() {
|
||||
@Override
|
||||
public void after(RepeatContext context, RepeatStatus result) {
|
||||
calls.add("1");
|
||||
}
|
||||
}, new RepeatListenerSupport() {
|
||||
}, new RepeatListener() {
|
||||
@Override
|
||||
public void onError(RepeatContext context, Throwable t) {
|
||||
calls.add("2");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2021 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.
|
||||
@@ -42,6 +42,7 @@ import org.springframework.batch.repeat.policy.SimpleCompletionPolicy;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
*/
|
||||
public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
|
||||
@@ -458,7 +459,7 @@ public class SimpleRepeatTemplateTests extends AbstractTradeBatchTests {
|
||||
}
|
||||
ExceptionHandlerStub exHandler = new ExceptionHandlerStub();
|
||||
|
||||
class RepeatListenerStub extends RepeatListenerSupport {
|
||||
class RepeatListenerStub implements RepeatListener {
|
||||
boolean called = false;
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user