diff --git a/spring-context/src/test/java/org/springframework/context/event/AbstractApplicationEventListenerTests.java b/spring-context/src/test/java/org/springframework/context/event/AbstractApplicationEventListenerTests.java index 31bd074446..bf4360ef58 100644 --- a/spring-context/src/test/java/org/springframework/context/event/AbstractApplicationEventListenerTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/AbstractApplicationEventListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2020 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. @@ -16,8 +16,6 @@ package org.springframework.context.event; -import java.io.IOException; - import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.ResolvableType; @@ -125,17 +123,8 @@ public abstract class AbstractApplicationEventListenerTests { static class TestEvents { - public ApplicationEvent applicationEvent; - public GenericTestEvent wildcardEvent; - public GenericTestEvent stringEvent; - - public GenericTestEvent longEvent; - - public GenericTestEvent illegalStateExceptionEvent; - - public GenericTestEvent ioExceptionEvent; } } diff --git a/spring-context/src/test/java/org/springframework/context/event/ApplicationContextEventTests.java b/spring-context/src/test/java/org/springframework/context/event/ApplicationContextEventTests.java index 2e92dbcaa1..3b40c090d7 100644 --- a/spring-context/src/test/java/org/springframework/context/event/ApplicationContextEventTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/ApplicationContextEventTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -79,13 +79,13 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen @Test public void multicastGenericEvent() { multicastEvent(true, StringEventListener.class, createGenericTestEvent("test"), - getGenericApplicationEventType("stringEvent")); + ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); } @Test public void multicastGenericEventWrongType() { multicastEvent(false, StringEventListener.class, createGenericTestEvent(123L), - getGenericApplicationEventType("longEvent")); + ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class)); } @Test diff --git a/spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.java b/spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.java index 9d989d33ce..c8fa0fcfe6 100644 --- a/spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -56,27 +56,27 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv @Test public void rawListener() { Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleRaw", ApplicationEvent.class); - supportsEventType(true, method, getGenericApplicationEventType("applicationEvent")); + supportsEventType(true, method, ResolvableType.forClass(ApplicationEvent.class)); } @Test public void rawListenerWithGenericEvent() { Method method = ReflectionUtils.findMethod(SampleEvents.class, "handleRaw", ApplicationEvent.class); - supportsEventType(true, method, getGenericApplicationEventType("stringEvent")); + supportsEventType(true, method, ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); } @Test public void genericListener() { Method method = ReflectionUtils.findMethod( SampleEvents.class, "handleGenericString", GenericTestEvent.class); - supportsEventType(true, method, getGenericApplicationEventType("stringEvent")); + supportsEventType(true, method, ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); } @Test public void genericListenerWrongParameterizedType() { Method method = ReflectionUtils.findMethod( SampleEvents.class, "handleGenericString", GenericTestEvent.class); - supportsEventType(false, method, getGenericApplicationEventType("longEvent")); + supportsEventType(false, method, ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class)); } @Test diff --git a/spring-context/src/test/java/org/springframework/context/event/GenericApplicationListenerAdapterTests.java b/spring-context/src/test/java/org/springframework/context/event/GenericApplicationListenerAdapterTests.java index 18bbae4052..4ef4fdee39 100644 --- a/spring-context/src/test/java/org/springframework/context/event/GenericApplicationListenerAdapterTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/GenericApplicationListenerAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -16,6 +16,8 @@ package org.springframework.context.event; +import java.io.IOException; + import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationEvent; @@ -51,7 +53,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE @Test public void genericListenerStrictType() { - supportsEventType(true, StringEventListener.class, getGenericApplicationEventType("stringEvent")); + supportsEventType(true, StringEventListener.class, ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); } @Test // Demonstrates we can't inject that event because the generic type is lost @@ -83,7 +85,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE @Test public void genericListenerStrictTypeNotMatching() { - supportsEventType(false, StringEventListener.class, getGenericApplicationEventType("longEvent")); + supportsEventType(false, StringEventListener.class, ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class)); } @Test @@ -102,25 +104,25 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE @Test public void genericListenerStrictTypeSubClass() { - supportsEventType(false, ObjectEventListener.class, getGenericApplicationEventType("longEvent")); + supportsEventType(false, ObjectEventListener.class, ResolvableType.forClassWithGenerics(GenericTestEvent.class, Long.class)); } @Test public void genericListenerUpperBoundType() { supportsEventType(true, UpperBoundEventListener.class, - getGenericApplicationEventType("illegalStateExceptionEvent")); + ResolvableType.forClassWithGenerics(GenericTestEvent.class, IllegalStateException.class)); } @Test public void genericListenerUpperBoundTypeNotMatching() { supportsEventType(false, UpperBoundEventListener.class, - getGenericApplicationEventType("ioExceptionEvent")); + ResolvableType.forClassWithGenerics(GenericTestEvent.class, IOException.class)); } @Test public void genericListenerWildcardType() { supportsEventType(true, GenericEventListener.class, - getGenericApplicationEventType("stringEvent")); + ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); } @Test // Demonstrates we cant inject that event because the listener has a wildcard @@ -133,7 +135,7 @@ public class GenericApplicationListenerAdapterTests extends AbstractApplicationE @Test public void genericListenerRawType() { supportsEventType(true, RawApplicationListener.class, - getGenericApplicationEventType("stringEvent")); + ResolvableType.forClassWithGenerics(GenericTestEvent.class, String.class)); } @Test // Demonstrates we cant inject that event because the listener has a raw type