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();
    }
  }
@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"));
  }