1 package org.picocontainer.tck; 2 3 import junit.framework.TestCase; 4 5 import java.lang.reflect.Constructor; 6 import java.lang.reflect.InvocationTargetException; 7 import java.util.Arrays; 8 9 public abstract class AbstractNullConstructionTestCase extends TestCase { 10 11 protected abstract Class getContainerClass(); 12 13 protected abstract Object[] getContainersInstantiationParameters(); 14 15 public void testContainerInstansiable() throws InvocationTargetException, 16 IllegalAccessException, InstantiationException { 17 Class container = getContainerClass(); 18 Constructor ctor = container.getConstructors()[0]; 19 ctor.newInstance(getContainersInstantiationParameters()); 20 } 21 22 public void testContainerNotInstansiableWillNullParams() throws InvocationTargetException, 23 IllegalAccessException, InstantiationException { 24 Class container = getContainerClass(); 25 Constructor ctor = container.getConstructors()[0]; 26 Object[] params = getContainersInstantiationParameters(); 27 for (int i = 0; i < params.length; i++) { 28 Object[] testParams = (Object[]) params.clone(); 29 testParams[i] = null; 30 try { 31 ctor.newInstance(testParams); 32 fail("Should have barfed with NullPointerException"); 33 } catch (InvocationTargetException ite) { 34 if (ite.getTargetException() instanceof NullPointerException) { 35 // expected 36 } else { 37 throw ite; 38 } 39 } 40 } 41 } 42 43 44 }

This page was automatically generated by Maven