From 1baf903d22ec384ea7d730889c2b0fd5f087a0e5 Mon Sep 17 00:00:00 2001 From: Erik Brakkee Date: Fri, 16 Jul 2010 11:27:43 +0000 Subject: [PATCH] --- .../java/org/wamblee/cdi/BaseTestFixture.java | 34 +++++++++++++++++++ .../wamblee/cdi/BeanManagerLookupTest.java | 7 ++-- .../wamblee/cdi/CdiInjectorFactoryTest.java | 8 +++-- .../java/org/wamblee/cdi/CdiInjectorTest.java | 8 +++-- .../cdi/InjectorFactoryBuilderTest.java | 3 +- .../org/wamblee/cdi/SimpleInjectorTest.java | 8 +++-- 6 files changed, 53 insertions(+), 15 deletions(-) create mode 100644 support/cdi/src/test/java/org/wamblee/cdi/BaseTestFixture.java diff --git a/support/cdi/src/test/java/org/wamblee/cdi/BaseTestFixture.java b/support/cdi/src/test/java/org/wamblee/cdi/BaseTestFixture.java new file mode 100644 index 00000000..dd3abc40 --- /dev/null +++ b/support/cdi/src/test/java/org/wamblee/cdi/BaseTestFixture.java @@ -0,0 +1,34 @@ +/* + * Copyright 2005-2010 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.wamblee.cdi; + +import org.junit.After; +import org.junit.Before; + +public class BaseTestFixture { + + @Before + public void setUp() throws Exception { + BeanManagerLookup.setBeanManager(null); + } + + + @After + public void tearDown() throws Exception { + BeanManagerLookup.setBeanManager(null); + } + +} diff --git a/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java b/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java index c1fd7cb1..f73f7066 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/BeanManagerLookupTest.java @@ -16,6 +16,7 @@ package org.wamblee.cdi; import static junit.framework.Assert.*; +import static org.mockito.Mockito.*; import javax.enterprise.inject.spi.BeanManager; import javax.naming.InitialContext; @@ -23,10 +24,8 @@ import javax.naming.InitialContext; import org.junit.Test; import org.wamblee.support.jndi.StubInitialContextFactory; -import static org.mockito.Mockito.*; - -public class BeanManagerLookupTest { - +public class BeanManagerLookupTest extends BaseTestFixture { + @Test public void testLookupInJndi() throws Exception { BeanManagerSetup setup = new BeanManagerSetup(); diff --git a/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java b/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java index 76931da4..5461d5c0 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorFactoryTest.java @@ -23,19 +23,21 @@ import org.wamblee.inject.InjectorFactory; import static junit.framework.TestCase.*; -public class CdiInjectorFactoryTest { +public class CdiInjectorFactoryTest extends BaseTestFixture { private BeanManagerSetup manager; @Before - public void setUp() { + public void setUp() throws Exception { + super.setUp(); manager = new BeanManagerSetup(); manager.initialize(); } @After - public void tearDown() { + public void tearDown() throws Exception { manager.shutdown(); + super.tearDown(); } @Test diff --git a/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorTest.java b/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorTest.java index 21133fa7..c1ee4f92 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorTest.java @@ -21,19 +21,21 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; -public class CdiInjectorTest { +public class CdiInjectorTest extends BaseTestFixture { private BeanManagerSetup manager; @Before - public void setUp() { + public void setUp() throws Exception { + super.setUp(); manager = new BeanManagerSetup(); manager.initialize(); } @After - public void tearDown() { + public void tearDown() throws Exception { manager.shutdown(); + super.tearDown(); } @Test diff --git a/support/cdi/src/test/java/org/wamblee/cdi/InjectorFactoryBuilderTest.java b/support/cdi/src/test/java/org/wamblee/cdi/InjectorFactoryBuilderTest.java index 97c85bf1..cc5f8b22 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/InjectorFactoryBuilderTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/InjectorFactoryBuilderTest.java @@ -24,8 +24,7 @@ import org.wamblee.inject.InjectorFactory; import org.wamblee.inject.InjectorFactoryBuilder; import org.wamblee.support.jndi.StubInitialContextFactory; -public class InjectorFactoryBuilderTest { - +public class InjectorFactoryBuilderTest extends BaseTestFixture { @Test diff --git a/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java b/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java index 2a3b1242..61cdfb86 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/SimpleInjectorTest.java @@ -28,24 +28,26 @@ import org.wamblee.inject.InjectorFactory; import org.wamblee.inject.SimpleInjector; import org.wamblee.support.jndi.StubInitialContextFactory; -public class SimpleInjectorTest { +public class SimpleInjectorTest extends BaseTestFixture { private BeanManagerSetup setup; @Before public void setUp() throws Exception { + super.setUp(); setup = new BeanManagerSetup(); setup.initialize(); StubInitialContextFactory.register(); InitialContext ctx = new InitialContext(); ctx.bind(BeanManagerLookup.BEAN_MANAGER_JNDI, setup.getBeanManager()); - MySingleton.reset(); + MySingleton.reset(); } @After - public void tearDown() { + public void tearDown() throws Exception { StubInitialContextFactory.unregister(); setup.shutdown(); + super.tearDown(); } @Test -- 2.31.1