(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Jul 2010 19:08:14 +0000 (19:08 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 30 Jul 2010 19:08:14 +0000 (19:08 +0000)
wicket/joe/src/test/java/org/wamblee/wicket/inject/InjectionBehaviorTest.java [new file with mode: 0644]

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
new file mode 100644 (file)
index 0000000..4a2fef2
--- /dev/null
@@ -0,0 +1,79 @@
+/*
+ * 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.wicket.inject;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.wicket.Component;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.wamblee.inject.Injector;
+import org.wamblee.inject.InjectorBuilder;
+import org.wamblee.inject.InjectorFactory;
+
+import static org.mockito.Mockito.*;
+
+public class InjectionBehaviorTest {
+
+    Component component;
+    Injector injector;
+    InjectorFactory injectorFactory;
+
+    @Before
+    public void setUp() {
+        component = mock(Component.class);
+        injector = mock(Injector.class);
+        injectorFactory = mock(InjectorFactory.class);
+        when(injectorFactory.create(any(Class.class))).thenReturn(injector);
+        InjectorBuilder.setInjectorFactory(injectorFactory);
+    }
+
+    @After
+    public void tearDown() {
+        InjectorBuilder.setInjectorFactory(null);
+    }
+
+    @Test
+    public void testNoInjectionInitially() {
+        InjectionBehavior behavior = new InjectionBehavior();
+        behavior.beforeRender(component); 
+        verifyNoMoreInteractions(injector);
+    }
+    
+    @Test
+    public void testInjectOnlyOnceAfterDeserialisation() throws Exception { 
+        InjectionBehavior behavior = new InjectionBehavior();
+        
+        ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
+        ObjectOutputStream os = new ObjectOutputStream(bos); 
+        os.writeObject(behavior);
+        os.flush();
+        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+        ObjectInputStream ois = new ObjectInputStream(bis); 
+        behavior = (InjectionBehavior)ois.readObject();
+        
+        behavior.beforeRender(component); 
+        verify(injector).inject(same(component));
+        reset(injector);
+        behavior.beforeRender(component); 
+        verifyNoMoreInteractions(injector);
+
+    }
+}