ClassUtil { public static Object create(String className) throws ClassLoadException { Object object = null; Thread t = Thread.currentThread(); ClassLoader cl = t.getContextClassLoader(); try { object = cl.loadClass(className).newInstance(); } catch (InstantiationException e) { throw new ClassLoadException(e); } catch (IllegalAccessException e) { throw new ClassLoadException(e); } catch (ClassNotFoundException e) { throw new ClassLoadException(e); } return object; }  static Object create(String className); static Object create(String className,
                                 Object[] constructorParameter);  }
@Test public void testCreateString01() { String input = "java.lang.String"; try { Object obj = ClassUtil.create(input); assertEquals("java.lang.String", obj.getClass().getName()); } catch (ClassLoadException e) { fail(); } }
@Test public void testCreateString02() { String input = "jp.terasoluna.fw.util.ClassUtil"; try { Object obj = ClassUtil.create(input); assertEquals("jp.terasoluna.fw.util.ClassUtil", obj.getClass() .getName()); } catch (ClassLoadException e) { fail(); } }
@Test public void testCreateString03() { String input = "javax.swing.AbstractAction"; try { ClassUtil.create(input); fail(); } catch (ClassLoadException e) { if (e.getMessage().indexOf("InstantiationException") == -1) { fail(); } } }
@Test public void testCreateString04() { String input = "java.lang.Str"; try { ClassUtil.create(input); fail(); } catch (ClassLoadException e) { if (e.getMessage().indexOf("ClassNotFoundException") == -1) { fail(); } } }
@Test public void testCreateString05() { String input = "java.lang.Void"; try { ClassUtil.create(input); } catch (ClassLoadException e) { if (e.getMessage().indexOf("IllegalAccessException") == -1) { fail(); } } }
@Test public void testCreateStringObjectArray01() { String input = "java.lang.Integer"; try { Object obj = ClassUtil.create(input, new Object[] { "12" }); java.lang.Integer resultObj = (java.lang.Integer) obj; assertEquals("java.lang.Integer", obj.getClass().getName()); assertEquals("12", resultObj.toString()); } catch (ClassLoadException e) { fail(); } }
@Test public void testCreateStringObjectArray02() { String input = "java.lang.String"; try { Object obj = ClassUtil.create(input, new Object[] {}); java.lang.String resultObj = (java.lang.String) obj; assertEquals("java.lang.String", obj.getClass().getName()); assertEquals("", resultObj); } catch (ClassLoadException e) { fail(); } }
@Test public void testCreateStringObjectArray03() { String input = "java.util.Locale"; String language = "es"; String country = "MEXICO"; try { Object obj = ClassUtil.create(input, new Object[] { language, country }); java.util.Locale resultObj = (java.util.Locale) obj; assertEquals("java.util.Locale", obj.getClass().getName()); assertEquals("MEXICO", resultObj.getCountry()); assertEquals("es", resultObj.getLanguage()); } catch (ClassLoadException e) { fail(); } }
@Test public void testCreateStringObjectArray04() { String input = ClassUtil.class.getName(); try { Object obj = ClassUtil.create(input, new Object[] {}); assertEquals(input, obj.getClass().getName()); } catch (ClassLoadException e) { fail(); } }
@Test public void testCreateStringObjectArray05() { String input = "java.lang.Str"; try { ClassUtil.create(input, new Object[] {}); } catch (ClassLoadException e) { if (e.getMessage().indexOf("ClassNotFoundException") == -1) { fail(); } } }
@Test public void testCreateStringObjectArray06() { String input = "javax.swing.AbstractAction"; try { ClassUtil.create(input, new Object[] { "1", "2" }); } catch (ClassLoadException e) { if (e.getMessage().indexOf("InstantiationException") == -1) { fail(); } } }
@Test public void testCreateStringObjectArray07() { String input = "java.lang.String"; try { ClassUtil.create(input, new Object[] { null }); } catch (ClassLoadException e) { if (e.getMessage().indexOf("InvocationTargetException") == -1) { fail(); } } }
@Test public void testCreateStringObjectArray08() { String input = "java.lang.Void"; try { ClassUtil.create(input, new Object[] {}); } catch (ClassLoadException e) { if (e.getMessage().indexOf("IllegalArgumentException") == -1) { fail(); } if (e.getCause().getMessage().indexOf( "class name is java.lang.Void") == -1) { fail(); } } }