GenericApplicationListenerAdapter caches resolved event types
Issue: SPR-16970
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -33,13 +33,13 @@ public abstract class AbstractApplicationEventListenerTests {
|
||||
try {
|
||||
return ResolvableType.forField(TestEvents.class.getField(fieldName));
|
||||
}
|
||||
catch (NoSuchFieldException e) {
|
||||
catch (NoSuchFieldException ex) {
|
||||
throw new IllegalStateException("No such field on Events '" + fieldName + "'");
|
||||
}
|
||||
}
|
||||
|
||||
protected static class GenericTestEvent<T>
|
||||
extends ApplicationEvent {
|
||||
|
||||
protected static class GenericTestEvent<T> extends ApplicationEvent {
|
||||
|
||||
private final T payload;
|
||||
|
||||
@@ -51,11 +51,9 @@ public abstract class AbstractApplicationEventListenerTests {
|
||||
public T getPayload() {
|
||||
return this.payload;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class SmartGenericTestEvent<T>
|
||||
extends GenericTestEvent<T> implements ResolvableTypeProvider {
|
||||
protected static class SmartGenericTestEvent<T> extends GenericTestEvent<T> implements ResolvableTypeProvider {
|
||||
|
||||
private final ResolvableType resolvableType;
|
||||
|
||||
@@ -119,6 +117,7 @@ public abstract class AbstractApplicationEventListenerTests {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
static class RawApplicationListener implements ApplicationListener {
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
}
|
||||
@@ -137,7 +136,6 @@ public abstract class AbstractApplicationEventListenerTests {
|
||||
public GenericTestEvent<IllegalStateException> illegalStateExceptionEvent;
|
||||
|
||||
public GenericTestEvent<IOException> ioExceptionEvent;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,6 +63,8 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
|
||||
|
||||
@Test
|
||||
public void multicastSimpleEvent() {
|
||||
multicastEvent(true, ApplicationListener.class,
|
||||
new ContextRefreshedEvent(new StaticApplicationContext()), null);
|
||||
multicastEvent(true, ApplicationListener.class,
|
||||
new ContextClosedEvent(new StaticApplicationContext()), null);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -100,8 +100,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
|
||||
|
||||
@Test
|
||||
public void genericListenerStrictTypeSubClass() {
|
||||
supportsEventType(false, ObjectEventListener.class,
|
||||
getGenericApplicationEventType("longEvent"));
|
||||
supportsEventType(false, ObjectEventListener.class, getGenericApplicationEventType("longEvent"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -111,7 +110,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
|
||||
}
|
||||
|
||||
@Test
|
||||
public void genericListenerUpperBoundTypeNotMatching() throws NoSuchFieldException {
|
||||
public void genericListenerUpperBoundTypeNotMatching() {
|
||||
supportsEventType(false, UpperBoundEventListener.class,
|
||||
getGenericApplicationEventType("ioExceptionEvent"));
|
||||
}
|
||||
@@ -142,8 +141,9 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE
|
||||
supportsEventType(true, RawApplicationListener.class, eventType);
|
||||
}
|
||||
|
||||
private void supportsEventType(boolean match, Class<? extends ApplicationListener> listenerType,
|
||||
ResolvableType eventType) {
|
||||
|
||||
private void supportsEventType(
|
||||
boolean match, Class<? extends ApplicationListener> listenerType, ResolvableType eventType) {
|
||||
|
||||
ApplicationListener<?> listener = mock(listenerType);
|
||||
GenericApplicationListenerAdapter adapter = new GenericApplicationListenerAdapter(listener);
|
||||
|
||||
Reference in New Issue
Block a user