Top extends AbstractCssProperty<Top> { @Override public Top setCssValue(final String cssValue) { final String previousCssValue = this.cssValue; try { if (cssValue == null) { throw new NullValueException( "null is an invalid value. The value format should be as for example 75px or 85%. Or, initial/inherit."); } else { final String trimmedCssValue = TagStringUtil .toLowerCase(StringUtil.strip(cssValue)); boolean invalidValue = true; for (final CssLengthUnit cssLengthUnit : CssLengthUnit .values()) { final String unit = cssLengthUnit.getUnit(); if (trimmedCssValue.endsWith(unit)) { final String valueOnly = trimmedCssValue .replaceFirst(unit, ""); try { value = Float.parseFloat(valueOnly); } catch (final NumberFormatException e) { break; } this.cssLengthUnit = cssLengthUnit; this.cssValue = cssValue; invalidValue = false; break; } } if (PREDEFINED_CONSTANTS.contains(trimmedCssValue)) { this.cssValue = trimmedCssValue; cssLengthUnit = null; value = null; invalidValue = false; } if (invalidValue) { throw new InvalidValueException(cssValue + " is an invalid value. The value format should be as for example 75px, 85%, initial, inherit etc.."); } } if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } } catch (final NumberFormatException e) { this.cssValue = previousCssValue; throw new InvalidValueException(cssValue + " is an invalid value. The value format should be as for example 75px or 85%. Or, initial/inherit.", e); } catch (final InvalidValueException e) { this.cssValue = previousCssValue; throw e; } return this; } Top();  Top(final String cssValue);  Top(final Top top);  Top(final float percent);  Top(final float value, final CssLengthUnit cssLengthUnit); Top setValue(final float value, final CssLengthUnit cssLengthUnit); void setPercent(final float percent); @Override String getCssName(); @Override String getCssValue(); @Override String toString(); Float getValue(); CssLengthUnit getUnit(); @Override Top setCssValue(final String cssValue); void setAsInitial(); void setAsInherit(); void setAsAuto(); static boolean isValid(final String cssValue); static final String AUTO; static final String INITIAL; static final String INHERIT; }
@Test(expected = InvalidValueException.class) public void testInvalidValueForSetCssValue() throws Exception { Top padding = new Top(); padding.setCssValue("--1px"); }