NumberParser { public static Float parseFloat(final String str) { if (null != str) { try { return new Float(Float.parseFloat(str.trim())); } catch (final Exception e) { } } return null; } private  NumberParser(); static Long parseLong(final String str); static Integer parseInt(final String str); static Float parseFloat(final String str); static float parseFloat(final String str, final float def); static long parseLong(final String str, final long def);  }
@Test public void testFloatParseFailure() { Float num = NumberParser.parseFloat("Non Float"); assertNull(num); }
@Test public void testFloatParseSuccess() { Float num = NumberParser.parseFloat("1.0"); assertEquals(new Float(1.0f), num); }
@Test public void testFloatParseDefaultSuccess() { float num = NumberParser.parseFloat("Non Float", 1.0f); assertEquals(1.0f, num, 0); }
@Test public void testFloatParseNonDefaultSuccess() { float num = NumberParser.parseFloat("0.0", 1.0f); assertEquals(0.0f, num, 0); }