|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
50 | 50 | import org.springframework.context.event.test.AbstractIdentifiable;
|
51 | 51 | import org.springframework.context.event.test.AnotherTestEvent;
|
52 | 52 | import org.springframework.context.event.test.EventCollector;
|
| 53 | +import org.springframework.context.event.test.GenericEventPojo; |
53 | 54 | import org.springframework.context.event.test.Identifiable;
|
54 | 55 | import org.springframework.context.event.test.TestEvent;
|
55 | 56 | import org.springframework.context.support.ClassPathXmlApplicationContext;
|
@@ -443,6 +444,30 @@ public void listenerWithGenericApplicationEvent() {
|
443 | 444 | this.eventCollector.assertTotalEventsCount(1);
|
444 | 445 | }
|
445 | 446 |
|
| 447 | + @Test |
| 448 | + public void listenerWithResolvableTypeEvent() { |
| 449 | + load(ResolvableTypeEventListener.class); |
| 450 | + ResolvableTypeEventListener listener = this.context.getBean(ResolvableTypeEventListener.class); |
| 451 | + |
| 452 | + this.eventCollector.assertNoEventReceived(listener); |
| 453 | + GenericEventPojo<String> event = new GenericEventPojo<>("TEST"); |
| 454 | + this.context.publishEvent(event); |
| 455 | + this.eventCollector.assertEvent(listener, event); |
| 456 | + this.eventCollector.assertTotalEventsCount(1); |
| 457 | + } |
| 458 | + |
| 459 | + @Test |
| 460 | + public void listenerWithResolvableTypeEventWrongGeneric() { |
| 461 | + load(ResolvableTypeEventListener.class); |
| 462 | + ResolvableTypeEventListener listener = this.context.getBean(ResolvableTypeEventListener.class); |
| 463 | + |
| 464 | + this.eventCollector.assertNoEventReceived(listener); |
| 465 | + GenericEventPojo<Long> event = new GenericEventPojo<>(123L); |
| 466 | + this.context.publishEvent(event); |
| 467 | + this.eventCollector.assertNoEventReceived(listener); |
| 468 | + this.eventCollector.assertTotalEventsCount(0); |
| 469 | + } |
| 470 | + |
446 | 471 | @Test
|
447 | 472 | public void conditionMatch() {
|
448 | 473 | long timestamp = System.currentTimeMillis();
|
@@ -791,6 +816,16 @@ public void handleString(PayloadApplicationEvent<String> event) {
|
791 | 816 | }
|
792 | 817 |
|
793 | 818 |
|
| 819 | + @Component |
| 820 | + static class ResolvableTypeEventListener extends AbstractTestEventListener { |
| 821 | + |
| 822 | + @EventListener |
| 823 | + public void handleString(GenericEventPojo<String> value) { |
| 824 | + collectEvent(value); |
| 825 | + } |
| 826 | + } |
| 827 | + |
| 828 | + |
794 | 829 | @Component
|
795 | 830 | static class ConditionalEventListener extends TestEventListener {
|
796 | 831 |
|
|
0 commit comments