2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.wicket.inject;
18 import java.io.ByteArrayInputStream;
19 import java.io.ByteArrayOutputStream;
20 import java.io.ObjectInputStream;
21 import java.io.ObjectOutputStream;
23 import org.apache.wicket.Component;
24 import org.junit.After;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.wamblee.general.ObjectSerializationUtils;
28 import org.wamblee.inject.Injector;
29 import org.wamblee.inject.InjectorBuilder;
30 import org.wamblee.inject.InjectorFactory;
32 import static org.mockito.Mockito.*;
34 public class InjectionBehaviorTest {
38 InjectorFactory injectorFactory;
42 component = mock(Component.class);
43 injector = mock(Injector.class);
44 injectorFactory = mock(InjectorFactory.class);
45 when(injectorFactory.create(any(Class.class))).thenReturn(injector);
46 InjectorBuilder.setInjectorFactory(injectorFactory);
50 public void tearDown() {
51 InjectorBuilder.setInjectorFactory(null);
55 public void testNoInjectionInitially() {
56 InjectionBehavior behavior = new InjectionBehavior();
57 behavior.beforeRender(component);
58 verifyNoMoreInteractions(injector);
62 public void testInjectOnlyOnceAfterDeserialisation() throws Exception {
63 InjectionBehavior behavior = new InjectionBehavior();
65 behavior = ObjectSerializationUtils.deserialize(ObjectSerializationUtils.serialize(behavior), InjectionBehavior.class);
67 behavior.beforeRender(component);
68 verify(injector).inject(same(component));
70 behavior.beforeRender(component);
71 verifyNoMoreInteractions(injector);