1 10 11 package org.picocontainer.defaults; 12 13 import org.picocontainer.ComponentAdapter; 14 import org.picocontainer.PicoContainer; 15 import org.picocontainer.PicoVisitor; 16 17 import org.jmock.Mock; 18 import org.jmock.MockObjectTestCase; 19 20 21 25 public class ImmutablePicoContainerProxyFactoryTest extends MockObjectTestCase { 26 27 public void testImmutingOfNullBarfs() { 28 try { 29 ImmutablePicoContainerProxyFactory.newProxyInstance(null); 30 fail("Should have barfed"); 31 } catch (NullPointerException e) { 32 } 34 } 35 36 public void testLifecylceBarfs() { 37 Mock mockPicoContainer = mock(PicoContainer.class); 38 PicoContainer ipc = ImmutablePicoContainerProxyFactory.newProxyInstance((PicoContainer)mockPicoContainer 39 .proxy()); 40 try { 41 ipc.start(); 42 fail("should have barfed"); 43 } catch (UnsupportedOperationException e) { 44 } 46 try { 47 ipc.stop(); 48 fail("should have barfed"); 49 } catch (UnsupportedOperationException e) { 50 } 52 try { 53 ipc.dispose(); 54 fail("should have barfed"); 55 } catch (UnsupportedOperationException e) { 56 } 58 } 59 60 public void testVisitingOfImmutableContainerWorks() { 61 DefaultPicoContainer pico = new DefaultPicoContainer(); 62 Object foo = new Object (); 63 ComponentAdapter componentAdapter = pico.registerComponentInstance(foo); 64 65 Mock fooVisitor = new Mock(PicoVisitor.class); 66 fooVisitor.expects(once()).method("visitContainer").with(same(pico)); 67 fooVisitor.expects(once()).method("visitComponentAdapter").with(same(componentAdapter)); 68 69 PicoContainer ipc = ImmutablePicoContainerProxyFactory.newProxyInstance(pico); 70 ipc.accept((PicoVisitor)fooVisitor.proxy()); 71 } 72 73 public void testProxyEquals() throws Exception { 74 DefaultPicoContainer pico = new DefaultPicoContainer(); 75 PicoContainer ipc = ImmutablePicoContainerProxyFactory.newProxyInstance(pico); 76 assertEquals(ipc, ipc); 77 assertEquals(ipc, ImmutablePicoContainerProxyFactory.newProxyInstance(pico)); 78 } 79 80 public void testHashCodeIsSame() throws Exception { 81 DefaultPicoContainer pico = new DefaultPicoContainer(); 82 PicoContainer ipc = ImmutablePicoContainerProxyFactory.newProxyInstance(pico); 83 assertEquals(ipc.hashCode(), ImmutablePicoContainerProxyFactory.newProxyInstance(pico).hashCode()); 84 } 85 86 public void testDoesNotEqualsToNull() { 87 DefaultPicoContainer pico = new DefaultPicoContainer(); 88 PicoContainer ipc = ImmutablePicoContainerProxyFactory.newProxyInstance(pico); 89 assertFalse(ipc.equals(null)); 90 } 91 } 92 | Popular Tags |