Size { public static Size parse(String providedLongWithUnitString) throws Exception { if (providedLongWithUnitString.equalsIgnoreCase(UNKNOWN)) { return new Size(Unit.NoUnit, UNKNOWN_VALUE); } if (providedLongWithUnitString.equalsIgnoreCase(UNLIMITED)) { return new Size(Unit.NoUnit, UNLIMITED_VALUE); } char lastChar = providedLongWithUnitString.charAt(providedLongWithUnitString.length() - 1); Unit unit = getUnit(lastChar); String argWithoutUnit = removeLastCharIfNeeded(providedLongWithUnitString, unit); return new Size(unit, Long.parseLong(argWithoutUnit)); } private  Size(Unit unit, Long value); static Size parse(String providedLongWithUnitString); Unit getUnit(); Long getValue(); long asBytes(); static final String UNKNOWN; static final String UNLIMITED; static final long UNKNOWN_VALUE; static final long UNLIMITED_VALUE; }
@Test void testBadUnit() { assertThatThrownBy(() -> Size.parse("42T")) .isInstanceOf(Exception.class); }
@Test void testWrongNumber() { assertThatThrownBy(() -> Size.parse("42RG")) .isInstanceOf(NumberFormatException.class); }