From ec1f304793d6c8b8be2153377e1e49604316bf8b Mon Sep 17 00:00:00 2001 From: mcombellack Date: Wed, 3 Dec 2008 14:35:23 +0000 Subject: Converted unit tests from JUnit 3 to JUnit 4 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@722905 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/context/MultiplicityTestCase.java | 6 +++-- .../java/injection/FieldInjectorTestCase.java | 13 ++++++----- .../java/injection/MethodEventInvokerTestCase.java | 15 ++++++++----- .../java/injection/MethodInjectorTestCase.java | 15 ++++++++----- .../RequestContextObjectFactoryTestCase.java | 7 ++++-- .../injection/SingletonObjectFactoryTestCase.java | 7 ++++-- .../java/injection/TestObjectFactoryTestCase.java | 17 +++++++++----- .../java/util/JavaIntrospectionHelperTestCase.java | 26 +++++++++++++--------- 8 files changed, 66 insertions(+), 40 deletions(-) (limited to 'java/sca') diff --git a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java index ba8da101c6..629ba8b321 100644 --- a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java +++ b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java @@ -18,7 +18,8 @@ */ package org.apache.tuscany.sca.implementation.java.context; -import junit.framework.TestCase; +import org.junit.Test; + /** @@ -26,8 +27,9 @@ import junit.framework.TestCase; * * @version $Rev$ $Date$ */ -public class MultiplicityTestCase extends TestCase { +public class MultiplicityTestCase { + @Test public void testMultiplicity() throws Exception { // TODO implement } diff --git a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java index cc852cc677..098789f495 100644 --- a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java +++ b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java @@ -18,17 +18,21 @@ */ package org.apache.tuscany.sca.implementation.java.injection; +import static org.junit.Assert.assertEquals; + import java.lang.reflect.Field; -import junit.framework.TestCase; +import org.junit.Before; +import org.junit.Test; /** * @version $Rev$ $Date$ */ -public class FieldInjectorTestCase extends TestCase { +public class FieldInjectorTestCase { protected Field protectedField; + @Test public void testIllegalAccess() throws Exception { FieldInjector injector = new FieldInjector(protectedField, new SingletonObjectFactory("foo")); Foo foo = new Foo(); @@ -37,9 +41,8 @@ public class FieldInjectorTestCase extends TestCase { } - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { protectedField = Foo.class.getDeclaredField("hidden"); } diff --git a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java index 4de0a4e8c7..e9cbce4390 100644 --- a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java +++ b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java @@ -18,20 +18,23 @@ */ package org.apache.tuscany.sca.implementation.java.injection; -import java.lang.reflect.Method; +import static org.junit.Assert.fail; -import junit.framework.TestCase; +import java.lang.reflect.Method; import org.apache.tuscany.sca.implementation.java.invocation.EventInvocationException; import org.apache.tuscany.sca.implementation.java.invocation.MethodEventInvoker; +import org.junit.Before; +import org.junit.Test; /** * @version $Rev$ $Date$ */ -public class MethodEventInvokerTestCase extends TestCase { +public class MethodEventInvokerTestCase { private Method privateMethod; private Method exceptionMethod; + @Test public void testIllegalAccess() throws Exception { MethodEventInvoker injector = new MethodEventInvoker(privateMethod); try { @@ -42,6 +45,7 @@ public class MethodEventInvokerTestCase extends TestCase { } } + @Test public void testException() throws Exception { MethodEventInvoker injector = new MethodEventInvoker(exceptionMethod); try { @@ -52,9 +56,8 @@ public class MethodEventInvokerTestCase extends TestCase { } } - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { privateMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("hidden"); exceptionMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("exception"); diff --git a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java index 214779ed3f..19184d5204 100644 --- a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java +++ b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java @@ -18,21 +18,24 @@ */ package org.apache.tuscany.sca.implementation.java.injection; -import java.lang.reflect.Method; +import static org.junit.Assert.fail; -import junit.framework.TestCase; +import java.lang.reflect.Method; import org.apache.tuscany.sca.core.factory.ObjectCreationException; import org.apache.tuscany.sca.core.factory.ObjectFactory; +import org.junit.Before; +import org.junit.Test; /** * @version $Rev$ $Date$ */ -public class MethodInjectorTestCase extends TestCase { +public class MethodInjectorTestCase { private Method fooMethod; private Method privateMethod; private Method exceptionMethod; + @Test public void testIllegalArgument() throws Exception { ObjectFactory factory = new SingletonObjectFactory(new Object()); MethodInjector injector = new MethodInjector(fooMethod, factory); @@ -44,6 +47,7 @@ public class MethodInjectorTestCase extends TestCase { } } + @Test public void testException() throws Exception { ObjectFactory factory = new SingletonObjectFactory("foo"); MethodInjector injector = new MethodInjector(exceptionMethod, factory); @@ -55,9 +59,8 @@ public class MethodInjectorTestCase extends TestCase { } } - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { fooMethod = Foo.class.getMethod("foo", String.class); privateMethod = Foo.class.getDeclaredMethod("hidden", String.class); exceptionMethod = Foo.class.getDeclaredMethod("exception", String.class); diff --git a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java index c470b8cf3d..61af4de19c 100644 --- a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java +++ b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java @@ -18,13 +18,16 @@ */ package org.apache.tuscany.sca.implementation.java.injection; -import junit.framework.TestCase; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; /** * @version $Rev$ $Date$ */ -public class RequestContextObjectFactoryTestCase extends TestCase { +public class RequestContextObjectFactoryTestCase { + @Test public void testInstanceCreate() { RequestContextObjectFactory factory = new RequestContextObjectFactory(null); assertNotNull(factory.getInstance()); diff --git a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java index 40ad1b1e95..0bb222bad4 100644 --- a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java +++ b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java @@ -18,13 +18,16 @@ */ package org.apache.tuscany.sca.implementation.java.injection; -import junit.framework.TestCase; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; /** * @version $Rev$ $Date$ */ -public class SingletonObjectFactoryTestCase extends TestCase { +public class SingletonObjectFactoryTestCase { + @Test public void testSingleton() throws Exception { Object o = new Object(); SingletonObjectFactory factory = new SingletonObjectFactory(o); diff --git a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.java b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.java index 1fb7abb917..ea9d15b3f6 100644 --- a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.java +++ b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.java @@ -18,21 +18,25 @@ */ package org.apache.tuscany.sca.implementation.java.injection; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - import org.apache.tuscany.sca.core.factory.ObjectFactory; +import org.junit.Before; +import org.junit.Test; /** * @version $Rev$ $Date$ */ -public class TestObjectFactoryTestCase extends TestCase { +public class TestObjectFactoryTestCase { private Constructor ctor; + @Test public void testConstructorInjection() throws Exception { List initializers = new ArrayList(); initializers.add(new SingletonObjectFactory("foo")); @@ -45,6 +49,7 @@ public class TestObjectFactoryTestCase extends TestCase { * Verifies null parameters can be passed to a constructor. This is valid when a reference is optional during * constructor injection */ + @Test public void testConstructorInjectionOptionalParam() throws Exception { List initializers = new ArrayList(); initializers.add(null); @@ -53,6 +58,7 @@ public class TestObjectFactoryTestCase extends TestCase { assertNull(foo.foo); } + @Test public void testConstructorInitializerInjection() throws Exception { TestObjectFactory factory = new TestObjectFactory(ctor); factory.setInitializerFactory(0, new SingletonObjectFactory("foo")); @@ -60,9 +66,8 @@ public class TestObjectFactoryTestCase extends TestCase { assertEquals("foo", foo.foo); } - @Override - protected void setUp() throws Exception { - super.setUp(); + @Before + public void setUp() throws Exception { ctor = Foo.class.getConstructor(String.class); } diff --git a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java index b104f1a6c0..192536e2c9 100644 --- a/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java +++ b/java/sca/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java @@ -18,6 +18,9 @@ */ package org.apache.tuscany.sca.implementation.java.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -25,15 +28,14 @@ import java.util.List; import java.util.Map; import java.util.Set; -import junit.framework.TestCase; - import org.apache.tuscany.sca.implementation.java.introspect.JavaIntrospectionHelper; +import org.junit.Test; /** * * @version $Rev$ $Date$ */ -public class JavaIntrospectionHelperTestCase extends TestCase { +public class JavaIntrospectionHelperTestCase { private List testNoGenericsList; private List testList; @@ -41,29 +43,25 @@ public class JavaIntrospectionHelperTestCase extends TestCase { private Entry[] testArray; private String[] testStringArray; - public JavaIntrospectionHelperTestCase() { - super(); - } - - public JavaIntrospectionHelperTestCase(String arg0) { - super(arg0); - } - + @Test public void testBean1AllPublicProtectedFields() throws Exception { Set beanFields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(Bean1.class, true); assertEquals(4, beanFields.size()); //Bean1.ALL_BEAN1_PUBLIC_PROTECTED_FIELDS } + @Test public void testGetSuperAllMethods() throws Exception { Set superBeanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(SuperBean.class, true); assertEquals(SuperBean.ALL_SUPER_METHODS, superBeanMethods.size()); } + @Test public void testGetBean1AllMethods() throws Exception { Set beanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class, true); assertEquals(Bean1.ALL_BEAN1_METHODS, beanMethods.size()); } + @Test public void testOverrideMethod() throws Exception { Set beanFields = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class, true); boolean invoked = false; @@ -78,6 +76,7 @@ public class JavaIntrospectionHelperTestCase extends TestCase { } } + @Test public void testNoOverrideMethod() throws Exception { Set beanFields = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class, true); boolean found = false; @@ -91,6 +90,7 @@ public class JavaIntrospectionHelperTestCase extends TestCase { } } + @Test public void testDefaultConstructor() throws Exception { Constructor ctr = JavaIntrospectionHelper.getDefaultConstructor(Bean2.class); assertEquals(ctr, Bean2.class.getConstructor()); @@ -98,6 +98,7 @@ public class JavaIntrospectionHelperTestCase extends TestCase { } + @Test public void testGetAllInterfaces() { Set interfaces = JavaIntrospectionHelper.getAllInterfaces(Z.class); assertEquals(2, interfaces.size()); @@ -106,11 +107,13 @@ public class JavaIntrospectionHelperTestCase extends TestCase { } + @Test public void testGetAllInterfacesObject() { Set interfaces = JavaIntrospectionHelper.getAllInterfaces(Object.class); assertEquals(0, interfaces.size()); } + @Test public void testGetAllInterfacesNoInterfaces() { Set interfaces = JavaIntrospectionHelper.getAllInterfaces(NoInterface.class); assertEquals(0, interfaces.size()); @@ -119,6 +122,7 @@ public class JavaIntrospectionHelperTestCase extends TestCase { /** * Tests generics introspection capabilities */ + @Test public void testGenerics() throws Exception { List classes = JavaIntrospectionHelper.getGenerics(getClass().getDeclaredField("testList").getGenericType()); -- cgit v1.2.3