1 /* 2 * Copyright (C) The JContainer Group. All rights reserved. 3 * 4 * This software is published under the terms of the JContainer 5 * Software License version 1.1, a copy of which has been included 6 * with this distribution in the LICENSE.txt file. 7 */ 8 package org.jcontainer.dna.impl; 9 10 import junit.framework.TestCase; 11 import org.jcontainer.dna.ResourceLocator; 12 13 public class ContainerUtilTestCase 14 extends TestCase 15 { 16 public void testEnableLoggingOnComponentNotImplementingStage() 17 throws Exception 18 { 19 final Object object = new Object(); 20 ContainerUtil.enableLogging( object, null ); 21 } 22 23 public void testEnableLoggingOnComponentImplementingStage() 24 throws Exception 25 { 26 final MockComponent object = new MockComponent(); 27 final ConsoleLogger logger = new ConsoleLogger(); 28 29 ContainerUtil.enableLogging( object, logger ); 30 31 assertEquals( logger, object.getLogger() ); 32 } 33 34 public void testEnableLoggingOnComponentImplementingStageButNullLogger() 35 throws Exception 36 { 37 final MockComponent object = new MockComponent(); 38 final ConsoleLogger logger = null; 39 40 try 41 { 42 ContainerUtil.enableLogging( object, logger ); 43 } 44 catch( IllegalArgumentException iae ) 45 { 46 return; 47 } 48 fail( "Expected stage to fail as passing in null " + 49 "resource but object implements stage." ); 50 } 51 52 public void testComposeOnComponentNotImplementingStage() 53 throws Exception 54 { 55 final Object object = new Object(); 56 ContainerUtil.compose( object, null ); 57 } 58 59 public void testComposeOnComponentImplementingStage() 60 throws Exception 61 { 62 final MockComponent object = new MockComponent(); 63 final ResourceLocator resource = new DefaultResourceLocator(); 64 65 ContainerUtil.compose( object, resource ); 66 67 assertEquals( resource, object.getServices() ); 68 } 69 70 public void testComposeOnComponentImplementingStageButNullLogger() 71 throws Exception 72 { 73 final MockComponent object = new MockComponent(); 74 final ResourceLocator resource = null; 75 76 try 77 { 78 ContainerUtil.compose( object, resource ); 79 } 80 catch( IllegalArgumentException iae ) 81 { 82 return; 83 } 84 fail( "Expected stage to fail as passing in null " + 85 "resource but object implements stage." ); 86 } 87 88 public void testParameterizeOnComponentNotImplementingStage() 89 throws Exception 90 { 91 final Object object = new Object(); 92 ContainerUtil.parameterize( object, null ); 93 } 94 95 public void testParameterizeOnComponentImplementingStage() 96 throws Exception 97 { 98 final MockComponent object = new MockComponent(); 99 final DefaultParameters resource = new DefaultParameters(); 100 101 ContainerUtil.parameterize( object, resource ); 102 103 assertEquals( resource, object.getParameters() ); 104 } 105 106 public void testParameterizeOnComponentImplementingStageButNullLogger() 107 throws Exception 108 { 109 final MockComponent object = new MockComponent(); 110 final DefaultParameters resource = null; 111 112 try 113 { 114 ContainerUtil.parameterize( object, resource ); 115 } 116 catch( IllegalArgumentException iae ) 117 { 118 return; 119 } 120 fail( "Expected stage to fail as passing in null " + 121 "resource but object implements stage." ); 122 } 123 124 public void testConfigureOnComponentNotImplementingStage() 125 throws Exception 126 { 127 final Object object = new Object(); 128 ContainerUtil.configure( object, null ); 129 } 130 131 public void testConfigureOnComponentImplementingStage() 132 throws Exception 133 { 134 final MockComponent object = new MockComponent(); 135 final DefaultConfiguration resource = new DefaultConfiguration( "s", "", "" ); 136 137 ContainerUtil.configure( object, resource ); 138 139 assertEquals( resource, object.getConfiguration() ); 140 } 141 142 public void testConfigureOnComponentImplementingStageButNullLogger() 143 throws Exception 144 { 145 final MockComponent object = new MockComponent(); 146 final DefaultConfiguration resource = null; 147 148 try 149 { 150 ContainerUtil.configure( object, resource ); 151 } 152 catch( IllegalArgumentException iae ) 153 { 154 return; 155 } 156 fail( "Expected stage to fail as passing in null " + 157 "resource but object implements stage." ); 158 } 159 160 public void testInitializeOnComponentNotImplementingStage() 161 throws Exception 162 { 163 final Object object = new Object(); 164 ContainerUtil.initialize( object ); 165 } 166 167 public void testInitializeOnComponentImplementingStage() 168 throws Exception 169 { 170 final MockComponent object = new MockComponent(); 171 ContainerUtil.initialize( object ); 172 assertEquals( true, object.isInitialized() ); 173 } 174 175 public void testDisposeOnComponentNotImplementingStage() 176 throws Exception 177 { 178 final Object object = new Object(); 179 ContainerUtil.dispose( object ); 180 } 181 182 public void testDisposeOnComponentImplementingStage() 183 throws Exception 184 { 185 final MockComponent object = new MockComponent(); 186 ContainerUtil.dispose( object ); 187 assertEquals( true, object.isDisposed() ); 188 } 189 }

This page was automatically generated by Maven