From 69d80518f3d34a272d75bd52a6259c54e0b8adb4 Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Sun, 14 Dec 2008 18:40:53 +0000 Subject: [PATCH] moving unit tests from .testsuite -> .context --- .../springframework/context/TestListener.java | 41 ++++++++++ .../AnnotationProcessorPerformanceTests.java | 0 .../EventPublicationInterceptorTests.java | 80 ++++++++++--------- 3 files changed, 82 insertions(+), 39 deletions(-) create mode 100644 org.springframework.context/src/test/java/org/springframework/context/TestListener.java rename {org.springframework.testsuite => org.springframework.context}/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java (100%) rename {org.springframework.testsuite => org.springframework.context}/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java (66%) diff --git a/org.springframework.context/src/test/java/org/springframework/context/TestListener.java b/org.springframework.context/src/test/java/org/springframework/context/TestListener.java new file mode 100644 index 00000000000..b9f57f73087 --- /dev/null +++ b/org.springframework.context/src/test/java/org/springframework/context/TestListener.java @@ -0,0 +1,41 @@ +/* + * Copyright 2002-2007 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.context; + +/** + * Listener that maintains a global count of events. + * + * @author Rod Johnson + * @since January 21, 2001 + */ +public class TestListener implements ApplicationListener { + + private int eventCount; + + public int getEventCount() { + return eventCount; + } + + public void zeroCounter() { + eventCount = 0; + } + + public void onApplicationEvent(ApplicationEvent e) { + ++eventCount; + } + +} diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java b/org.springframework.context/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java similarity index 100% rename from org.springframework.testsuite/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java rename to org.springframework.context/src/test/java/org/springframework/context/annotation/AnnotationProcessorPerformanceTests.java diff --git a/org.springframework.testsuite/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java b/org.springframework.context/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java similarity index 66% rename from org.springframework.testsuite/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java rename to org.springframework.context/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java index 8f4f919073a..5ab570373c6 100644 --- a/org.springframework.testsuite/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java +++ b/org.springframework.context/src/test/java/org/springframework/context/event/EventPublicationInterceptorTests.java @@ -16,74 +16,76 @@ package org.springframework.context.event; -import junit.framework.TestCase; +import static org.easymock.EasyMock.*; +import static org.junit.Assert.assertTrue; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.BeansException; import org.springframework.beans.ITestBean; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.TestBean; import org.springframework.beans.factory.FactoryBean; -import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.TestListener; import org.springframework.context.support.StaticApplicationContext; -import org.springframework.test.AssertThrows; /** * @author Dmitriy Kopylenko * @author Juergen Hoeller * @author Rick Evans */ -public class EventPublicationInterceptorTests extends TestCase { +public class EventPublicationInterceptorTests { + + private ApplicationEventPublisher publisher; + + @Before + public void setUp() { + publisher = createMock(ApplicationEventPublisher.class); + replay(publisher); + } + + @After + public void tearDown() { + verify(publisher); + } + + @Test(expected=IllegalArgumentException.class) public void testWithNoApplicationEventClassSupplied() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); - ApplicationContext ctx = new StaticApplicationContext(); - interceptor.setApplicationEventPublisher(ctx); - interceptor.afterPropertiesSet(); - } - }.runTest(); + EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); + interceptor.setApplicationEventPublisher(publisher); + interceptor.afterPropertiesSet(); } + @Test(expected=IllegalArgumentException.class) public void testWithNonApplicationEventClassSupplied() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); - ApplicationContext ctx = new StaticApplicationContext(); - interceptor.setApplicationEventPublisher(ctx); - interceptor.setApplicationEventClass(getClass()); - interceptor.afterPropertiesSet(); - } - }.runTest(); + EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); + interceptor.setApplicationEventPublisher(publisher); + interceptor.setApplicationEventClass(getClass()); + interceptor.afterPropertiesSet(); } + @Test(expected=IllegalArgumentException.class) public void testWithAbstractStraightApplicationEventClassSupplied() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); - ApplicationContext ctx = new StaticApplicationContext(); - interceptor.setApplicationEventPublisher(ctx); - interceptor.setApplicationEventClass(ApplicationEvent.class); - interceptor.afterPropertiesSet(); - } - }.runTest(); + EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); + interceptor.setApplicationEventPublisher(publisher); + interceptor.setApplicationEventClass(ApplicationEvent.class); + interceptor.afterPropertiesSet(); } + @Test(expected=IllegalArgumentException.class) public void testWithApplicationEventClassThatDoesntExposeAValidCtor() throws Exception { - new AssertThrows(IllegalArgumentException.class) { - public void test() throws Exception { - EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); - ApplicationContext ctx = new StaticApplicationContext(); - interceptor.setApplicationEventPublisher(ctx); - interceptor.setApplicationEventClass(TestEventWithNoValidOneArgObjectCtor.class); - interceptor.afterPropertiesSet(); - } - }.runTest(); + EventPublicationInterceptor interceptor = new EventPublicationInterceptor(); + interceptor.setApplicationEventPublisher(publisher); + interceptor.setApplicationEventClass(TestEventWithNoValidOneArgObjectCtor.class); + interceptor.afterPropertiesSet(); } + @Test public void testExpectedBehavior() throws Exception { TestBean target = new TestBean(); final TestListener listener = new TestListener();