AdminHelper { static String prettifyException(Exception e) { if (e.getLocalizedMessage() != null) { return e.getClass().getSimpleName() + ": " + e.getLocalizedMessage().split("\n")[0]; } else if (e.getStackTrace() != null && e.getStackTrace().length > 0) { return e.getClass().getSimpleName() + " at " + e.getStackTrace()[0]; } else { return e.getClass().getSimpleName(); } }  static DistributedFileSystem getDFS(Configuration conf);  }
@Test public void prettifyExceptionWithNpe() { String pretty = AdminHelper.prettifyException(new NullPointerException()); Assert.assertTrue( "Prettified exception message doesn't contain the required exception " + "message", pretty.startsWith("NullPointerException at org.apache.hadoop.hdfs.tools" + ".TestAdminHelper.prettifyExceptionWithNpe")); }
@Test public void prettifyException() { String pretty = AdminHelper.prettifyException( new IllegalArgumentException("Something is wrong", new IllegalArgumentException("Something is illegal"))); Assert.assertEquals( "IllegalArgumentException: Something is wrong", pretty); }