From 8be905cf2323e531927b1730e92e68613dbacbb9 Mon Sep 17 00:00:00 2001 From: erik Date: Fri, 30 Jul 2010 19:08:14 +0000 Subject: [PATCH] --- .../wicket/inject/InjectionBehaviorTest.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 wicket/joe/src/test/java/org/wamblee/wicket/inject/InjectionBehaviorTest.java 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 index 00000000..4a2fef21 --- /dev/null +++ b/wicket/joe/src/test/java/org/wamblee/wicket/inject/InjectionBehaviorTest.java @@ -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); + + } +} -- 2.31.1