Longs { public static Long parseDecimal(final String s) { Long parsed = null; try { if (s != null) { parsed = (long) Double.parseDouble(s); } } catch (final NumberFormatException e) { } return parsed; } private  Longs(); static Long parseDecimal(final String s);  }
@Test public void testParseDecimal() { final String nullString = null; final String emptyString = ""; final String longString = String.valueOf(Long.MAX_VALUE); final String decimalString = String.valueOf(Double.MAX_VALUE); assertThat(Longs.parseDecimal(nullString), is(nullValue())); assertThat(Longs.parseDecimal(emptyString), is(nullValue())); assertThat(Longs.parseDecimal(longString), is(Long.MAX_VALUE)); assertThat(Longs.parseDecimal(decimalString), is((long) Double.MAX_VALUE)); }