Allow null return type for interceptors

This commit is contained in:
James Agnew 2019-01-20 19:43:58 -05:00
parent 690af1c7ff
commit 17f03ac843
2 changed files with 3 additions and 6 deletions

View File

@ -26,7 +26,6 @@ import static org.junit.Assert.*;
@ContextConfiguration(classes = {InterceptorRegistryTest.InterceptorRegistryTestCtxConfig.class}) @ContextConfiguration(classes = {InterceptorRegistryTest.InterceptorRegistryTestCtxConfig.class})
public class InterceptorRegistryTest { public class InterceptorRegistryTest {
private static boolean ourNext_beforeRestHookDelivery_Return2;
private static boolean ourNext_beforeRestHookDelivery_Return1; private static boolean ourNext_beforeRestHookDelivery_Return1;
private static List<String> ourInvocations = new ArrayList<>(); private static List<String> ourInvocations = new ArrayList<>();
private static CanonicalSubscription ourLastCanonicalSubscription; private static CanonicalSubscription ourLastCanonicalSubscription;
@ -88,7 +87,6 @@ public class InterceptorRegistryTest {
@Before @Before
public void before() { public void before() {
ourNext_beforeRestHookDelivery_Return1 = true; ourNext_beforeRestHookDelivery_Return1 = true;
ourNext_beforeRestHookDelivery_Return2 = true;
ourLastCanonicalSubscription = null; ourLastCanonicalSubscription = null;
ourLastResourceDeliveryMessage0 = null; ourLastResourceDeliveryMessage0 = null;
ourLastResourceDeliveryMessage1 = null; ourLastResourceDeliveryMessage1 = null;
@ -140,11 +138,10 @@ public class InterceptorRegistryTest {
@Order(200) @Order(200)
public static class MyTestInterceptorTwo { public static class MyTestInterceptorTwo {
@Hook(Pointcut.SUBSCRIPTION_BEFORE_REST_HOOK_DELIVERY) @Hook(Pointcut.SUBSCRIPTION_BEFORE_REST_HOOK_DELIVERY)
public boolean beforeRestHookDelivery(ResourceDeliveryMessage theResourceDeliveryMessage0, ResourceDeliveryMessage theResourceDeliveryMessage1) { public void beforeRestHookDelivery(ResourceDeliveryMessage theResourceDeliveryMessage0, ResourceDeliveryMessage theResourceDeliveryMessage1) {
ourLastResourceDeliveryMessage0 = theResourceDeliveryMessage0; ourLastResourceDeliveryMessage0 = theResourceDeliveryMessage0;
ourLastResourceDeliveryMessage1 = theResourceDeliveryMessage1; ourLastResourceDeliveryMessage1 = theResourceDeliveryMessage1;
ourInvocations.add("MyTestInterceptorTwo.beforeRestHookDelivery"); ourInvocations.add("MyTestInterceptorTwo.beforeRestHookDelivery");
return ourNext_beforeRestHookDelivery_Return2;
} }
} }

View File

@ -254,10 +254,10 @@ public class InterceptorRegistry implements IInterceptorRegistry, ApplicationCon
myMethod = theHookMethod; myMethod = theHookMethod;
Class<?> returnType = theHookMethod.getReturnType(); Class<?> returnType = theHookMethod.getReturnType();
if (returnType.equals(boolean.class) || returnType.equals(Boolean.class)) { if (returnType.equals(boolean.class)) {
myReturnsBoolean = true; myReturnsBoolean = true;
} else { } else {
Validate.isTrue(Void.class.equals(returnType), "Method does not return boolean or void: %s", theHookMethod); Validate.isTrue(void.class.equals(returnType), "Method does not return boolean or void: %s", theHookMethod);
myReturnsBoolean = false; myReturnsBoolean = false;
} }