Utils { static Long numberOrDefault(String candidate, long defaultLong) { try { return Long.parseLong(candidate); } catch (NumberFormatException e) { return defaultLong; } } private  Utils();   }
@Test public void testNumberOrDefault_validNumber() { assertEquals(Long.valueOf(123), Utils.numberOrDefault("123", -1L)); }
@Test public void testNumberOrDefault_invalidNumber() { assertEquals(Long.valueOf(-1L), Utils.numberOrDefault("abc", -1L)); }