Opacity extends AbstractCssProperty<Opacity> { @Override public Opacity setCssValue(final String cssValue) { if (cssValue == null) { throw new NullValueException( "null is an invalid value. The value format should be as for example 0.5, initial/inherit."); } else { final String trimmedCssValue = TagStringUtil .toLowerCase(StringUtil.strip(cssValue)); if (INITIAL.equals(trimmedCssValue) || INHERIT.equals(trimmedCssValue)) { this.cssValue = trimmedCssValue; value = null; } else { try { final float tempValue = Float.valueOf(trimmedCssValue); if (tempValue < 0 || tempValue > 1) { throw new InvalidValueException( "The cssValue should be a number in between 0 to 1."); } value = tempValue; this.cssValue = value.toString(); } catch (final NumberFormatException e) { throw new InvalidValueException(cssValue + " is an invalid value. The value format should be as for example 0.5, initial, inherit etc.."); } } } if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } return this; } Opacity();  Opacity(final String cssValue);  Opacity(final Opacity opacity);  Opacity(final float value); @Override String getCssName(); @Override String getCssValue(); @Override String toString(); Float getValue(); void setValue(final float value); @Override Opacity setCssValue(final String cssValue); void setAsInitial(); void setAsInherit(); static boolean isValid(final String cssValue); static final String INITIAL; static final String INHERIT; }
@Test(expected = InvalidValueException.class) public void testSetCssValueInvalidValue1() throws Exception { try { new Opacity().setCssValue("1px"); } catch (Exception e) { throw e; } }
@Test(expected = InvalidValueException.class) public void testSetCssValueInvalidValue2() throws Exception { try { new Opacity().setCssValue("2"); } catch (Exception e) { throw e; } }