moving unit tests from .testsuite -> .context
This commit is contained in:
parent
95950d28de
commit
69d80518f3
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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.setApplicationEventPublisher(publisher);
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
|
||||
@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.setApplicationEventPublisher(publisher);
|
||||
interceptor.setApplicationEventClass(getClass());
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
|
||||
@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.setApplicationEventPublisher(publisher);
|
||||
interceptor.setApplicationEventClass(ApplicationEvent.class);
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
|
||||
@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.setApplicationEventPublisher(publisher);
|
||||
interceptor.setApplicationEventClass(TestEventWithNoValidOneArgObjectCtor.class);
|
||||
interceptor.afterPropertiesSet();
|
||||
}
|
||||
}.runTest();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExpectedBehavior() throws Exception {
|
||||
TestBean target = new TestBean();
|
||||
final TestListener listener = new TestListener();
|
||||
Loading…
Reference in New Issue