Util { public static long parseTimestamp(String timestampString) { try { Date date = Constant.DATE_FORMAT_ARGS.parse(timestampString); if (date.compareTo(new Date(System.currentTimeMillis())) > 0) throw new IllegalArgumentException(Constant.MESSAGE_INVALID_DATE_FORMAT); return date.getTime(); } catch (ParseException e) { throw new IllegalArgumentException(Constant.MESSAGE_INVALID_DATE_FORMAT); } } private  Util(); static void setLoggingThreshold(String loggingLevel); static void validateTable(HBaseAdmin admin, String tableName); static boolean isMoved(HBaseAdmin admin, String tableName, String regionName, String serverNameTarget); static boolean existsRegion(String regionName, Set<HRegionInfo> regionLocations); static boolean askProceed(); static long printVerboseMessage(Args args, String message, long startTimestamp); static void printVerboseMessage(Args args, String message); static void printMessage(String message); static String getResource(String rsc); static String readFromResource(String fileName); static String readFromFile(String fileName); static boolean isFile(String path); static Set<String> parseTableSet(HBaseAdmin admin, Args args); @SuppressWarnings("deprecation") static String getRegionInfoString(HRegionInfo regionA); static void sendAlertAfterFailed(Args args, Class clazz, String message); static void sendAlertAfterSuccess(Args args, Class clazz); static void sendAlertAfterSuccess(Args args, Class clazz, String message); static void sendAlertAfterFinish(Args args, Class clazz, String message, boolean success); static String getMethodName(); static long parseTimestamp(String timestampString); static boolean askProceedInteractively(Args args, boolean printNewLine); static final SimpleDateFormat DATE_FORMAT; }
@Test public void testParseTimestamp() throws Exception { try { Util.parseTimestamp("0"); Assert.fail(); } catch (IllegalArgumentException e) { if (!e.getMessage().contains(Constant.MESSAGE_INVALID_DATE_FORMAT)) { throw e; } } try { Util.parseTimestamp("20200101000000"); Assert.fail(); } catch (IllegalArgumentException e) { if (!e.getMessage().contains(Constant.MESSAGE_INVALID_DATE_FORMAT)) { throw e; } } Assert.assertEquals("20151130102200", Constant.DATE_FORMAT_ARGS.format(new Date(Util.parseTimestamp("20151130102200")))); }