Stringnifier { public static String simpleNameFor(AccessibleObject object) { if (object instanceof Method) { Method method = (Method) object; return method.getDeclaringClass().getSimpleName() + '.' + method.getName() + argumentsToString(method.getParameterTypes()); } if (object instanceof Constructor<?>) { Constructor<?> constructor = (Constructor<?>) object; return constructor.getDeclaringClass().getSimpleName() + argumentsToString(constructor.getParameterTypes()); } throw new IllegalArgumentException("can only strignify constructors and methods"); } private  Stringnifier(); static String simpleNameFor(AccessibleObject object);  }
@Test public void returnSimpleNameOfMethodWithoutArguments() throws SecurityException, NoSuchMethodException { Method m = Object.class.getMethod("toString"); Assert.assertEquals("Object.toString()", Stringnifier.simpleNameFor(m)); }
@Test public void returnSimpleNameOConstructorWithoutArguments() throws SecurityException, NoSuchMethodException { Constructor<Object> c = Object.class.getConstructor(); Assert.assertEquals("Object()", Stringnifier.simpleNameFor(c)); }
@Test public void returnSimpleNameOfMethodWithArguments() throws SecurityException, NoSuchMethodException { Method m = Comparator.class.getMethod("compare", Object.class, Object.class); Assert.assertEquals("Comparator.compare(Object, Object)", Stringnifier.simpleNameFor(m)); }
@Test public void returnSimpleNameOfMethodWithArgumentsGenerics() throws SecurityException, NoSuchMethodException { Method m = X.class.getMethod("method", List.class); Assert.assertEquals("X.method(List)", Stringnifier.simpleNameFor(m)); }