### Question:
ClassUtil { public static String getClassName(Class cls) { if (cls == null) { return null; } return getClassName(cls.getName()); } private  ClassUtil(); static Class toClass(String str, ClassLoader loader); static Class toClass(String str, boolean resolve,
                                ClassLoader loader); static String getClassName(Class cls); static String getClassName(String fullName); static String getPackageName(Class cls); static String getPackageName(String fullName);  }### Answer:
@Test public void testGetClassName() { Assert.assertEquals("ClassUtilTest", ClassUtil.getClassName(ClassUtilTest.class)); Assert.assertEquals("ClassUtilTest$MyInnerClass", ClassUtil.getClassName(MyInnerClass.class)); Assert.assertEquals("ClassUtilTest$1", ClassUtil.getClassName(INSTANCE.getClass())); Assert.assertEquals("byte", ClassUtil.getClassName(byte.class)); Assert.assertEquals("char", ClassUtil.getClassName(char.class)); Assert.assertEquals("double", ClassUtil.getClassName(double.class)); Assert.assertEquals("float", ClassUtil.getClassName(float.class)); Assert.assertEquals("int", ClassUtil.getClassName(int.class)); Assert.assertEquals("long", ClassUtil.getClassName(long.class)); Assert.assertEquals("short", ClassUtil.getClassName(short.class)); Assert.assertEquals("boolean", ClassUtil.getClassName(boolean.class)); Assert.assertEquals("void", ClassUtil.getClassName(void.class)); Assert.assertEquals("long[]", ClassUtil.getClassName(long[].class)); Assert.assertEquals("long[][]", ClassUtil.getClassName(long[][].class)); Assert.assertEquals("float[][][]", ClassUtil.getClassName(float[][][].class)); Assert.assertEquals("ClassUtilTest[]", ClassUtil.getClassName(ClassUtilTest[].class)); Assert.assertEquals("ClassUtilTest$MyInnerClass[]", ClassUtil.getClassName(MyInnerClass[].class)); Assert.assertEquals("ClassUtilTest$MyInnerClass[][]", ClassUtil.getClassName(MyInnerClass[][].class)); }
@Test @Ignore("only needed for manual performance tests") public void testGetClassNamePerformance() { long start = System.nanoTime(); for (int i = 1; i < 10000000; i++) { ClassUtil.getClassName(MyInnerClass.class); } long stop = System.nanoTime(); System.out.println("took: " + TimeUnit.NANOSECONDS.toMillis(stop - start)); }