/* * 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.general.ObjectSerializationUtils; import org.wamblee.inject.Injector; import org.wamblee.inject.InjectorBuilder; import org.wamblee.inject.InjectorFactory; import static org.mockito.Mockito.*; public class InjectionBehaviorTest { private Component component; private Injector injector; private 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() { Component component = mock(Component.class); InjectionBehavior behavior = new InjectionBehavior(component); behavior.beforeRender(component); verifyNoMoreInteractions(injector); } @Test public void testInjectOnlyOnceAfterDeserialisation() throws Exception { Component component = mock(Component.class); InjectionBehavior behavior = new InjectionBehavior(component); behavior = ObjectSerializationUtils.deserialize( ObjectSerializationUtils.serialize(behavior), InjectionBehavior.class); verify(injector).inject(any(Component.class)); reset(injector); behavior.beforeRender(component); verifyNoMoreInteractions(injector); } }