PrimitiveTypeUtil { public static final Class<?> getPrimitiveClass(String typeName) { Assertion.on("typeName").mustNotBeEmpty(typeName); if (typeName.equals("byte")) return byte.class; if (typeName.equals("short")) return short.class; if (typeName.equals("int")) return int.class; if (typeName.equals("long")) return long.class; if (typeName.equals("char")) return char.class; if (typeName.equals("float")) return float.class; if (typeName.equals("double")) return double.class; if (typeName.equals("boolean")) return boolean.class; if (typeName.equals("void")) return void.class; throw new IllegalArgumentException("Not primitive type : " + typeName); } private  PrimitiveTypeUtil(); static final boolean isPrimitive(String typeName); static final Class<?> getPrimitiveClass(String typeName); static final String getTypeDefaultValue(String typeName);  }
@Test public void getPrimitiveClass_A$String() throws Exception { String[] args = new String[] { "byte", "short", "int", "long", "char", "float", "double", "boolean", "void", }; Class<?>[] expected = new Class<?>[] { byte.class, short.class, int.class, long.class, char.class, float.class, double.class, boolean.class, void.class, }; for (int i = 0; i < args.length; i++) { Class<?> actual = PrimitiveTypeUtil.getPrimitiveClass(args[i]); assertEquals(expected[i], actual); } try { PrimitiveTypeUtil.getPrimitiveClass("dummy"); fail("Expected Exception did not occurred!"); } catch (IllegalArgumentException e) { } }