Migrate JUnit 3 tests to JUnit 4

This commit migrates all remaining tests from JUnit 3 to JUnit 4, with
the exception of Spring's legacy JUnit 3.8 based testing framework that
is still in use in the spring-orm module.

Issue: SPR-13514
This commit is contained in:
Sam Brannen
2015-09-26 00:10:58 +02:00
parent 1580288815
commit d5ee787e1e
213 changed files with 4879 additions and 3939 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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.
@@ -21,7 +21,6 @@ import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -36,25 +35,29 @@ import static org.junit.Assert.*;
* @author Juergen Hoeller
* @author Chris Beams
*/
@SuppressWarnings("resource")
public final class PropertyDependentAspectTests {
@Test
public void testPropertyDependentAspectWithPropertyDeclaredBeforeAdvice() throws Exception {
public void propertyDependentAspectWithPropertyDeclaredBeforeAdvice()
throws Exception {
checkXmlAspect(getClass().getSimpleName() + "-before.xml");
}
@Test
public void testPropertyDependentAspectWithPropertyDeclaredAfterAdvice() throws Exception {
public void propertyDependentAspectWithPropertyDeclaredAfterAdvice() throws Exception {
checkXmlAspect(getClass().getSimpleName() + "-after.xml");
}
@Test
public void testPropertyDependentAtAspectJAspectWithPropertyDeclaredBeforeAdvice() throws Exception {
public void propertyDependentAtAspectJAspectWithPropertyDeclaredBeforeAdvice()
throws Exception {
checkAtAspectJAspect(getClass().getSimpleName() + "-atAspectJ-before.xml");
}
@Test
public void testPropertyDependentAtAspectJAspectWithPropertyDeclaredAfterAdvice() throws Exception {
public void propertyDependentAtAspectJAspectWithPropertyDeclaredAfterAdvice()
throws Exception {
checkAtAspectJAspect(getClass().getSimpleName() + "-atAspectJ-after.xml");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -18,6 +18,7 @@ package org.springframework.aop.aspectj;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Before;
import org.junit.Test;
@@ -27,7 +28,7 @@ import static org.junit.Assert.*;
/**
* Tests for target selection matching (see SPR-3783).
* Thanks to Tomasz Blachowicz for the bug report!
* <p>Thanks to Tomasz Blachowicz for the bug report!
*
* @author Ramnivas Laddad
* @author Chris Beams
@@ -46,6 +47,7 @@ public final class TargetPointcutSelectionTests {
@Before
@SuppressWarnings("resource")
public void setUp() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
@@ -63,7 +65,7 @@ public final class TargetPointcutSelectionTests {
@Test
public void testTargetSelectionForMatchedType() {
public void targetSelectionForMatchedType() {
testImpl1.interfaceMethod();
assertEquals("Should have been advised by POJO advice for impl", 1, testAspectForTestImpl1.count);
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count);
@@ -71,7 +73,7 @@ public final class TargetPointcutSelectionTests {
}
@Test
public void testTargetNonSelectionForMismatchedType() {
public void targetNonSelectionForMismatchedType() {
testImpl2.interfaceMethod();
assertEquals("Shouldn't have been advised by POJO advice for impl", 0, testAspectForTestImpl1.count);
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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.
@@ -22,7 +22,6 @@ import java.lang.annotation.RetentionPolicy;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.*;
@@ -32,13 +31,17 @@ import static org.junit.Assert.*;
* @author Chris Beams
*/
public final class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
public TestInterface testBean;
public TestInterface testAnnotatedClassBean;
public TestInterface testAnnotatedMethodBean;
protected Counter counter;
private TestInterface testBean;
private TestInterface testAnnotatedClassBean;
private TestInterface testAnnotatedMethodBean;
private Counter counter;
@org.junit.Before
@SuppressWarnings("resource")
public void setUp() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
@@ -50,56 +53,56 @@ public final class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
}
@Test
public void testThisAsClassDoesNotMatch() {
public void thisAsClassDoesNotMatch() {
testBean.doIt();
assertEquals(0, counter.thisAsClassCounter);
}
@Test
public void testThisAsInterfaceMatch() {
public void thisAsInterfaceMatch() {
testBean.doIt();
assertEquals(1, counter.thisAsInterfaceCounter);
}
@Test
public void testTargetAsClassDoesMatch() {
public void targetAsClassDoesMatch() {
testBean.doIt();
assertEquals(1, counter.targetAsClassCounter);
}
@Test
public void testTargetAsInterfaceMatch() {
public void targetAsInterfaceMatch() {
testBean.doIt();
assertEquals(1, counter.targetAsInterfaceCounter);
}
@Test
public void testThisAsClassAndTargetAsClassCounterNotMatch() {
public void thisAsClassAndTargetAsClassCounterNotMatch() {
testBean.doIt();
assertEquals(0, counter.thisAsClassAndTargetAsClassCounter);
}
@Test
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() {
public void thisAsInterfaceAndTargetAsInterfaceCounterMatch() {
testBean.doIt();
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
}
@Test
public void testThisAsInterfaceAndTargetAsClassCounterMatch() {
public void thisAsInterfaceAndTargetAsClassCounterMatch() {
testBean.doIt();
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
}
@Test
public void testAtTargetClassAnnotationMatch() {
public void atTargetClassAnnotationMatch() {
testAnnotatedClassBean.doIt();
assertEquals(1, counter.atTargetClassAnnotationCounter);
}
@Test
public void testAtAnnotationMethodAnnotationMatch() {
public void atAnnotationMethodAnnotationMatch() {
testAnnotatedMethodBean.doIt();
assertEquals(1, counter.atAnnotationMethodAnnotationCounter);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -22,16 +22,19 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Locale;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.AbstractListableBeanFactoryTests;
import org.springframework.tests.sample.beans.LifecycleBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
/**
* @author Rod Johnson
* @author Juergen Hoeller
* @author Sam Brannen
*/
public abstract class AbstractApplicationContextTests extends AbstractListableBeanFactoryTests {
@@ -45,8 +48,8 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
protected TestListener parentListener = new TestListener();
@Override
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
this.applicationContext = createContext();
}
@@ -67,7 +70,8 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
*/
protected abstract ConfigurableApplicationContext createContext() throws Exception;
public void testContextAwareSingletonWasCalledBack() throws Exception {
@Test
public void contextAwareSingletonWasCalledBack() throws Exception {
ACATester aca = (ACATester) applicationContext.getBean("aca");
assertTrue("has had context set", aca.getApplicationContext() == applicationContext);
Object aca2 = applicationContext.getBean("aca");
@@ -75,7 +79,8 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
assertTrue("Says is singleton", applicationContext.isSingleton("aca"));
}
public void testContextAwarePrototypeWasCalledBack() throws Exception {
@Test
public void contextAwarePrototypeWasCalledBack() throws Exception {
ACATester aca = (ACATester) applicationContext.getBean("aca-prototype");
assertTrue("has had context set", aca.getApplicationContext() == applicationContext);
Object aca2 = applicationContext.getBean("aca-prototype");
@@ -83,30 +88,36 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
assertTrue("Says is prototype", !applicationContext.isSingleton("aca-prototype"));
}
public void testParentNonNull() {
@Test
public void parentNonNull() {
assertTrue("parent isn't null", applicationContext.getParent() != null);
}
public void testGrandparentNull() {
@Test
public void grandparentNull() {
assertTrue("grandparent is null", applicationContext.getParent().getParent() == null);
}
public void testOverrideWorked() throws Exception {
@Test
public void overrideWorked() throws Exception {
TestBean rod = (TestBean) applicationContext.getParent().getBean("rod");
assertTrue("Parent's name differs", rod.getName().equals("Roderick"));
}
public void testGrandparentDefinitionFound() throws Exception {
@Test
public void grandparentDefinitionFound() throws Exception {
TestBean dad = (TestBean) applicationContext.getBean("father");
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
}
public void testGrandparentTypedDefinitionFound() throws Exception {
@Test
public void grandparentTypedDefinitionFound() throws Exception {
TestBean dad = applicationContext.getBean("father", TestBean.class);
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
}
public void testCloseTriggersDestroy() {
@Test
public void closeTriggersDestroy() {
LifecycleBean lb = (LifecycleBean) applicationContext.getBean("lifecycle");
assertTrue("Not destroyed", !lb.isDestroyed());
applicationContext.close();
@@ -121,25 +132,21 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
assertTrue("Destroyed", lb.isDestroyed());
}
public void testMessageSource() throws NoSuchMessageException {
@Test(expected = NoSuchMessageException.class)
public void messageSource() throws NoSuchMessageException {
assertEquals("message1", applicationContext.getMessage("code1", null, Locale.getDefault()));
assertEquals("message2", applicationContext.getMessage("code2", null, Locale.getDefault()));
try {
applicationContext.getMessage("code0", null, Locale.getDefault());
fail("looking for code0 should throw a NoSuchMessageException");
}
catch (NoSuchMessageException ex) {
// that's how it should be
}
applicationContext.getMessage("code0", null, Locale.getDefault());
}
public void testEvents() throws Exception {
@Test
public void events() throws Exception {
doTestEvents(this.listener, this.parentListener, new MyEvent(this));
}
@Test
public void testEventsWithNoSource() throws Exception {
public void eventsWithNoSource() throws Exception {
// See SPR-10945 Serialized events result in a null source
MyEvent event = new MyEvent(this);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -162,7 +169,8 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
assertTrue("1 parent events after publication", parentListener.getEventCount() == 1);
}
public void testBeanAutomaticallyHearsEvents() throws Exception {
@Test
public void beanAutomaticallyHearsEvents() throws Exception {
//String[] listenerNames = ((ListableBeanFactory) applicationContext).getBeanDefinitionNames(ApplicationListener.class);
//assertTrue("listeners include beanThatListens", Arrays.asList(listenerNames).contains("beanThatListens"));
BeanThatListens b = (BeanThatListens) applicationContext.getBean("beanThatListens");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -20,7 +20,7 @@ import java.util.Collection;
import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
@@ -28,11 +28,13 @@ import org.springframework.beans.factory.access.BootstrapException;
import org.springframework.context.ApplicationContext;
import org.springframework.tests.mock.jndi.SimpleNamingContextBuilder;
import static org.junit.Assert.*;
/**
* @author Colin Sampaleanu
* @author Chris Beams
*/
public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
public final class ContextJndiBeanFactoryLocatorTests {
private static final String BEAN_FACTORY_PATH_ENVIRONMENT_KEY = "java:comp/env/ejb/BeanFactoryPath";
@@ -45,7 +47,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
private static final String PARENT_CONTEXT = FQ_PATH + CLASSNAME + "-parent.xml";
public void testBeanFactoryPathRequiredFromJndiEnvironment() throws Exception {
@Test
public void beanFactoryPathRequiredFromJndiEnvironment() throws Exception {
// Set up initial context but don't bind anything
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
@@ -60,7 +63,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
}
}
public void testBeanFactoryPathFromJndiEnvironmentNotFound() throws Exception {
@Test
public void beanFactoryPathFromJndiEnvironmentNotFound() throws Exception {
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
String bogusPath = "RUBBISH/com/xxxx/framework/server/test1.xml";
@@ -79,7 +83,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
}
}
public void testBeanFactoryPathFromJndiEnvironmentNotValidXml() throws Exception {
@Test
public void beanFactoryPathFromJndiEnvironmentNotValidXml() throws Exception {
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
String nonXmlPath = "com/xxxx/framework/server/SlsbEndpointBean.class";
@@ -98,7 +103,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
}
}
public void testBeanFactoryPathFromJndiEnvironmentWithSingleFile() throws Exception {
@Test
public void beanFactoryPathFromJndiEnvironmentWithSingleFile() throws Exception {
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
// Set up initial context
@@ -110,7 +116,8 @@ public final class ContextJndiBeanFactoryLocatorTests extends TestCase {
assertTrue(bf instanceof ApplicationContext);
}
public void testBeanFactoryPathFromJndiEnvironmentWithMultipleFiles() throws Exception {
@Test
public void beanFactoryPathFromJndiEnvironmentWithMultipleFiles() throws Exception {
SimpleNamingContextBuilder sncb = SimpleNamingContextBuilder.emptyActivatedContextBuilder();
String path = String.format("%s %s", COLLECTIONS_CONTEXT, PARENT_CONTEXT);

View File

@@ -16,19 +16,22 @@
package org.springframework.context.access;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
import org.springframework.beans.factory.access.BeanFactoryLocator;
/**
* @author Colin Sampaleanu
*/
public class DefaultLocatorFactoryTests extends TestCase {
public class DefaultLocatorFactoryTests {
/*
* Class to test for BeanFactoryLocator getInstance()
*/
public void testGetInstance() {
@Test
public void getInstance() {
BeanFactoryLocator bf = DefaultLocatorFactory.getInstance();
BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance();
assertTrue(bf.equals(bf2));
@@ -37,7 +40,8 @@ public class DefaultLocatorFactoryTests extends TestCase {
/*
* Class to test for BeanFactoryLocator getInstance(String)
*/
public void testGetInstanceString() {
@Test
public void getInstanceString() {
BeanFactoryLocator bf = DefaultLocatorFactory.getInstance("my-bean-refs.xml");
BeanFactoryLocator bf2 = DefaultLocatorFactory.getInstance("my-bean-refs.xml");
assertTrue(bf.equals(bf2));

View File

@@ -27,7 +27,6 @@ import org.hamcrest.Matcher;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.InOrder;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
@@ -35,7 +34,6 @@ import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.EnvironmentAware;
import org.springframework.context.MessageSource;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrarTests.SampleRegistrar;
import org.springframework.core.Ordered;
@@ -53,6 +51,7 @@ import static org.mockito.Mockito.*;
*
* @author Phillip Webb
*/
@SuppressWarnings("resource")
public class ImportSelectorTests {
static Map<Class<?>, String> importFrom = new HashMap<Class<?>, String>();
@@ -81,7 +80,6 @@ public class ImportSelectorTests {
@Test
public void invokeAwareMethodsInImportSelector() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AwareConfig.class);
context.getBean(MessageSource.class);
assertThat(SampleRegistrar.beanFactory, is((BeanFactory) context.getBeanFactory()));
assertThat(SampleRegistrar.classLoader, is(context.getBeanFactory().getBeanClassLoader()));
assertThat(SampleRegistrar.resourceLoader, is(notNullValue()));
@@ -90,7 +88,7 @@ public class ImportSelectorTests {
@Test
public void correctMetaDataOnIndirectImports() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(IndirectConfig.class);
new AnnotationConfigApplicationContext(IndirectConfig.class);
Matcher<String> isFromIndirect = equalTo(IndirectImport.class.getName());
assertThat(importFrom.get(ImportSelector1.class), isFromIndirect);
assertThat(importFrom.get(ImportSelector2.class), isFromIndirect);

View File

@@ -50,7 +50,7 @@ import static org.junit.Assert.*;
public class ImportResourceTests {
@Test
public void testImportXml() {
public void importXml() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlConfig.class);
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
@@ -61,7 +61,7 @@ public class ImportResourceTests {
@Ignore // TODO: SPR-6310
@Test
public void testImportXmlWithRelativePath() {
public void importXmlWithRelativePath() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithRelativePathConfig.class);
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
@@ -72,7 +72,7 @@ public class ImportResourceTests {
@Ignore // TODO: SPR-6310
@Test
public void testImportXmlByConvention() {
public void importXmlByConvention() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(
ImportXmlByConventionConfig.class);
assertTrue("context does not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
@@ -80,14 +80,14 @@ public class ImportResourceTests {
}
@Test
public void testImportXmlIsInheritedFromSuperclassDeclarations() {
public void importXmlIsInheritedFromSuperclassDeclarations() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(FirstLevelSubConfig.class);
assertTrue(ctx.containsBean("xmlDeclaredBean"));
ctx.close();
}
@Test
public void testImportXmlIsMergedFromSuperclassDeclarations() {
public void importXmlIsMergedFromSuperclassDeclarations() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SecondLevelSubConfig.class);
assertTrue("failed to pick up second-level-declared XML bean", ctx.containsBean("secondLevelXmlDeclaredBean"));
assertTrue("failed to pick up parent-declared XML bean", ctx.containsBean("xmlDeclaredBean"));
@@ -95,7 +95,7 @@ public class ImportResourceTests {
}
@Test
public void testImportXmlWithNamespaceConfig() {
public void importXmlWithNamespaceConfig() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithAopNamespaceConfig.class);
Object bean = ctx.getBean("proxiedXmlBean");
assertTrue(AopUtils.isAopProxy(bean));
@@ -103,7 +103,7 @@ public class ImportResourceTests {
}
@Test
public void testImportXmlWithOtherConfigurationClass() {
public void importXmlWithOtherConfigurationClass() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlWithConfigurationClass.class);
assertTrue("did not contain java-declared bean", ctx.containsBean("javaDeclaredBean"));
assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean"));
@@ -114,7 +114,7 @@ public class ImportResourceTests {
@Ignore // TODO: SPR-6327
@Test
public void testImportDifferentResourceTypes() {
public void importDifferentResourceTypes() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(SubResourceConfig.class);
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
assertTrue(ctx.containsBean("xmlDeclaredBean"));
@@ -134,7 +134,7 @@ public class ImportResourceTests {
}
@Test
public void testImportXmlWithAutowiredConfig() {
public void importXmlWithAutowiredConfig() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class);
String name = ctx.getBean("xmlBeanName", String.class);
assertThat(name, equalTo("xml.declared"));
@@ -142,7 +142,7 @@ public class ImportResourceTests {
}
@Test
public void testImportNonXmlResource() {
public void importNonXmlResource() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportNonXmlResourceConfig.class);
assertTrue(ctx.containsBean("propertiesDeclaredBean"));
ctx.close();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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,7 +16,7 @@
package org.springframework.context.event;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
@@ -24,13 +24,16 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.Lifecycle;
import org.springframework.context.support.StaticApplicationContext;
import static org.junit.Assert.*;
/**
* @author Mark Fisher
* @author Juergen Hoeller
*/
public class LifecycleEventTests extends TestCase {
public class LifecycleEventTests {
public void testContextStartedEvent() {
@Test
public void contextStartedEvent() {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton("lifecycle", LifecycleTestBean.class);
context.registerSingleton("listener", LifecycleListener.class);
@@ -45,7 +48,8 @@ public class LifecycleEventTests extends TestCase {
assertSame(context, listener.getApplicationContext());
}
public void testContextStoppedEvent() {
@Test
public void contextStoppedEvent() {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton("lifecycle", LifecycleTestBean.class);
context.registerSingleton("listener", LifecycleListener.class);

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2002-2015 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.support;
import java.lang.reflect.Field;
@@ -5,6 +21,7 @@ import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;

View File

@@ -20,6 +20,8 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.junit.Test;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.context.ACATester;
@@ -34,6 +36,8 @@ import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
/**
* Tests for static application context with custom application event multicaster.
*
@@ -43,7 +47,6 @@ public class StaticApplicationContextMulticasterTests extends AbstractApplicatio
protected StaticApplicationContext sac;
/** Run for each test */
@Override
protected ConfigurableApplicationContext createContext() throws Exception {
StaticApplicationContext parent = new StaticApplicationContext();
@@ -74,16 +77,17 @@ public class StaticApplicationContextMulticasterTests extends AbstractApplicatio
return sac;
}
/** Overridden */
@Test
@Override
public void testCount() {
public void count() {
assertCount(15);
}
@Test
@Override
public void testEvents() throws Exception {
public void events() throws Exception {
TestApplicationEventMulticaster.counter = 0;
super.testEvents();
super.events();
assertEquals(1, TestApplicationEventMulticaster.counter);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -20,6 +20,8 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.junit.Test;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.context.ACATester;
@@ -38,7 +40,6 @@ public class StaticApplicationContextTests extends AbstractApplicationContextTes
protected StaticApplicationContext sac;
/** Run for each test */
@Override
protected ConfigurableApplicationContext createContext() throws Exception {
StaticApplicationContext parent = new StaticApplicationContext();
@@ -66,9 +67,9 @@ public class StaticApplicationContextTests extends AbstractApplicationContextTes
return sac;
}
/** Overridden */
@Test
@Override
public void testCount() {
public void count() {
assertCount(15);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -21,6 +21,10 @@ import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.support.PropertiesBeanDefinitionReader;
import org.springframework.context.ACATester;
@@ -31,9 +35,12 @@ import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.core.io.ClassPathResource;
import static org.junit.Assert.*;
/**
* @author Rod Johnson
* @author Juergen Hoeller
* @author Sam Brannen
*/
public class StaticMessageSourceTests extends AbstractApplicationContextTests {
@@ -48,27 +55,34 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
protected StaticApplicationContext sac;
/** Overridden */
@Rule
public final ExpectedException exception = ExpectedException.none();
@Test
@Override
public void testCount() {
public void count() {
// These are only checked for current Ctx (not parent ctx)
assertCount(15);
}
@Test
@Override
public void testMessageSource() throws NoSuchMessageException {
public void messageSource() throws NoSuchMessageException {
// Do nothing here since super is looking for errorCodes we
// do NOT have in the Context
}
public void testGetMessageWithDefaultPassedInAndFoundInMsgCatalog() {
@Test
public void getMessageWithDefaultPassedInAndFoundInMsgCatalog() {
// Try with Locale.US
assertTrue("valid msg from staticMsgSource with default msg passed in returned msg from msg catalog for Locale.US",
sac.getMessage("message.format.example2", null, "This is a default msg if not found in MessageSource.", Locale.US)
.equals("This is a test message in the message catalog with no args."));
}
public void testGetMessageWithDefaultPassedInAndNotFoundInMsgCatalog() {
@Test
public void getMessageWithDefaultPassedInAndNotFoundInMsgCatalog() {
// Try with Locale.US
assertTrue("bogus msg from staticMsgSource with default msg passed in returned default msg for Locale.US",
sac.getMessage("bogus.message", null, "This is a default msg if not found in MessageSource.", Locale.US)
@@ -82,7 +96,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
* make sure the cache is being used properly.
* @see org.springframework.context.support.AbstractMessageSource for more details.
*/
public void testGetMessageWithMessageAlreadyLookedFor() {
@Test
public void getMessageWithMessageAlreadyLookedFor() {
Object[] arguments = {
new Integer(7), new Date(System.currentTimeMillis()),
"a disturbance in the Force"
@@ -111,7 +126,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
/**
* Example taken from the javadocs for the java.text.MessageFormat class
*/
public void testGetMessageWithNoDefaultPassedInAndFoundInMsgCatalog() {
@Test
public void getMessageWithNoDefaultPassedInAndFoundInMsgCatalog() {
Object[] arguments = {
new Integer(7), new Date(System.currentTimeMillis()),
"a disturbance in the Force"
@@ -140,63 +156,37 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
.equals("This is a test message in the message catalog with no args."));
}
public void testGetMessageWithNoDefaultPassedInAndNotFoundInMsgCatalog() {
// Expecting an exception
try {
// Try with Locale.US
sac.getMessage("bogus.message", null, Locale.US);
fail("bogus msg from staticMsgSource for Locale.US without default msg should have thrown exception");
}
catch (NoSuchMessageException tExcept) {
assertTrue("bogus msg from staticMsgSource for Locale.US without default msg threw expected exception", true);
}
@Test(expected = NoSuchMessageException.class)
public void getMessageWithNoDefaultPassedInAndNotFoundInMsgCatalog() {
// Try with Locale.US
sac.getMessage("bogus.message", null, Locale.US);
}
public void testMessageSourceResolvable() {
@Test
public void messageSourceResolvable() {
// first code valid
String[] codes1 = new String[] {"message.format.example3", "message.format.example2"};
MessageSourceResolvable resolvable1 = new DefaultMessageSourceResolvable(codes1, null, "default");
try {
assertTrue("correct message retrieved", MSG_TXT3_US.equals(sac.getMessage(resolvable1, Locale.US)));
}
catch (NoSuchMessageException ex) {
fail("Should not throw NoSuchMessageException");
}
assertTrue("correct message retrieved", MSG_TXT3_US.equals(sac.getMessage(resolvable1, Locale.US)));
// only second code valid
String[] codes2 = new String[] {"message.format.example99", "message.format.example2"};
MessageSourceResolvable resolvable2 = new DefaultMessageSourceResolvable(codes2, null, "default");
try {
assertTrue("correct message retrieved", MSG_TXT2_US.equals(sac.getMessage(resolvable2, Locale.US)));
}
catch (NoSuchMessageException ex) {
fail("Should not throw NoSuchMessageException");
}
assertTrue("correct message retrieved", MSG_TXT2_US.equals(sac.getMessage(resolvable2, Locale.US)));
// no code valid, but default given
String[] codes3 = new String[] {"message.format.example99", "message.format.example98"};
MessageSourceResolvable resolvable3 = new DefaultMessageSourceResolvable(codes3, null, "default");
try {
assertTrue("correct message retrieved", "default".equals(sac.getMessage(resolvable3, Locale.US)));
}
catch (NoSuchMessageException ex) {
fail("Should not throw NoSuchMessageException");
}
assertTrue("correct message retrieved", "default".equals(sac.getMessage(resolvable3, Locale.US)));
// no code valid, no default
String[] codes4 = new String[] {"message.format.example99", "message.format.example98"};
MessageSourceResolvable resolvable4 = new DefaultMessageSourceResolvable(codes4);
try {
sac.getMessage(resolvable4, Locale.US);
fail("Should have thrown NoSuchMessageException");
}
catch (NoSuchMessageException ex) {
// expected
}
exception.expect(NoSuchMessageException.class);
sac.getMessage(resolvable4, Locale.US);
}
/** Run for each test */
@Override
protected ConfigurableApplicationContext createContext() throws Exception {
StaticApplicationContext parent = new StaticApplicationContext();
@@ -234,7 +224,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
return sac;
}
public void testNestedMessageSourceWithParamInChild() {
@Test
public void nestedMessageSourceWithParamInChild() {
StaticMessageSource source = new StaticMessageSource();
StaticMessageSource parent = new StaticMessageSource();
source.setParentMessageSource(parent);
@@ -248,7 +239,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
assertEquals("put value here", source.getMessage(resolvable, Locale.ENGLISH));
}
public void testNestedMessageSourceWithParamInParent() {
@Test
public void nestedMessageSourceWithParamInParent() {
StaticMessageSource source = new StaticMessageSource();
StaticMessageSource parent = new StaticMessageSource();
source.setParentMessageSource(parent);

View File

@@ -26,6 +26,8 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
import org.junit.After;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import org.springframework.util.SocketUtils;
@@ -78,6 +80,7 @@ public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTes
return this.connector.getMBeanServerConnection();
}
@After
@Override
public void tearDown() throws Exception {
if (this.connector != null) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2015 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
@@ -19,24 +19,22 @@ package org.springframework.jmx.export;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jmx.support.ObjectNameManager;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Juergen Hoeller
*/
public class LazyInitMBeanTests extends TestCase {
public class LazyInitMBeanTests {
public void testLazyInit() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getApplicationContextPath());
ctx.close();
}
public void testInvokeOnLazyInitBean() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(getApplicationContextPath());
@Test
public void invokeOnLazyInitBean() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("org/springframework/jmx/export/lazyInit.xml");
assertFalse(ctx.getBeanFactory().containsSingleton("testBean"));
assertFalse(ctx.getBeanFactory().containsSingleton("testBean2"));
try {
@@ -50,8 +48,4 @@ public class LazyInitMBeanTests extends TestCase {
}
}
private String getApplicationContextPath() {
return "org/springframework/jmx/export/lazyInit.xml";
}
}

View File

@@ -16,10 +16,12 @@
package org.springframework.jmx.export.annotation;
import org.junit.Test;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -29,9 +31,10 @@ import org.springframework.jmx.support.ObjectNameManager;
* @author Rob Harrop
* @author Juergen Hoeller
*/
public class AnnotationLazyInitMBeanTests extends TestCase {
public class AnnotationLazyInitMBeanTests {
public void testLazyNaming() throws Exception {
@Test
public void lazyNaming() throws Exception {
ConfigurableApplicationContext ctx =
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyNaming.xml");
try {
@@ -46,7 +49,8 @@ public class AnnotationLazyInitMBeanTests extends TestCase {
}
}
public void testLazyAssembling() throws Exception {
@Test
public void lazyAssembling() throws Exception {
System.setProperty("domain", "bean");
ConfigurableApplicationContext ctx =
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/lazyAssembling.xml");
@@ -79,7 +83,8 @@ public class AnnotationLazyInitMBeanTests extends TestCase {
}
}
public void testComponentScan() throws Exception {
@Test
public void componentScan() throws Exception {
ConfigurableApplicationContext ctx =
new ClassPathXmlApplicationContext("org/springframework/jmx/export/annotation/componentScan.xml");
try {

View File

@@ -16,16 +16,19 @@
package org.springframework.jmx.export.assembler;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
import org.springframework.jmx.JmxTestBean;
/**
* @author Rob Harrop
*/
public abstract class AbstractAutodetectTests extends TestCase {
public abstract class AbstractAutodetectTests {
public void testAutodetect() throws Exception {
@Test
public void autodetect() throws Exception {
JmxTestBean bean = new JmxTestBean();
AutodetectCapableMBeanInfoAssembler assembler = getAssembler();

View File

@@ -16,16 +16,19 @@
package org.springframework.jmx.export.naming;
import org.junit.Test;
import javax.management.ObjectName;
import junit.framework.TestCase;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
*/
public abstract class AbstractNamingStrategyTests extends TestCase {
public abstract class AbstractNamingStrategyTests {
public void testNaming() throws Exception {
@Test
public void naming() throws Exception {
ObjectNamingStrategy strat = getStrategy();
ObjectName objectName = strat.getObjectName(getManagedResource(), getKey());
assertEquals(objectName.getCanonicalName(), getCorrectObjectName());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2015 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.
@@ -19,18 +19,21 @@ package org.springframework.jmx.export.naming;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.jmx.JmxTestBean;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
*/
public class IdentityNamingStrategyTests extends TestCase {
public class IdentityNamingStrategyTests {
public void testNaming() throws MalformedObjectNameException {
@Test
public void naming() throws MalformedObjectNameException {
JmxTestBean bean = new JmxTestBean();
IdentityNamingStrategy strategy = new IdentityNamingStrategy();
ObjectName objectName = strategy.getObjectName(bean, "null");

View File

@@ -18,6 +18,7 @@ package org.springframework.jmx.support;
import java.io.IOException;
import java.net.MalformedURLException;
import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
@@ -27,6 +28,7 @@ import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;
import org.junit.After;
import org.junit.Test;
import org.springframework.jmx.AbstractMBeanServerTests;
@@ -41,27 +43,25 @@ import static org.junit.Assert.*;
*
* @author Rob Harrop
* @author Chris Beams
* @author Sam Brannen
*/
public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
private static final String OBJECT_NAME = "spring:type=connector,name=test";
private boolean runTests = false;
@Override
protected void onSetUp() throws Exception {
Assume.group(TestGroup.JMXMP);
runTests = true;
}
@After
@Override
public void tearDown() throws Exception {
if (runTests) {
super.tearDown();
}
Assume.group(TestGroup.JMXMP, () -> super.tearDown());
}
@Test
public void testStartupWithLocatedServer() throws Exception {
public void startupWithLocatedServer() throws Exception {
ConnectorServerFactoryBean bean = new ConnectorServerFactoryBean();
bean.afterPropertiesSet();
@@ -73,7 +73,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
}
@Test
public void testStartupWithSuppliedServer() throws Exception {
public void startupWithSuppliedServer() throws Exception {
//Added a brief snooze here - seems to fix occasional
//java.net.BindException: Address already in use errors
Thread.sleep(1);
@@ -90,7 +90,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
}
@Test
public void testRegisterWithMBeanServer() throws Exception {
public void registerWithMBeanServer() throws Exception {
//Added a brief snooze here - seems to fix occasional
//java.net.BindException: Address already in use errors
Thread.sleep(1);
@@ -108,7 +108,7 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
}
@Test
public void testNoRegisterWithMBeanServer() throws Exception {
public void noRegisterWithMBeanServer() throws Exception {
ConnectorServerFactoryBean bean = new ConnectorServerFactoryBean();
bean.afterPropertiesSet();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2015 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
@@ -18,31 +18,39 @@ package org.springframework.jmx.support;
import java.lang.management.ManagementFactory;
import java.util.List;
import javax.management.MBeanServer;
import javax.management.MBeanServerFactory;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.util.MBeanTestUtils;
import static org.junit.Assert.*;
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Phillip Webb
*/
public class MBeanServerFactoryBeanTests extends TestCase {
public class MBeanServerFactoryBeanTests {
@Override
protected void setUp() throws Exception {
@Before
public void setUp() throws Exception {
MBeanTestUtils.resetMBeanServers();
}
@Override
protected void tearDown() throws Exception {
@After
public void tearDown() throws Exception {
MBeanTestUtils.resetMBeanServers();
}
public void testGetObject() throws Exception {
@Test
public void getObject() throws Exception {
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
bean.afterPropertiesSet();
try {
@@ -54,7 +62,8 @@ public class MBeanServerFactoryBeanTests extends TestCase {
}
}
public void testDefaultDomain() throws Exception {
@Test
public void defaultDomain() throws Exception {
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
bean.setDefaultDomain("foo");
bean.afterPropertiesSet();
@@ -67,7 +76,8 @@ public class MBeanServerFactoryBeanTests extends TestCase {
}
}
public void testWithLocateExistingAndExistingServer() {
@Test
public void withLocateExistingAndExistingServer() {
MBeanServer server = MBeanServerFactory.createMBeanServer();
try {
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
@@ -86,7 +96,8 @@ public class MBeanServerFactoryBeanTests extends TestCase {
}
}
public void testWithLocateExistingAndFallbackToPlatformServer() {
@Test
public void withLocateExistingAndFallbackToPlatformServer() {
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
bean.setLocateExistingServerIfPossible(true);
bean.afterPropertiesSet();
@@ -98,7 +109,8 @@ public class MBeanServerFactoryBeanTests extends TestCase {
}
}
public void testWithEmptyAgentIdAndFallbackToPlatformServer() {
@Test
public void withEmptyAgentIdAndFallbackToPlatformServer() {
MBeanServerFactoryBean bean = new MBeanServerFactoryBean();
bean.setAgentId("");
bean.afterPropertiesSet();
@@ -110,11 +122,13 @@ public class MBeanServerFactoryBeanTests extends TestCase {
}
}
public void testCreateMBeanServer() throws Exception {
@Test
public void createMBeanServer() throws Exception {
testCreation(true, "The server should be available in the list");
}
public void testNewMBeanServer() throws Exception {
@Test
public void newMBeanServer() throws Exception {
testCreation(false, "The server should not be available in the list");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@@ -29,21 +29,25 @@ import java.rmi.StubNotFoundException;
import java.rmi.UnknownHostException;
import java.rmi.UnmarshalException;
import junit.framework.TestCase;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.remoting.RemoteAccessException;
import org.springframework.remoting.RemoteConnectFailureException;
import org.springframework.remoting.RemoteProxyFailureException;
import org.springframework.remoting.support.RemoteInvocation;
import static org.junit.Assert.*;
/**
* @author Juergen Hoeller
* @since 16.05.2003
*/
public class RmiSupportTests extends TestCase {
public class RmiSupportTests {
public void testRmiProxyFactoryBean() throws Exception {
@Test
public void rmiProxyFactoryBean() throws Exception {
CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
factory.setServiceInterface(IRemoteBean.class);
factory.setServiceUrl("rmi://localhost:1090/test");
@@ -56,35 +60,43 @@ public class RmiSupportTests extends TestCase {
assertEquals(1, factory.counter);
}
public void testRmiProxyFactoryBeanWithRemoteException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithRemoteException() throws Exception {
doTestRmiProxyFactoryBeanWithException(RemoteException.class);
}
public void testRmiProxyFactoryBeanWithConnectException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithConnectException() throws Exception {
doTestRmiProxyFactoryBeanWithException(ConnectException.class);
}
public void testRmiProxyFactoryBeanWithConnectIOException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithConnectIOException() throws Exception {
doTestRmiProxyFactoryBeanWithException(ConnectIOException.class);
}
public void testRmiProxyFactoryBeanWithUnknownHostException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithUnknownHostException() throws Exception {
doTestRmiProxyFactoryBeanWithException(UnknownHostException.class);
}
public void testRmiProxyFactoryBeanWithNoSuchObjectException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithNoSuchObjectException() throws Exception {
doTestRmiProxyFactoryBeanWithException(NoSuchObjectException.class);
}
public void testRmiProxyFactoryBeanWithStubNotFoundException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithStubNotFoundException() throws Exception {
doTestRmiProxyFactoryBeanWithException(StubNotFoundException.class);
}
public void testRmiProxyFactoryBeanWithMarshalException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithMarshalException() throws Exception {
doTestRmiProxyFactoryBeanWithException(MarshalException.class);
}
public void testRmiProxyFactoryBeanWithUnmarshalException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithUnmarshalException() throws Exception {
doTestRmiProxyFactoryBeanWithException(UnmarshalException.class);
}
@@ -110,23 +122,28 @@ public class RmiSupportTests extends TestCase {
assertEquals(1, factory.counter);
}
public void testRmiProxyFactoryBeanWithConnectExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithConnectExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(ConnectException.class);
}
public void testRmiProxyFactoryBeanWithConnectIOExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithConnectIOExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(ConnectIOException.class);
}
public void testRmiProxyFactoryBeanWithUnknownHostExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithUnknownHostExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(UnknownHostException.class);
}
public void testRmiProxyFactoryBeanWithNoSuchObjectExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithNoSuchObjectExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(NoSuchObjectException.class);
}
public void testRmiProxyFactoryBeanWithStubNotFoundExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithStubNotFoundExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithExceptionAndRefresh(StubNotFoundException.class);
}
@@ -153,7 +170,8 @@ public class RmiSupportTests extends TestCase {
assertEquals(2, factory.counter);
}
public void testRmiProxyFactoryBeanWithBusinessInterface() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterface() throws Exception {
CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
factory.setServiceInterface(IBusinessBean.class);
factory.setServiceUrl("rmi://localhost:1090/test");
@@ -166,7 +184,8 @@ public class RmiSupportTests extends TestCase {
assertEquals(1, factory.counter);
}
public void testRmiProxyFactoryBeanWithWrongBusinessInterface() throws Exception {
@Test
public void rmiProxyFactoryBeanWithWrongBusinessInterface() throws Exception {
CountingRmiProxyFactoryBean factory = new CountingRmiProxyFactoryBean();
factory.setServiceInterface(IWrongBusinessBean.class);
factory.setServiceUrl("rmi://localhost:1090/test");
@@ -186,32 +205,38 @@ public class RmiSupportTests extends TestCase {
assertEquals(1, factory.counter);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndRemoteException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndRemoteException() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
RemoteException.class, RemoteAccessException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndConnectException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectException() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
ConnectException.class, RemoteConnectFailureException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndConnectIOException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectIOException() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
ConnectIOException.class, RemoteConnectFailureException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostException() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
UnknownHostException.class, RemoteConnectFailureException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndNoSuchObjectExceptionException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndNoSuchObjectExceptionException() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
NoSuchObjectException.class, RemoteConnectFailureException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndStubNotFoundException() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndStubNotFoundException() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndException(
StubNotFoundException.class, RemoteConnectFailureException.class);
}
@@ -241,32 +266,38 @@ public class RmiSupportTests extends TestCase {
assertEquals(1, factory.counter);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndRemoteExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndRemoteExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
RemoteException.class, RemoteAccessException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndConnectExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
ConnectException.class, RemoteConnectFailureException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndConnectIOExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndConnectIOExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
ConnectIOException.class, RemoteConnectFailureException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndUnknownHostExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
UnknownHostException.class, RemoteConnectFailureException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndNoSuchObjectExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndNoSuchObjectExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
NoSuchObjectException.class, RemoteConnectFailureException.class);
}
public void testRmiProxyFactoryBeanWithBusinessInterfaceAndStubNotFoundExceptionAndRefresh() throws Exception {
@Test
public void rmiProxyFactoryBeanWithBusinessInterfaceAndStubNotFoundExceptionAndRefresh() throws Exception {
doTestRmiProxyFactoryBeanWithBusinessInterfaceAndExceptionAndRefresh(
StubNotFoundException.class, RemoteConnectFailureException.class);
}
@@ -302,7 +333,8 @@ public class RmiSupportTests extends TestCase {
}
}
public void testRmiClientInterceptorRequiresUrl() throws Exception{
@Test
public void rmiClientInterceptorRequiresUrl() throws Exception{
RmiClientInterceptor client = new RmiClientInterceptor();
client.setServiceInterface(IRemoteBean.class);
@@ -315,7 +347,8 @@ public class RmiSupportTests extends TestCase {
}
}
public void testRemoteInvocation() throws NoSuchMethodException {
@Test
public void remoteInvocation() throws NoSuchMethodException {
// let's see if the remote invocation object works
final RemoteBean rb = new RemoteBean();
@@ -365,7 +398,8 @@ public class RmiSupportTests extends TestCase {
assertEquals(String.class, inv.getParameterTypes()[0]);
}
public void testRmiInvokerWithSpecialLocalMethods() throws Exception {
@Test
public void rmiInvokerWithSpecialLocalMethods() throws Exception {
String serviceUrl = "rmi://localhost:1090/test";
RmiProxyFactoryBean factory = new RmiProxyFactoryBean() {
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2015 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,14 +16,17 @@
package org.springframework.remoting.support;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* @author Rick Evans
*/
public class RemoteInvocationUtilsTests extends TestCase {
public class RemoteInvocationUtilsTests {
public void testFillInClientStackTraceIfPossibleSunnyDay() throws Exception {
@Test
public void fillInClientStackTraceIfPossibleSunnyDay() throws Exception {
try {
throw new IllegalStateException("Mmm");
}
@@ -35,7 +38,8 @@ public class RemoteInvocationUtilsTests extends TestCase {
}
}
public void testFillInClientStackTraceIfPossibleWithNullThrowable() throws Exception {
@Test
public void fillInClientStackTraceIfPossibleWithNullThrowable() throws Exception {
// just want to ensure that it doesn't bomb
RemoteInvocationUtils.fillInClientStackTraceIfPossible(null);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2015 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,28 +16,31 @@
package org.springframework.scheduling.concurrent;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.core.task.NoOpRunnable;
/**
* @author Rick Evans
*/
public class ConcurrentTaskExecutorTests extends TestCase {
public class ConcurrentTaskExecutorTests {
public void testZeroArgCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
@Test
public void zeroArgCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor();
// must not throw a NullPointerException
executor.execute(new NoOpRunnable());
}
public void testPassingNullExecutorToCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
@Test
public void passingNullExecutorToCtorResultsInDefaultTaskExecutorBeingUsed() throws Exception {
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor(null);
// must not throw a NullPointerException
executor.execute(new NoOpRunnable());
}
public void testPassingNullExecutorToSetterResultsInDefaultTaskExecutorBeingUsed() throws Exception {
@Test
public void passingNullExecutorToSetterResultsInDefaultTaskExecutorBeingUsed() throws Exception {
ConcurrentTaskExecutor executor = new ConcurrentTaskExecutor();
executor.setConcurrentExecutor(null);
// must not throw a NullPointerException

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -19,7 +19,7 @@ package org.springframework.scripting.bsh;
import java.util.Arrays;
import java.util.Collection;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import org.springframework.aop.target.dynamic.Refreshable;
@@ -36,6 +36,7 @@ import org.springframework.scripting.TestBeanAwareMessenger;
import org.springframework.scripting.support.ScriptFactoryPostProcessor;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
@@ -43,9 +44,10 @@ import static org.mockito.BDDMockito.*;
* @author Rick Evans
* @author Juergen Hoeller
*/
public class BshScriptFactoryTests extends TestCase {
public class BshScriptFactoryTests {
public void testStaticScript() throws Exception {
@Test
public void staticScript() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Calculator.class)).contains("calculator"));
@@ -72,7 +74,8 @@ public class BshScriptFactoryTests extends TestCase {
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}
public void testStaticScriptWithNullReturnValue() throws Exception {
@Test
public void staticScriptWithNullReturnValue() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfig"));
@@ -82,7 +85,8 @@ public class BshScriptFactoryTests extends TestCase {
assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger));
}
public void testStaticScriptWithTwoInterfacesSpecified() throws Exception {
@Test
public void staticScriptWithTwoInterfacesSpecified() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerWithConfigExtra"));
@@ -95,7 +99,8 @@ public class BshScriptFactoryTests extends TestCase {
assertNull(messenger.getMessage());
}
public void testStaticWithScriptReturningInstance() throws Exception {
@Test
public void staticWithScriptReturningInstance() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstance"));
@@ -108,7 +113,8 @@ public class BshScriptFactoryTests extends TestCase {
assertNull(messenger.getMessage());
}
public void testStaticScriptImplementingInterface() throws Exception {
@Test
public void staticScriptImplementingInterface() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerImpl"));
@@ -121,7 +127,8 @@ public class BshScriptFactoryTests extends TestCase {
assertNull(messenger.getMessage());
}
public void testStaticPrototypeScript() throws Exception {
@Test
public void staticPrototypeScript() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshContext.xml", getClass());
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
@@ -139,7 +146,8 @@ public class BshScriptFactoryTests extends TestCase {
assertEquals("Byebye World!", messenger2.getMessage());
}
public void testNonStaticScript() throws Exception {
@Test
public void nonStaticScript() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
Messenger messenger = (Messenger) ctx.getBean("messenger");
@@ -156,7 +164,8 @@ public class BshScriptFactoryTests extends TestCase {
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
}
public void testNonStaticPrototypeScript() throws Exception {
@Test
public void nonStaticPrototypeScript() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bshRefreshableContext.xml", getClass());
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
@@ -179,7 +188,8 @@ public class BshScriptFactoryTests extends TestCase {
assertEquals("Incorrect refresh count", 2, refreshable.getRefreshCount());
}
public void testScriptCompilationException() throws Exception {
@Test
public void scriptCompilationException() throws Exception {
try {
new ClassPathXmlApplicationContext("org/springframework/scripting/bsh/bshBrokenContext.xml");
fail("Must throw exception for broken script file");
@@ -189,7 +199,8 @@ public class BshScriptFactoryTests extends TestCase {
}
}
public void testScriptThatCompilesButIsJustPlainBad() throws Exception {
@Test
public void scriptThatCompilesButIsJustPlainBad() throws Exception {
ScriptSource script = mock(ScriptSource.class);
final String badScript = "String getMessage() { throw new IllegalArgumentException(); }";
given(script.getScriptAsString()).willReturn(badScript);
@@ -205,7 +216,8 @@ public class BshScriptFactoryTests extends TestCase {
}
}
public void testCtorWithNullScriptSourceLocator() throws Exception {
@Test
public void ctorWithNullScriptSourceLocator() throws Exception {
try {
new BshScriptFactory(null, Messenger.class);
fail("Must have thrown exception by this point.");
@@ -214,7 +226,8 @@ public class BshScriptFactoryTests extends TestCase {
}
}
public void testCtorWithEmptyScriptSourceLocator() throws Exception {
@Test
public void ctorWithEmptyScriptSourceLocator() throws Exception {
try {
new BshScriptFactory("", new Class<?>[] {Messenger.class});
fail("Must have thrown exception by this point.");
@@ -223,7 +236,8 @@ public class BshScriptFactoryTests extends TestCase {
}
}
public void testCtorWithWhitespacedScriptSourceLocator() throws Exception {
@Test
public void ctorWithWhitespacedScriptSourceLocator() throws Exception {
try {
new BshScriptFactory("\n ", new Class<?>[] {Messenger.class});
fail("Must have thrown exception by this point.");
@@ -232,7 +246,8 @@ public class BshScriptFactoryTests extends TestCase {
}
}
public void testResourceScriptFromTag() throws Exception {
@Test
public void resourceScriptFromTag() throws Exception {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
TestBean testBean = (TestBean) ctx.getBean("testBean");
@@ -270,7 +285,8 @@ public class BshScriptFactoryTests extends TestCase {
assertNull(messengerInstance.getMessage());
}
public void testPrototypeScriptFromTag() throws Exception {
@Test
public void prototypeScriptFromTag() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
ConfigurableMessenger messenger = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
ConfigurableMessenger messenger2 = (ConfigurableMessenger) ctx.getBean("messengerPrototype");
@@ -285,21 +301,24 @@ public class BshScriptFactoryTests extends TestCase {
assertEquals("Byebye World!", messenger2.getMessage());
}
public void testInlineScriptFromTag() throws Exception {
@Test
public void inlineScriptFromTag() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
Calculator calculator = (Calculator) ctx.getBean("calculator");
assertNotNull(calculator);
assertFalse(calculator instanceof Refreshable);
}
public void testRefreshableFromTag() throws Exception {
@Test
public void refreshableFromTag() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
Messenger messenger = (Messenger) ctx.getBean("refreshableMessenger");
assertEquals("Hello World!", messenger.getMessage());
assertTrue("Messenger should be Refreshable", messenger instanceof Refreshable);
}
public void testApplicationEventListener() throws Exception {
@Test
public void applicationEventListener() throws Exception {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bsh-with-xsd.xml", getClass());
Messenger eventListener = (Messenger) ctx.getBean("eventListener");
ctx.publishEvent(new MyEvent(ctx));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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.
@@ -18,7 +18,7 @@ package org.springframework.scripting.config;
import java.lang.reflect.Field;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
@@ -26,11 +26,14 @@ import org.springframework.aop.target.dynamic.AbstractRefreshableTargetSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.*;
/**
* @author Mark Fisher
* @author Dave Syer
*/
public class ScriptingDefaultsTests extends TestCase {
@SuppressWarnings("resource")
public class ScriptingDefaultsTests {
private static final String CONFIG =
"org/springframework/scripting/config/scriptingDefaultsTests.xml";
@@ -39,7 +42,8 @@ public class ScriptingDefaultsTests extends TestCase {
"org/springframework/scripting/config/scriptingDefaultsProxyTargetClassTests.xml";
public void testDefaultRefreshCheckDelay() throws Exception {
@Test
public void defaultRefreshCheckDelay() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
Advised advised = (Advised) context.getBean("testBean");
AbstractRefreshableTargetSource targetSource =
@@ -50,19 +54,22 @@ public class ScriptingDefaultsTests extends TestCase {
assertEquals(5000L, delay);
}
public void testDefaultInitMethod() {
@Test
public void defaultInitMethod() {
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
ITestBean testBean = (ITestBean) context.getBean("testBean");
assertTrue(testBean.isInitialized());
}
public void testNameAsAlias() {
@Test
public void nameAsAlias() {
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
ITestBean testBean = (ITestBean) context.getBean("/url");
assertTrue(testBean.isInitialized());
}
public void testDefaultDestroyMethod() {
@Test
public void defaultDestroyMethod() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
ITestBean testBean = (ITestBean) context.getBean("nonRefreshableTestBean");
assertFalse(testBean.isDestroyed());
@@ -70,14 +77,16 @@ public class ScriptingDefaultsTests extends TestCase {
assertTrue(testBean.isDestroyed());
}
public void testDefaultAutowire() {
@Test
public void defaultAutowire() {
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
ITestBean testBean = (ITestBean) context.getBean("testBean");
ITestBean otherBean = (ITestBean) context.getBean("otherBean");
assertEquals(otherBean, testBean.getOtherBean());
}
public void testDefaultProxyTargetClass() {
@Test
public void defaultProxyTargetClass() {
ApplicationContext context = new ClassPathXmlApplicationContext(PROXY_CONFIG);
Object testBean = context.getBean("testBean");
assertTrue(AopUtils.isCglibProxy(testBean));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -30,14 +30,17 @@ import static org.junit.Assert.*;
/**
* @author Dave Syer
* @author Sam Brannen
*/
public class GroovyAspectTests {
@Test
public void testManualGroovyBeanWithUnconditionalPointcut() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
private final LogUserAdvice logAdvice = new LogUserAdvice();
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
private final GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
@Test
public void manualGroovyBeanWithUnconditionalPointcut() throws Exception {
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
@@ -45,10 +48,7 @@ public class GroovyAspectTests {
}
@Test
public void testManualGroovyBeanWithStaticPointcut() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
public void manualGroovyBeanWithStaticPointcut() throws Exception {
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
@@ -58,31 +58,23 @@ public class GroovyAspectTests {
}
@Test
public void testManualGroovyBeanWithDynamicPointcut() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
public void manualGroovyBeanWithDynamicPointcut() throws Exception {
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", false);
}
@Test
public void testManualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
LogUserAdvice logAdvice = new LogUserAdvice();
GroovyScriptFactory scriptFactory = new GroovyScriptFactory("GroovyServiceImpl.grv");
public void manualGroovyBeanWithDynamicPointcutProxyTargetClass() throws Exception {
TestService target = (TestService) scriptFactory.getScriptedObject(new ResourceScriptSource(
new ClassPathResource("GroovyServiceImpl.grv", getClass())));
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("@within(%s.Log)", ClassUtils.getPackageName(getClass())));
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "GroovyServiceImpl", true);
}
private void testAdvice(Advisor advisor, LogUserAdvice logAdvice, TestService target, String message)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2015 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,21 +16,25 @@
package org.springframework.scripting.groovy;
import groovy.lang.GroovyClassLoader;
import java.lang.reflect.Method;
import groovy.lang.GroovyClassLoader;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.*;
/**
* @author Mark Fisher
*/
public class GroovyClassLoadingTests extends TestCase {
public class GroovyClassLoadingTests {
public void testClassLoading() throws Exception {
@Test
@SuppressWarnings("resource")
public void classLoading() throws Exception {
StaticApplicationContext context = new StaticApplicationContext();
GroovyClassLoader gcl = new GroovyClassLoader();
@@ -41,16 +45,14 @@ public class GroovyClassLoadingTests extends TestCase {
Object testBean1 = context.getBean("testBean");
Method method1 = class1.getDeclaredMethod("myMethod", new Class<?>[0]);
Object result1 = ReflectionUtils.invokeMethod(method1, testBean1);
assertEquals("foo", (String) result1);
// ### uncommenting the next line causes the test to pass for Spring > 2.0.2 ###
//context.removeBeanDefinition("testBean");
assertEquals("foo", result1);
context.removeBeanDefinition("testBean");
context.registerBeanDefinition("testBean", new RootBeanDefinition(class2));
Object testBean2 = context.getBean("testBean");
Method method2 = class2.getDeclaredMethod("myMethod", new Class<?>[0]);
Object result2 = ReflectionUtils.invokeMethod(method2, testBean2);
assertEquals("bar", (String) result2);
assertEquals("bar", result2);
}
}

View File

@@ -1,3 +1,19 @@
/*
* Copyright 2002-2015 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.scripting.groovy;
import java.lang.reflect.Method;
@@ -14,15 +30,15 @@ public class LogUserAdvice implements MethodBeforeAdvice, ThrowsAdvice {
@Override
public void before(Method method, Object[] objects, Object o) throws Throwable {
countBefore++;
System.out.println("Method:"+method.getName());
// System.out.println("Method:" + method.getName());
}
public void afterThrowing(Exception e) throws Throwable {
countThrows++;
System.out.println("***********************************************************************************");
System.out.println("Exception caught:");
System.out.println("***********************************************************************************");
e.printStackTrace();
// System.out.println("***********************************************************************************");
// System.out.println("Exception caught:");
// System.out.println("***********************************************************************************");
// e.printStackTrace();
throw e;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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,24 +16,20 @@
package org.springframework.scripting.support;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import static org.mockito.BDDMockito.*;
import static org.mockito.Mockito.*;
/**
* @author Rick Evans
*/
public class RefreshableScriptTargetSourceTests extends TestCase {
public class RefreshableScriptTargetSourceTests {
public void testCreateWithNullScriptSource() throws Exception {
try {
new RefreshableScriptTargetSource(mock(BeanFactory.class), "a.bean", null, null, false);
fail("Must have failed when passed a null ScriptSource.");
}
catch (IllegalArgumentException expected) {
}
@Test(expected = IllegalArgumentException.class)
public void createWithNullScriptSource() throws Exception {
new RefreshableScriptTargetSource(mock(BeanFactory.class), "a.bean", null, null, false);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2015 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.
@@ -19,20 +19,22 @@ package org.springframework.scripting.support;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import junit.framework.TestCase;
import org.junit.Test;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.Resource;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.*;
/**
* @author Rick Evans
* @author Juergen Hoeller
*/
public class ResourceScriptSourceTests extends TestCase {
public class ResourceScriptSourceTests {
public void testDoesNotPropagateFatalExceptionOnResourceThatCannotBeResolvedToAFile() throws Exception {
@Test
public void doesNotPropagateFatalExceptionOnResourceThatCannotBeResolvedToAFile() throws Exception {
Resource resource = mock(Resource.class);
given(resource.lastModified()).willThrow(new IOException());
@@ -41,13 +43,15 @@ public class ResourceScriptSourceTests extends TestCase {
assertEquals(0, lastModified);
}
public void testBeginsInModifiedState() throws Exception {
@Test
public void beginsInModifiedState() throws Exception {
Resource resource = mock(Resource.class);
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
assertTrue(scriptSource.isModified());
}
public void testLastModifiedWorksWithResourceThatDoesNotSupportFileBasedReading() throws Exception {
@Test
public void lastModifiedWorksWithResourceThatDoesNotSupportFileBasedReading() throws Exception {
Resource resource = mock(Resource.class);
// underlying File is asked for so that the last modified time can be checked...
// And then mock the file changing; i.e. the File says it has been modified
@@ -65,7 +69,8 @@ public class ResourceScriptSourceTests extends TestCase {
assertTrue("ResourceScriptSource must report back as being modified if the underlying File resource is reporting a changed lastModified time.", scriptSource.isModified());
}
public void testLastModifiedWorksWithResourceThatDoesNotSupportFileBasedAccessAtAll() throws Exception {
@Test
public void lastModifiedWorksWithResourceThatDoesNotSupportFileBasedAccessAtAll() throws Exception {
Resource resource = new ByteArrayResource(new byte[0]);
ResourceScriptSource scriptSource = new ResourceScriptSource(resource);
assertTrue("ResourceScriptSource must start off in the 'isModified' state (it obviously isn't).", scriptSource.isModified());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2006 the original author or authors.
* Copyright 2002-2015 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,71 +16,64 @@
package org.springframework.scripting.support;
import junit.framework.TestCase;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Unit tests for the StaticScriptSource class.
*
* @author Rick Evans
* @author Sam Brannen
*/
public final class StaticScriptSourceTests extends TestCase {
public final class StaticScriptSourceTests {
private static final String SCRIPT_TEXT = "print($hello) if $true;";
private final StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
public void testCreateWithNullScript() throws Exception {
try {
new StaticScriptSource(null);
fail("Must have failed when passed a null script string.");
}
catch (IllegalArgumentException expected) {
}
@Test(expected = IllegalArgumentException.class)
public void createWithNullScript() throws Exception {
new StaticScriptSource(null);
}
public void testCreateWithEmptyScript() throws Exception {
try {
new StaticScriptSource("");
fail("Must have failed when passed an empty script string.");
}
catch (IllegalArgumentException expected) {
}
@Test(expected = IllegalArgumentException.class)
public void createWithEmptyScript() throws Exception {
new StaticScriptSource("");
}
public void testCreateWithWhitespaceOnlyScript() throws Exception {
try {
new StaticScriptSource(" \n\n\t \t\n");
fail("Must have failed when passed a whitespace-only script string.");
}
catch (IllegalArgumentException expected) {
}
@Test(expected = IllegalArgumentException.class)
public void createWithWhitespaceOnlyScript() throws Exception {
new StaticScriptSource(" \n\n\t \t\n");
}
public void testIsModifiedIsTrueByDefault() throws Exception {
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
@Test
public void isModifiedIsTrueByDefault() throws Exception {
assertTrue("Script must be flagged as 'modified' when first created.", source.isModified());
}
public void testGettingScriptTogglesIsModified() throws Exception {
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
@Test
public void gettingScriptTogglesIsModified() throws Exception {
source.getScriptAsString();
assertFalse("Script must be flagged as 'not modified' after script is read.", source.isModified());
}
public void testGettingScriptViaToStringDoesNotToggleIsModified() throws Exception {
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
@Test
public void gettingScriptViaToStringDoesNotToggleIsModified() throws Exception {
boolean isModifiedState = source.isModified();
source.toString();
assertEquals("Script's 'modified' flag must not change after script is read via toString().", isModifiedState, source.isModified());
}
public void testIsModifiedToggledWhenDifferentScriptIsSet() throws Exception {
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
@Test
public void isModifiedToggledWhenDifferentScriptIsSet() throws Exception {
source.setScript("use warnings;");
assertTrue("Script must be flagged as 'modified' when different script is passed in.", source.isModified());
}
public void testIsModifiedNotToggledWhenSameScriptIsSet() throws Exception {
StaticScriptSource source = new StaticScriptSource(SCRIPT_TEXT);
@Test
public void isModifiedNotToggledWhenSameScriptIsSet() throws Exception {
source.setScript(SCRIPT_TEXT);
assertFalse("Script must not be flagged as 'modified' when same script is passed in.", source.isModified());
}