This commit is contained in:
Stephane Nicoll 2016-04-12 08:34:38 +02:00
parent 454165f4c8
commit 10554a85c9
8 changed files with 54 additions and 54 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -49,7 +49,7 @@ public abstract class AbstractApplicationEventListenerTests {
} }
public T getPayload() { public T getPayload() {
return payload; return this.payload;
} }
} }

View File

@ -117,7 +117,7 @@ public class AnnotationDrivenEventListenerTests {
public void metaAnnotationIsDiscovered() { public void metaAnnotationIsDiscovered() {
load(MetaAnnotationListenerTestBean.class); load(MetaAnnotationListenerTestBean.class);
MetaAnnotationListenerTestBean bean = context.getBean(MetaAnnotationListenerTestBean.class); MetaAnnotationListenerTestBean bean = this.context.getBean(MetaAnnotationListenerTestBean.class);
this.eventCollector.assertNoEventReceived(bean); this.eventCollector.assertNoEventReceived(bean);
TestEvent event = new TestEvent(); TestEvent event = new TestEvent();
@ -149,9 +149,9 @@ public class AnnotationDrivenEventListenerTests {
failingContext.register(BasicConfiguration.class, failingContext.register(BasicConfiguration.class,
InvalidMethodSignatureEventListener.class); InvalidMethodSignatureEventListener.class);
thrown.expect(BeanInitializationException.class); this.thrown.expect(BeanInitializationException.class);
thrown.expectMessage(InvalidMethodSignatureEventListener.class.getName()); this.thrown.expectMessage(InvalidMethodSignatureEventListener.class.getName());
thrown.expectMessage("cannotBeCalled"); this.thrown.expectMessage("cannotBeCalled");
failingContext.refresh(); failingContext.refresh();
} }
@ -341,7 +341,7 @@ public class AnnotationDrivenEventListenerTests {
this.eventCollector.assertNoEventReceived(listener); this.eventCollector.assertNoEventReceived(listener);
this.context.publishEvent(event); this.context.publishEvent(event);
countDownLatch.await(2, TimeUnit.SECONDS); this.countDownLatch.await(2, TimeUnit.SECONDS);
this.eventCollector.assertEvent(listener, event); this.eventCollector.assertEvent(listener, event);
this.eventCollector.assertTotalEventsCount(1); this.eventCollector.assertTotalEventsCount(1);
} }
@ -356,7 +356,7 @@ public class AnnotationDrivenEventListenerTests {
this.eventCollector.assertNoEventReceived(listener); this.eventCollector.assertNoEventReceived(listener);
this.context.publishEvent(event); this.context.publishEvent(event);
countDownLatch.await(2, TimeUnit.SECONDS); this.countDownLatch.await(2, TimeUnit.SECONDS);
this.eventCollector.assertEvent(listener, event); this.eventCollector.assertEvent(listener, event);
this.eventCollector.assertTotalEventsCount(1); this.eventCollector.assertTotalEventsCount(1);
} }
@ -371,7 +371,7 @@ public class AnnotationDrivenEventListenerTests {
this.eventCollector.assertNoEventReceived(listener); this.eventCollector.assertNoEventReceived(listener);
this.context.publishEvent(event); this.context.publishEvent(event);
countDownLatch.await(2, TimeUnit.SECONDS); this.countDownLatch.await(2, TimeUnit.SECONDS);
this.eventCollector.assertEvent(listener, event); this.eventCollector.assertEvent(listener, event);
this.eventCollector.assertTotalEventsCount(1); this.eventCollector.assertTotalEventsCount(1);
} }
@ -401,7 +401,7 @@ public class AnnotationDrivenEventListenerTests {
this.eventCollector.assertNoEventReceived(listener); this.eventCollector.assertNoEventReceived(listener);
this.context.publishEvent(event); this.context.publishEvent(event);
countDownLatch.await(2, TimeUnit.SECONDS); this.countDownLatch.await(2, TimeUnit.SECONDS);
this.eventCollector.assertEvent(listener, event); this.eventCollector.assertEvent(listener, event);
this.eventCollector.assertTotalEventsCount(1); this.eventCollector.assertTotalEventsCount(1);
@ -699,7 +699,7 @@ public class AnnotationDrivenEventListenerTests {
public void handleAsync(AnotherTestEvent event) { public void handleAsync(AnotherTestEvent event) {
collectEvent(event); collectEvent(event);
if ("fail".equals(event.content)) { if ("fail".equals(event.content)) {
countDownLatch.countDown(); this.countDownLatch.countDown();
throw new IllegalStateException("Test exception"); throw new IllegalStateException("Test exception");
} }
} }
@ -717,7 +717,7 @@ public class AnnotationDrivenEventListenerTests {
public void handleAsync(AnotherTestEvent event) { public void handleAsync(AnotherTestEvent event) {
assertTrue(!Thread.currentThread().getName().equals(event.content)); assertTrue(!Thread.currentThread().getName().equals(event.content));
collectEvent(event); collectEvent(event);
countDownLatch.countDown(); this.countDownLatch.countDown();
} }
} }
@ -756,15 +756,15 @@ public class AnnotationDrivenEventListenerTests {
@EventListener @EventListener
@Override @Override
public void handleIt(TestEvent event) { public void handleIt(TestEvent event) {
eventCollector.addEvent(this, event); this.eventCollector.addEvent(this, event);
} }
@EventListener @EventListener
@Async @Async
public void handleAsync(AnotherTestEvent event) { public void handleAsync(AnotherTestEvent event) {
assertTrue(!Thread.currentThread().getName().equals(event.content)); assertTrue(!Thread.currentThread().getName().equals(event.content));
eventCollector.addEvent(this, event); this.eventCollector.addEvent(this, event);
countDownLatch.countDown(); this.countDownLatch.countDown();
} }
} }
@ -782,15 +782,15 @@ public class AnnotationDrivenEventListenerTests {
@EventListener @EventListener
@Override @Override
public void handleIt(TestEvent event) { public void handleIt(TestEvent event) {
eventCollector.addEvent(this, event); this.eventCollector.addEvent(this, event);
} }
@EventListener @EventListener
@Async @Async
public void handleAsync(AnotherTestEvent event) { public void handleAsync(AnotherTestEvent event) {
assertTrue(!Thread.currentThread().getName().equals(event.content)); assertTrue(!Thread.currentThread().getName().equals(event.content));
eventCollector.addEvent(this, event); this.eventCollector.addEvent(this, event);
countDownLatch.countDown(); this.countDownLatch.countDown();
} }
} }
@ -811,7 +811,7 @@ public class AnnotationDrivenEventListenerTests {
@Override @Override
public void handleIt(TestEvent event) { public void handleIt(TestEvent event) {
eventCollector.addEvent(this, event); this.eventCollector.addEvent(this, event);
} }
} }
@ -914,18 +914,18 @@ public class AnnotationDrivenEventListenerTests {
@EventListener @EventListener
@Order(50) @Order(50)
public void handleThird(String payload) { public void handleThird(String payload) {
order.add("third"); this.order.add("third");
} }
@EventListener @EventListener
@Order(-50) @Order(-50)
public void handleFirst(String payload) { public void handleFirst(String payload) {
order.add("first"); this.order.add("first");
} }
@EventListener @EventListener
public void handleSecond(String payload) { public void handleSecond(String payload) {
order.add("second"); this.order.add("second");
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -452,7 +452,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
@Override @Override
public void onApplicationEvent(MyEvent event) { public void onApplicationEvent(MyEvent event) {
assertTrue(otherListener.seenEvents.contains(event)); assertTrue(this.otherListener.seenEvents.contains(event));
} }
} }
@ -503,7 +503,7 @@ public class ApplicationContextEventTests extends AbstractApplicationEventListen
@Override @Override
public void onApplicationEvent(MyEvent event) { public void onApplicationEvent(MyEvent event) {
assertTrue(otherListener.seenEvents.contains(event)); assertTrue(this.otherListener.seenEvents.contains(event));
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -148,7 +148,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class,
"tooManyParameters", String.class, String.class); "tooManyParameters", String.class, String.class);
thrown.expect(IllegalStateException.class); this.thrown.expect(IllegalStateException.class);
createTestInstance(method); createTestInstance(method);
} }
@ -157,7 +157,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class,
"noParameter"); "noParameter");
thrown.expect(IllegalStateException.class); this.thrown.expect(IllegalStateException.class);
createTestInstance(method); createTestInstance(method);
} }
@ -166,7 +166,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
Method method = ReflectionUtils.findMethod(SampleEvents.class, Method method = ReflectionUtils.findMethod(SampleEvents.class,
"moreThanOneParameter", String.class, Integer.class); "moreThanOneParameter", String.class, Integer.class);
thrown.expect(IllegalStateException.class); this.thrown.expect(IllegalStateException.class);
createTestInstance(method); createTestInstance(method);
} }
@ -237,9 +237,9 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
"generateRuntimeException", GenericTestEvent.class); "generateRuntimeException", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("fail"); GenericTestEvent<String> event = createGenericTestEvent("fail");
thrown.expect(IllegalStateException.class); this.thrown.expect(IllegalStateException.class);
thrown.expectMessage("Test exception"); this.thrown.expectMessage("Test exception");
thrown.expectCause(is(isNull(Throwable.class))); this.thrown.expectCause(is(isNull(Throwable.class)));
invokeListener(method, event); invokeListener(method, event);
} }
@ -249,8 +249,8 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
"generateCheckedException", GenericTestEvent.class); "generateCheckedException", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("fail"); GenericTestEvent<String> event = createGenericTestEvent("fail");
thrown.expect(UndeclaredThrowableException.class); this.thrown.expect(UndeclaredThrowableException.class);
thrown.expectCause(is(instanceOf(IOException.class))); this.thrown.expectCause(is(instanceOf(IOException.class)));
invokeListener(method, event); invokeListener(method, event);
} }
@ -265,8 +265,8 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
Method method = ReflectionUtils.findMethod(InvalidProxyTestBean.class, "handleIt2", ApplicationEvent.class); Method method = ReflectionUtils.findMethod(InvalidProxyTestBean.class, "handleIt2", ApplicationEvent.class);
StaticApplicationListenerMethodAdapter listener = StaticApplicationListenerMethodAdapter listener =
new StaticApplicationListenerMethodAdapter(method, bean); new StaticApplicationListenerMethodAdapter(method, bean);
thrown.expect(IllegalStateException.class); this.thrown.expect(IllegalStateException.class);
thrown.expectMessage("handleIt2"); this.thrown.expectMessage("handleIt2");
listener.onApplicationEvent(createGenericTestEvent("test")); listener.onApplicationEvent(createGenericTestEvent("test"));
} }
@ -373,7 +373,7 @@ public class ApplicationListenerMethodAdapterTests extends AbstractApplicationEv
@Override @Override
public Object getTargetBean() { public Object getTargetBean() {
return targetBean; return this.targetBean;
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -46,20 +46,20 @@ public class EventPublicationInterceptorTests {
@Before @Before
public void setUp() { public void setUp() {
publisher = mock(ApplicationEventPublisher.class); this.publisher = mock(ApplicationEventPublisher.class);
} }
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)
public void testWithNoApplicationEventClassSupplied() throws Exception { public void testWithNoApplicationEventClassSupplied() throws Exception {
EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
interceptor.setApplicationEventPublisher(publisher); interceptor.setApplicationEventPublisher(this.publisher);
interceptor.afterPropertiesSet(); interceptor.afterPropertiesSet();
} }
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)
public void testWithNonApplicationEventClassSupplied() throws Exception { public void testWithNonApplicationEventClassSupplied() throws Exception {
EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
interceptor.setApplicationEventPublisher(publisher); interceptor.setApplicationEventPublisher(this.publisher);
interceptor.setApplicationEventClass(getClass()); interceptor.setApplicationEventClass(getClass());
interceptor.afterPropertiesSet(); interceptor.afterPropertiesSet();
} }
@ -67,7 +67,7 @@ public class EventPublicationInterceptorTests {
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)
public void testWithAbstractStraightApplicationEventClassSupplied() throws Exception { public void testWithAbstractStraightApplicationEventClassSupplied() throws Exception {
EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
interceptor.setApplicationEventPublisher(publisher); interceptor.setApplicationEventPublisher(this.publisher);
interceptor.setApplicationEventClass(ApplicationEvent.class); interceptor.setApplicationEventClass(ApplicationEvent.class);
interceptor.afterPropertiesSet(); interceptor.afterPropertiesSet();
} }
@ -75,7 +75,7 @@ public class EventPublicationInterceptorTests {
@Test(expected=IllegalArgumentException.class) @Test(expected=IllegalArgumentException.class)
public void testWithApplicationEventClassThatDoesntExposeAValidCtor() throws Exception { public void testWithApplicationEventClassThatDoesntExposeAValidCtor() throws Exception {
EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); EventPublicationInterceptor interceptor = new EventPublicationInterceptor();
interceptor.setApplicationEventPublisher(publisher); interceptor.setApplicationEventPublisher(this.publisher);
interceptor.setApplicationEventClass(TestEventWithNoValidOneArgObjectCtor.class); interceptor.setApplicationEventClass(TestEventWithNoValidOneArgObjectCtor.class);
interceptor.afterPropertiesSet(); interceptor.afterPropertiesSet();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ public abstract class AbstractIdentifiable implements Identifiable {
@Override @Override
public String getId() { public String getId() {
return id; return this.id;
} }
@Override @Override
@ -41,12 +41,12 @@ public abstract class AbstractIdentifiable implements Identifiable {
AbstractIdentifiable that = (AbstractIdentifiable) o; AbstractIdentifiable that = (AbstractIdentifiable) o;
return id.equals(that.id); return this.id.equals(that.id);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return id.hashCode(); return this.id.hashCode();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -56,7 +56,7 @@ public class EventCollector {
* Assert that the listener identified by the specified id has not received any event. * Assert that the listener identified by the specified id has not received any event.
*/ */
public void assertNoEventReceived(String listenerId) { public void assertNoEventReceived(String listenerId) {
List<Object> events = content.getOrDefault(listenerId, Collections.emptyList()); List<Object> events = this.content.getOrDefault(listenerId, Collections.emptyList());
assertEquals("Expected no events but got " + events, 0, events.size()); assertEquals("Expected no events but got " + events, 0, events.size());
} }
@ -72,7 +72,7 @@ public class EventCollector {
* specified events, in that specific order. * specified events, in that specific order.
*/ */
public void assertEvent(String listenerId, Object... events) { public void assertEvent(String listenerId, Object... events) {
List<Object> actual = content.getOrDefault(listenerId, Collections.emptyList()); List<Object> actual = this.content.getOrDefault(listenerId, Collections.emptyList());
assertEquals("wrong number of events", events.length, actual.size()); assertEquals("wrong number of events", events.length, actual.size());
for (int i = 0; i < events.length; i++) { for (int i = 0; i < events.length; i++) {
assertEquals("Wrong event at index " + i, events[i], actual.get(i)); assertEquals("Wrong event at index " + i, events[i], actual.get(i));

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ public abstract class IdentifiableApplicationEvent extends ApplicationEvent impl
@Override @Override
public String getId() { public String getId() {
return id; return this.id;
} }
@Override @Override
@ -55,13 +55,13 @@ public abstract class IdentifiableApplicationEvent extends ApplicationEvent impl
IdentifiableApplicationEvent that = (IdentifiableApplicationEvent) o; IdentifiableApplicationEvent that = (IdentifiableApplicationEvent) o;
return id.equals(that.id); return this.id.equals(that.id);
} }
@Override @Override
public int hashCode() { public int hashCode() {
return id.hashCode(); return this.id.hashCode();
} }
} }