Utils { public static long toLong(String num, long defaultValue) { if (num != null && !num.contains(" ")) { try (Scanner scanner = new Scanner(num)) { if (scanner.hasNextLong()) { return Long.parseLong(num); } } } return defaultValue; } private  Utils(); static String readFile(File file, String charsetName); static String readStream(InputStream is, String charsetName); static void delete(File file); static int toInt(String num, int defaultValue); static int toIntHex(String num, int defaultValue); static long toLong(String num, long defaultValue); static long toLong(Long num, long defaultValue); static float toFloat(String num, float defaultValue); static String getJspEncoding(InputStream is); static void sendFile(HttpServletRequest request, HttpServletResponse response, File file); static Thread getThreadByName(String name); static String highlightStream(String name, InputStream input, String rendererName,
      String encoding); static void sendCompressedFile(HttpServletResponse response, File file); static List<String> getNamesForLocale(String baseName, Locale locale); static boolean isThreadingEnabled();  }
@Test public void toLongTest() { Assertions.assertEquals(5L, Utils.toLong("garbage", 5L)); Assertions.assertEquals(3L, Utils.toLong("3", 5L)); Assertions.assertEquals(5L, Utils.toLong("3 3", 5L)); Assertions.assertEquals(5L, Utils.toLong((String) null, 5L)); }
@Test public void toLongIntTest() { Assertions.assertEquals(5, Utils.toLong((Long) null, 5)); Assertions.assertEquals(1, Utils.toLong(Long.valueOf(1), 5)); }