Browse Source

Polish

pull/24332/head
Stephane Nicoll 5 years ago
parent
commit
bdb9f9570e
  1. 13
      spring-context/src/test/java/org/springframework/context/event/AbstractApplicationEventListenerTests.java
  2. 6
      spring-context/src/test/java/org/springframework/context/event/ApplicationContextEventTests.java
  3. 10
      spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.java
  4. 18
      spring-context/src/test/java/org/springframework/context/event/GenericApplicationListenerAdapterTests.java

13
spring-context/src/test/java/org/springframework/context/event/AbstractApplicationEventListenerTests.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 { @@ -125,17 +123,8 @@ public abstract class AbstractApplicationEventListenerTests {
static class TestEvents {
public ApplicationEvent applicationEvent;
public GenericTestEvent<?> wildcardEvent;
public GenericTestEvent<String> stringEvent;
public GenericTestEvent<Long> longEvent;
public GenericTestEvent<IllegalStateException> illegalStateExceptionEvent;
public GenericTestEvent<IOException> ioExceptionEvent;
}
}

6
spring-context/src/test/java/org/springframework/context/event/ApplicationContextEventTests.java

@ -1,5 +1,5 @@ @@ -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 @@ -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

10
spring-context/src/test/java/org/springframework/context/event/ApplicationListenerMethodAdapterTests.java

@ -1,5 +1,5 @@ @@ -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 @@ -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

18
spring-context/src/test/java/org/springframework/context/event/GenericApplicationListenerAdapterTests.java

@ -1,5 +1,5 @@ @@ -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 @@ @@ -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 @@ -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 @@ -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 @@ -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 @@ -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

Loading…
Cancel
Save