(no commit message)
authorErik Brakkee <erik@brakkee.org>
Sat, 31 Jul 2010 17:33:59 +0000 (17:33 +0000)
committerErik Brakkee <erik@brakkee.org>
Sat, 31 Jul 2010 17:33:59 +0000 (17:33 +0000)
wicket/joe/src/main/java/org/wamblee/wicket/inject/ComponentInstantiationInjector.java
wicket/joe/src/main/java/org/wamblee/wicket/inject/InjectionBehavior.java
wicket/joe/src/main/java/org/wamblee/wicket/model/DetachableEntity.java
wicket/joe/src/main/java/org/wamblee/wicket/transactions/package-info.java
wicket/joe/src/test/java/org/wamblee/wicket/inject/ComponentInstantiationInjectorTest.java
wicket/joe/src/test/java/org/wamblee/wicket/inject/InjectionBehaviorTest.java
wicket/joe/src/test/java/org/wamblee/wicket/inject/TestInjectorFactory.java
wicket/joe/src/test/java/org/wamblee/wicket/model/DetachableEntityTest.java
wicket/joe/src/test/java/org/wamblee/wicket/transactions/MyPage.java
wicket/joe/src/test/java/org/wamblee/wicket/transactions/OpenTransactionInViewRequestCycleTest.java

index a4a0dcf96b4bbbac73a01581ffe8192bf78e3e08..cdda947daf8d3b4e8ab348e6a325605f499360d7 100644 (file)
@@ -23,39 +23,40 @@ import org.wamblee.inject.SimpleInjector;
 
 /**
  * <p>
- * 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.
  * </p>
  * 
  * <p>
- * To use this injector override {@link WebApplication#init()} and add the 
- * listener: 
+ * To use this injector override {@link WebApplication#init()} and add the
+ * listener:
  * </p>
+ * 
  * <pre>
- *    &#064;Override
- *    protected void init() {
- *       super.init();
- *       addComponentInstantiationListener(new ComponentInstantiationInjector());
- *    }
+ * &#064;Override
+ * protected void init() {
+ *     super.init();
+ *     addComponentInstantiationListener(new ComponentInstantiationInjector());
+ * }
  * </pre>
  * 
  * @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);
index 3d648c4e8c4da65a9fca7ca3c5997f9812035e5f..659be7a75a3fdbd90cbab7a6be898a8e8cd3fbf7 100644 (file)
@@ -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;
         }
     }
 }
index 11fe3abfd315ac5237f1a7d6d556e1185d0d89fa..5bde6cb6969bd2430ea0dea62490a1a8232853d8 100644 (file)
@@ -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<T> extends LoadableDetachableModel<T> {
-       
-       private Detachable<T> object;
-       
-       /**
-        * Constructs the model. 
-        * @param aObject Object to construct the model with. 
-        */
-       public DetachableEntity(Detachable<T> aObject) { 
-           super(aObject.get());
+
+    private Detachable<T> object;
+
+    /**
+     * Constructs the model.
+     * 
+     * @param aObject
+     *            Object to construct the model with.
+     */
+    public DetachableEntity(Detachable<T> 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");
+    }
 
 }
index aa536f7a1edeed5f6351fbeb0c6f80857854fd91..f2d66b793d58ec4567033cd1f07e3eda20311357 100644 (file)
@@ -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
index 5824c6dc2755ccb063956616142ac3fa85c13abb..59d59f69fdc4a305edf93aba45491a26ad35d1d7 100644 (file)
@@ -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));
     }
 
 }
index d5c62024137d8940d3b524d792c80a095ccc2829..d54de1ce4265af9f344611e97fc58df40d7e08b0 100644 (file)
@@ -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);
 
     }
index 91949143d2c8134be8c3466f2f252c5347a6a298..a650b5131daf5015af2cbf75afc847a91afbf355 100644 (file)
@@ -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;
     }
 }
index 3346be63e0ad23ef30ae1c49b13aaab5843d957d..218d0d6ac237a88ff7020cb639cb9f156c6e13e1 100644 (file)
@@ -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<X> detachable;
-    private DetachableEntity<X> entity; 
-    
+    private DetachableEntity<X> 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);
     }
 }
index 99af4844cd30ad9b69c69f21b1553eefd134c6b9..2efb856181486c57f061281c432055ae61c4409b 100644 (file)
@@ -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
index ca9ede10965609b6f821d82aed29d11f61d604ad..e14bc3323bcaaf72f82842182f471706b2e5a5dd 100644 (file)
@@ -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 {