BackgroundColor extends AbstractCssProperty<BackgroundColor> implements StateChangeInformer<Bean> { public void setRgbCssValue(final RgbCssValue rgbCssValue) { if (rgbCssValue == null) { throw new NullValueException("rgbCssValue can not be null"); } if (this.rgbCssValue != null) { if (rgbCssValue.isAlreadyInUse() && !Objects.equals( this.rgbCssValue.getStateChangeInformer(), rgbCssValue.getStateChangeInformer())) { try { final RgbCssValue rgbCssValueClone = CloneUtil .deepClone(rgbCssValue); this.rgbCssValue.setAlreadyInUse(false); this.rgbCssValue = rgbCssValueClone; if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("cloned rgbCssValue " + rgbCssValue + "(hashcode: " + rgbCssValue.hashCode() + ") as it is already used by another object"); } } catch (final CloneNotSupportedException e) { throw new InvalidValueException(e.toString()); } } else { this.rgbCssValue.setAlreadyInUse(false); this.rgbCssValue = rgbCssValue; } } else { if (rgbCssValue.isAlreadyInUse()) { try { this.rgbCssValue = CloneUtil.deepClone(rgbCssValue); if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning("cloned rgbCssValue " + rgbCssValue + "(hashcode: " + rgbCssValue.hashCode() + ") as it is already used by another object"); } } catch (final CloneNotSupportedException e) { throw new InvalidValueException(e.toString()); } } else { this.rgbCssValue = rgbCssValue; } } cssValue = this.rgbCssValue.getValue(); this.rgbCssValue.setStateChangeInformer(this); this.rgbCssValue.setAlreadyInUse(true); makeRgbaCssValueNull(); makeHslCssValueNull(); makeHslaCssValueNull(); } BackgroundColor();  BackgroundColor(final String cssValue);  BackgroundColor(final BackgroundColor backgroundColor);  BackgroundColor(final RgbCssValue rgbCssValue); BackgroundColor setValue(final String value); @Override String getCssName(); @Override String getCssValue(); @Override String toString(); String getValue(); @Override BackgroundColor setCssValue(final String cssValue); void setAsInitial(); void setAsInherit(); void setAsTransparent(); static boolean isValid(final String cssValue); @Override void stateChanged(final Bean stateChangedObject); RgbCssValue getRgbCssValue(); RgbaCssValue getRgbaCssValue(); HslCssValue getHslCssValue(); HslaCssValue getHslaCssValue(); void setRgbCssValue(final RgbCssValue rgbCssValue); void setRgbaCssValue(final RgbaCssValue rgbaCssValue); void setHslCssValue(final HslCssValue hslCssValue); void setHslaCssValue(final HslaCssValue hslaCssValue); static final String INITIAL; static final String INHERIT; static final String TRANSPARENT; }
@Test public void testSetRgbCssValue() { try { { BackgroundColor backgroundColor = new BackgroundColor(); RgbCssValue rgbCssValue = new RgbCssValue("rgb(15, 25, 255)"); backgroundColor.setRgbCssValue(rgbCssValue); backgroundColor.setRgbCssValue(rgbCssValue); assertEquals(CssNameConstants.BACKGROUND_COLOR + ": rgb(15, 25, 255)", backgroundColor.toString()); assertEquals("rgb(15, 25, 255)", backgroundColor.getCssValue()); BackgroundColor backgroundColor2 = new BackgroundColor(); backgroundColor2.setRgbCssValue(rgbCssValue); RgbCssValue rgbCssValueClone = backgroundColor2.getRgbCssValue(); assertNotEquals(backgroundColor.getRgbCssValue(), rgbCssValueClone); RgbCssValue rgbCssValue2 = new RgbCssValue("rgb(55, 5, 255)"); backgroundColor2.setRgbCssValue(rgbCssValue2); assertNotEquals(rgbCssValueClone, backgroundColor2.getRgbCssValue()); assertEquals(rgbCssValue2, backgroundColor2.getRgbCssValue()); backgroundColor2.setAsTransparent(); assertEquals(BackgroundColor.TRANSPARENT, backgroundColor2.getCssValue()); assertNull(backgroundColor2.getRgbCssValue()); assertFalse(rgbCssValue2.isAlreadyInUse()); } { BackgroundColor color = new BackgroundColor(); RgbCssValue rgbCssValue = new RgbCssValue("rgb(15, 25, 255)"); assertFalse(rgbCssValue.isAlreadyInUse()); color.setRgbCssValue(rgbCssValue); assertTrue(rgbCssValue.isAlreadyInUse()); RgbaCssValue rgbaCssValue = new RgbaCssValue("rgba(15, 25, 100, 1)"); assertFalse(rgbaCssValue.isAlreadyInUse()); color.setRgbaCssValue(rgbaCssValue); assertTrue(rgbaCssValue.isAlreadyInUse()); assertFalse(rgbCssValue.isAlreadyInUse()); assertNull(color.getRgbCssValue()); color.setAsInherit(); assertNull(color.getRgbaCssValue()); assertNull(color.getRgbCssValue()); assertNull(color.getHslCssValue()); assertNull(color.getHslaCssValue()); HslCssValue hslCssValue = new HslCssValue("hsl(15, 25%, 100%)"); assertFalse(hslCssValue.isAlreadyInUse()); color.setHslCssValue(hslCssValue); assertTrue(hslCssValue.isAlreadyInUse()); assertNull(color.getRgbaCssValue()); assertNull(color.getRgbCssValue()); assertNotNull(color.getHslCssValue()); assertNull(color.getHslaCssValue()); HslaCssValue hslaCssValue = new HslaCssValue("hsla(15, 25%, 100%, 1)"); assertFalse(hslaCssValue.isAlreadyInUse()); color.setHslaCssValue(hslaCssValue); assertTrue(hslaCssValue.isAlreadyInUse()); assertNull(color.getRgbaCssValue()); assertNull(color.getRgbCssValue()); assertNull(color.getHslCssValue()); assertNotNull(color.getHslaCssValue()); color.setAsInitial(); assertNull(color.getRgbaCssValue()); assertNull(color.getRgbCssValue()); assertNull(color.getHslCssValue()); assertNull(color.getHslaCssValue()); } } catch (Exception e) { e.printStackTrace(); fail(); } }