1 /****************************************************************************** 2 * Copyright (C) PicoContainer Organization. All rights reserved. * 3 * ------------------------------------------------------------------------- * 4 * The software in this package is published under the terms of the BSD * 5 * style license a copy of which has been included with this distribution in * 6 * the LICENSE.txt file. * 7 * * 8 * Idea by Rachel Davies, Original code by Aslak Hellesoy and Paul Hammant * 9 *****************************************************************************/ 10 11 package org.picocontainer.extras; 12 13 import junit.framework.TestCase; 14 import org.picocontainer.PicoInitializationException; 15 import org.picocontainer.defaults.DefaultComponentFactory; 16 import org.picocontainer.internals.ComponentSpecification; 17 18 import java.util.ArrayList; 19 import java.util.List; 20 21 public class ImplementationHidingComponentFactoryTestCase extends TestCase { 22 23 private static boolean addCalled = false; 24 25 public static class OneConstructorArrayList extends ArrayList { 26 public OneConstructorArrayList() { 27 super(); 28 } 29 30 public boolean add(Object o) { 31 addCalled = true; 32 return super.add(o); 33 } 34 } 35 36 public void testBasic() throws NoSuchMethodException, PicoInitializationException { 37 ImplementationHidingComponentFactory cf = new ImplementationHidingComponentFactory(new DefaultComponentFactory()); 38 Object o = cf.createComponent(new ComponentSpecification(cf, List.class, OneConstructorArrayList.class), null); 39 assertTrue(o instanceof List); 40 assertFalse(o instanceof OneConstructorArrayList); 41 ((List) o).add("hello"); 42 assertTrue("Add was called", addCalled); 43 } 44 45 }

This page was automatically generated by Maven