From 21f5aed3b5ab9e5877fb16cc51f99db9d59ea6be Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 29 Jul 2010 21:41:41 +0000 Subject: [PATCH] --- .../java/org/wamblee/cdi/CdiInjectorTest.java | 44 ++++++++++--------- .../org/wamblee/cdi/InjectorBuilderTest.java | 19 ++++++++ 2 files changed, 43 insertions(+), 20 deletions(-) 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 c1ee4f92..13946b3a 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/CdiInjectorTest.java @@ -20,44 +20,48 @@ import static junit.framework.Assert.*; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.wamblee.inject.InjectorBuilder; public class CdiInjectorTest extends BaseTestFixture { - - private BeanManagerSetup manager; - + + private BeanManagerSetup manager; + @Before - public void setUp() throws Exception { + public void setUp() throws Exception { super.setUp(); manager = new BeanManagerSetup(); - manager.initialize(); + manager.initialize(); } - + @After - public void tearDown() throws Exception { + public void tearDown() throws Exception { manager.shutdown(); super.tearDown(); } - + @Test - public void testInject() { - CdiInjector injector = new CdiInjector(manager.getBeanManager(), MyPojo.class); - MyPojo pojo = new MyPojo(); + public void testInject() { + CdiInjector injector = new CdiInjector(manager.getBeanManager(), + MyPojo.class); + MyPojo pojo = new MyPojo(); injector.inject(pojo); assertNotNull(pojo.getSingleton()); } - + @Test(expected = IllegalArgumentException.class) - public void testWrongType() { - CdiInjector injector = new CdiInjector(manager.getBeanManager(), String.class); - MyPojo pojo = new MyPojo(); + public void testWrongType() { + CdiInjector injector = new CdiInjector(manager.getBeanManager(), + String.class); + MyPojo pojo = new MyPojo(); injector.inject(pojo); } - + @Test - public void testNullObject() { - CdiInjector injector = new CdiInjector(manager.getBeanManager(), MyPojo.class); + public void testNullObject() { + CdiInjector injector = new CdiInjector(manager.getBeanManager(), + MyPojo.class); injector.inject(null); - - // ok should simply ignore. + + // ok should simply ignore. } } diff --git a/support/cdi/src/test/java/org/wamblee/cdi/InjectorBuilderTest.java b/support/cdi/src/test/java/org/wamblee/cdi/InjectorBuilderTest.java index dd1210fb..36440cf4 100644 --- a/support/cdi/src/test/java/org/wamblee/cdi/InjectorBuilderTest.java +++ b/support/cdi/src/test/java/org/wamblee/cdi/InjectorBuilderTest.java @@ -46,4 +46,23 @@ public class InjectorBuilderTest extends BaseTestFixture { StubInitialContextFactory.unregister(); } } + + @Test + public void testInjectManyTimes() { + int n = 1000; + BeanManagerSetup setup = new BeanManagerSetup(); + setup.initialize(); + BeanManagerLookup.setBeanManager(setup.getBeanManager()); + InjectorBuilder.setInjectorFactory(null); + long t0 = System.currentTimeMillis(); + for (int i = 0; i < n; i++) { + MyPojo pojo = new MyPojo(); + InjectorBuilder.getInjector().inject(pojo); + } + long t1 = System.currentTimeMillis(); + System.out.println(t1 - t0); + System.out.println("Injections per second: " + ((double) n) / + ((double) (t1 - t0)) * ((double) 1000)); + setup.shutdown(); + } } -- 2.31.1