ClassCreation { @SuppressWarnings("rawtypes") public static Object createObject(String label) throws NoSuchMethodException { Class className = Parameters.parameters.classParameter(label); if (className == null) { System.out.println("Error: Class Name null for label: " + label); return null; } return createObject(className); }  @SuppressWarnings("rawtypes") // Any type is possible, so it must be raw static Object createObject(String label); @SuppressWarnings({ "rawtypes", "unchecked" }) // Any type is possible, so it must be raw static Object createObject(Class className); @SuppressWarnings("rawtypes") // Any type is possible, so it must be raw static Object createObject(Constructor constructor); @SuppressWarnings("rawtypes") // Any type is possible, so it must be raw static Object createObject(Constructor constructor, Object[] arguments);  }
@Test public void testCreateObjectConstructor() throws NoSuchMethodException, SecurityException { Constructor<Point> pointConstructor = Point.class.getConstructor(new Class[0]); Point p = null; p = (Point) ClassCreation.createObject(pointConstructor); assertNotNull(p); assertEquals(p, new Point(0,0)); }
@Test public void testCreateObjectConstructorObjectArray() throws NoSuchMethodException, SecurityException { Constructor<Point> pointConstructor = Point.class.getConstructor(new Class[0]); Point p = null; p = (Point) ClassCreation.createObject(pointConstructor, new Object[0]); assertNotNull(p); assertEquals(p, new Point(0,0)); pointConstructor = Point.class.getConstructor(new Class[]{Integer.TYPE, Integer.TYPE}); p = null; p = (Point) ClassCreation.createObject(pointConstructor, new Object[]{4,5}); assertNotNull(p); assertEquals(p, new Point(4,5)); }
@Test public void testCreateObjectString() throws NoSuchMethodException { Parameters.initializeParameterCollections(new String[] { "io:false", "netio:false", "task:java.awt.Point", "substrateMapping:java.lang.String"}); Point p = null; p = (Point) ClassCreation.createObject("task"); assertNotNull(p); assertEquals(p, new Point(0,0)); String s = null; s = (String) ClassCreation.createObject("substrateMapping"); assertNotNull(s); assertEquals(s, ""); }
@Test public void testCreateObjectClass() throws NoSuchMethodException { Point p = null; p = (Point) ClassCreation.createObject(Point.class); assertNotNull(p); assertEquals(p, new Point(0,0)); }