From: erik Date: Sat, 31 Jul 2010 17:33:59 +0000 (+0000) Subject: (no commit message) X-Git-Tag: wamblee-utils-0.5~6 X-Git-Url: http://wamblee.org/gitweb/?a=commitdiff_plain;h=a7ad3d8ca1cc0f40662282cbda9922e95aaf8821;p=utils --- diff --git a/wicket/joe/src/main/java/org/wamblee/wicket/inject/ComponentInstantiationInjector.java b/wicket/joe/src/main/java/org/wamblee/wicket/inject/ComponentInstantiationInjector.java index a4a0dcf9..cdda947d 100644 --- a/wicket/joe/src/main/java/org/wamblee/wicket/inject/ComponentInstantiationInjector.java +++ b/wicket/joe/src/main/java/org/wamblee/wicket/inject/ComponentInstantiationInjector.java @@ -23,39 +23,40 @@ import org.wamblee.inject.SimpleInjector; /** *

- * Component instantiation listener that injects references into a component - * using the injector mini-framework. Together with an implementation of the + * Component instantiation listener that injects references into a component + * using the injector mini-framework. Together with an implementation of the * mini-framework, Contexts and Dependency Injection support can be provided or - * for standard Java EE injection into components. Or, other injection + * for standard Java EE injection into components. Or, other injection * frameworks can be used. *

* *

- * To use this injector override {@link WebApplication#init()} and add the - * listener: + * To use this injector override {@link WebApplication#init()} and add the + * listener: *

+ * *
- *    @Override
- *    protected void init() {
- *       super.init();
- *       addComponentInstantiationListener(new ComponentInstantiationInjector());
- *    }
+ * @Override
+ * protected void init() {
+ *     super.init();
+ *     addComponentInstantiationListener(new ComponentInstantiationInjector());
+ * }
  * 
* * @author Erik Brakkee */ public class ComponentInstantiationInjector implements - IComponentInstantiationListener { - - private SimpleInjector injector; - + IComponentInstantiationListener { + + private SimpleInjector injector; + /** - * Constructs the component instantiation listener. + * Constructs the component instantiation listener. */ - public ComponentInstantiationInjector() { + public ComponentInstantiationInjector() { injector = new SimpleInjector(InjectorBuilder.getInjectorFactory()); } - + @Override public void onInstantiation(Component aComponent) { injector.inject(aComponent); diff --git a/wicket/joe/src/main/java/org/wamblee/wicket/inject/InjectionBehavior.java b/wicket/joe/src/main/java/org/wamblee/wicket/inject/InjectionBehavior.java index 3d648c4e..659be7a7 100644 --- a/wicket/joe/src/main/java/org/wamblee/wicket/inject/InjectionBehavior.java +++ b/wicket/joe/src/main/java/org/wamblee/wicket/inject/InjectionBehavior.java @@ -21,27 +21,28 @@ import org.wamblee.inject.InjectorBuilder; /** * Injection behavior that performs dependency injection after - * serialization/deserialisation of the object. + * serialization/deserialisation of the object. * * @author Erik Brakkee - * + * */ public class InjectionBehavior extends AbstractBehavior { + private static final long serialVersionUID = 7363393083209418693L; private transient boolean injectionUptodate; - + /** * Constructs the behavior. */ - public InjectionBehavior() { - injectionUptodate = true; + public InjectionBehavior() { + injectionUptodate = true; } - + @Override public void beforeRender(Component aComponent) { - if (!injectionUptodate) { + if (!injectionUptodate) { InjectorBuilder.getInjector().inject(aComponent); - injectionUptodate = true; + injectionUptodate = true; } } } diff --git a/wicket/joe/src/main/java/org/wamblee/wicket/model/DetachableEntity.java b/wicket/joe/src/main/java/org/wamblee/wicket/model/DetachableEntity.java index 11fe3abf..5bde6cb6 100644 --- a/wicket/joe/src/main/java/org/wamblee/wicket/model/DetachableEntity.java +++ b/wicket/joe/src/main/java/org/wamblee/wicket/model/DetachableEntity.java @@ -19,35 +19,38 @@ import org.apache.wicket.model.LoadableDetachableModel; import org.wamblee.persistence.Detachable; /** - * A detachable model that wraps a domain object. - * + * A detachable model that wraps a domain object. + * */ public class DetachableEntity extends LoadableDetachableModel { - - private Detachable object; - - /** - * Constructs the model. - * @param aObject Object to construct the model with. - */ - public DetachableEntity(Detachable aObject) { - super(aObject.get()); + + private Detachable object; + + /** + * Constructs the model. + * + * @param aObject + * Object to construct the model with. + */ + public DetachableEntity(Detachable aObject) { + super(aObject.get()); object = aObject; - } - - @Override - protected void onDetach() { - object.detach(); - } - - @Override - protected T load() { - return object.get(); - } - - @Override - public void setObject(T object) { - throw new UnsupportedOperationException("setObject is not supported on this class"); - } + } + + @Override + protected void onDetach() { + object.detach(); + } + + @Override + protected T load() { + return object.get(); + } + + @Override + public void setObject(T aObject) { + throw new UnsupportedOperationException( + "setObject is not supported on this class"); + } } diff --git a/wicket/joe/src/main/java/org/wamblee/wicket/transactions/package-info.java b/wicket/joe/src/main/java/org/wamblee/wicket/transactions/package-info.java index aa536f7a..f2d66b79 100644 --- a/wicket/joe/src/main/java/org/wamblee/wicket/transactions/package-info.java +++ b/wicket/joe/src/main/java/org/wamblee/wicket/transactions/package-info.java @@ -17,4 +17,4 @@ * This package provides transaction support for wicket making it really easy * to work with transactions. */ -package org.wamblee.wicket.transactions; \ No newline at end of file +package org.wamblee.wicket.transactions; \ No newline at end of file diff --git a/wicket/joe/src/test/java/org/wamblee/wicket/inject/ComponentInstantiationInjectorTest.java b/wicket/joe/src/test/java/org/wamblee/wicket/inject/ComponentInstantiationInjectorTest.java index 5824c6dc..59d59f69 100644 --- a/wicket/joe/src/test/java/org/wamblee/wicket/inject/ComponentInstantiationInjectorTest.java +++ b/wicket/joe/src/test/java/org/wamblee/wicket/inject/ComponentInstantiationInjectorTest.java @@ -23,21 +23,21 @@ import org.apache.wicket.util.tester.WicketTester; import org.junit.Test; import org.wamblee.inject.Injector; - public class ComponentInstantiationInjectorTest { - + @Test - public void testListener() { + public void testListener() { WicketTester tester = new WicketTester(); - tester.getApplication().addComponentInstantiationListener(new ComponentInstantiationInjector()); - - Injector injector = mock(Injector.class); - TestInjectorFactory.setMockInjector(injector); - + tester.getApplication().addComponentInstantiationListener( + new ComponentInstantiationInjector()); + + Injector injector = mock(Injector.class); + TestInjectorFactory.setMockInjector(injector); + Component component = new WebMarkupContainer("hello"); - - // Verify the injector was called with the component as an argument. - verify(injector).inject(same(component)); + + // Verify the injector was called with the component as an argument. + verify(injector).inject(same(component)); } } diff --git a/wicket/joe/src/test/java/org/wamblee/wicket/inject/InjectionBehaviorTest.java b/wicket/joe/src/test/java/org/wamblee/wicket/inject/InjectionBehaviorTest.java index d5c62024..d54de1ce 100644 --- a/wicket/joe/src/test/java/org/wamblee/wicket/inject/InjectionBehaviorTest.java +++ b/wicket/joe/src/test/java/org/wamblee/wicket/inject/InjectionBehaviorTest.java @@ -33,9 +33,9 @@ import static org.mockito.Mockito.*; public class InjectionBehaviorTest { - Component component; - Injector injector; - InjectorFactory injectorFactory; + private Component component; + private Injector injector; + private InjectorFactory injectorFactory; @Before public void setUp() { @@ -54,20 +54,22 @@ public class InjectionBehaviorTest { @Test public void testNoInjectionInitially() { InjectionBehavior behavior = new InjectionBehavior(); - behavior.beforeRender(component); + behavior.beforeRender(component); verifyNoMoreInteractions(injector); } - + @Test - public void testInjectOnlyOnceAfterDeserialisation() throws Exception { + public void testInjectOnlyOnceAfterDeserialisation() throws Exception { InjectionBehavior behavior = new InjectionBehavior(); - - behavior = ObjectSerializationUtils.deserialize(ObjectSerializationUtils.serialize(behavior), InjectionBehavior.class); - - behavior.beforeRender(component); + + behavior = ObjectSerializationUtils.deserialize( + ObjectSerializationUtils.serialize(behavior), + InjectionBehavior.class); + + behavior.beforeRender(component); verify(injector).inject(same(component)); reset(injector); - behavior.beforeRender(component); + behavior.beforeRender(component); verifyNoMoreInteractions(injector); } diff --git a/wicket/joe/src/test/java/org/wamblee/wicket/inject/TestInjectorFactory.java b/wicket/joe/src/test/java/org/wamblee/wicket/inject/TestInjectorFactory.java index 91949143..a650b513 100644 --- a/wicket/joe/src/test/java/org/wamblee/wicket/inject/TestInjectorFactory.java +++ b/wicket/joe/src/test/java/org/wamblee/wicket/inject/TestInjectorFactory.java @@ -19,19 +19,19 @@ import org.wamblee.inject.Injector; import org.wamblee.inject.InjectorFactory; public class TestInjectorFactory implements InjectorFactory { - - private static Injector MOCK_INJECTOR; - - public TestInjectorFactory() { - // Empty. + + private static Injector MOCK_INJECTOR; + + public TestInjectorFactory() { + // Empty. } - + public static void setMockInjector(Injector aMockInjector) { MOCK_INJECTOR = aMockInjector; } @Override public Injector create(Class aClass) { - return MOCK_INJECTOR; + return MOCK_INJECTOR; } } diff --git a/wicket/joe/src/test/java/org/wamblee/wicket/model/DetachableEntityTest.java b/wicket/joe/src/test/java/org/wamblee/wicket/model/DetachableEntityTest.java index 3346be63..218d0d6a 100644 --- a/wicket/joe/src/test/java/org/wamblee/wicket/model/DetachableEntityTest.java +++ b/wicket/joe/src/test/java/org/wamblee/wicket/model/DetachableEntityTest.java @@ -20,20 +20,20 @@ import org.junit.Test; import org.wamblee.persistence.Detachable; import static org.mockito.Mockito.*; -import static junit.framework.TestCase.*; +import static junit.framework.TestCase.*; public class DetachableEntityTest { - - public static class X { - + + public static class X { + } - - private X initialValue; + + private X initialValue; private Detachable detachable; - private DetachableEntity entity; - + private DetachableEntity entity; + @Before - public void setUp() { + public void setUp() { initialValue = mock(X.class); detachable = mock(Detachable.class); when(detachable.get()).thenReturn(initialValue); @@ -42,7 +42,7 @@ public class DetachableEntityTest { @Test public void testGetObject() { - X x = new X(); + X x = new X(); reset(detachable); when(detachable.get()).thenReturn(x); X value = entity.getObject(); @@ -53,23 +53,23 @@ public class DetachableEntityTest { @Test public void testOnDetachReattach() { - X x = new X(); + X x = new X(); when(detachable.get()).thenReturn(x); - + entity.detach(); verify(detachable).detach(); - + reset(detachable); when(detachable.get()).thenReturn(x); - + X y = entity.getObject(); - assertSame(x, y); + assertSame(x, y); verify(detachable).get(); } @Test(expected = UnsupportedOperationException.class) public void testSetObject() { - X x = new X(); + X x = new X(); entity.setObject(x); } } diff --git a/wicket/joe/src/test/java/org/wamblee/wicket/transactions/MyPage.java b/wicket/joe/src/test/java/org/wamblee/wicket/transactions/MyPage.java index 99af4844..2efb8561 100644 --- a/wicket/joe/src/test/java/org/wamblee/wicket/transactions/MyPage.java +++ b/wicket/joe/src/test/java/org/wamblee/wicket/transactions/MyPage.java @@ -5,8 +5,8 @@ package org.wamblee.wicket.transactions; import org.apache.wicket.markup.html.WebPage; -public class MyPage extends WebPage { - public MyPage() { - OpenTransactionInViewRequestCycleTest.BEHAVIOR.run(); +public class MyPage extends WebPage { + public MyPage() { + OpenTransactionInViewRequestCycleTest.getBEHAVIOR().run(); } } \ No newline at end of file diff --git a/wicket/joe/src/test/java/org/wamblee/wicket/transactions/OpenTransactionInViewRequestCycleTest.java b/wicket/joe/src/test/java/org/wamblee/wicket/transactions/OpenTransactionInViewRequestCycleTest.java index ca9ede10..e14bc332 100644 --- a/wicket/joe/src/test/java/org/wamblee/wicket/transactions/OpenTransactionInViewRequestCycleTest.java +++ b/wicket/joe/src/test/java/org/wamblee/wicket/transactions/OpenTransactionInViewRequestCycleTest.java @@ -43,7 +43,11 @@ public class OpenTransactionInViewRequestCycleTest { private UserTransaction userTransaction; private WicketTester wicket; - public static Runnable BEHAVIOR; + private static Runnable BEHAVIOR; + + public static Runnable getBEHAVIOR() { + return BEHAVIOR; + } @Before public void setUp() throws Exception {