BorderTop extends AbstractCssProperty<BorderTop> implements StateChangeInformer<CssProperty> { public BorderTop setBorderTopColor(final BorderTopColor borderTopColor) { final StringBuilder cssValueBuilder = new StringBuilder(); if (borderTopWidth != null) { cssValueBuilder.append(borderTopWidth.getCssValue()).append(' '); } if (borderTopStyle != null) { cssValueBuilder.append(borderTopStyle.getCssValue()).append(' '); } if (borderTopColor != null) { final String borderTopColorCssValue = borderTopColor.getCssValue(); if (BorderTopColor.INITIAL.equals(borderTopColorCssValue) || BorderTopColor.INHERIT.equals(borderTopColorCssValue)) { throw new InvalidValueException( "borderTopColor cannot have initial/inherit as its cssValue"); } cssValueBuilder.append(borderTopColorCssValue); } final String trimmedCssValue = StringBuilderUtil .getTrimmedString(cssValueBuilder).toString(); cssValue = trimmedCssValue.isEmpty() ? INHERIT : trimmedCssValue; if (borderTopColor != null && borderTopColor.isAlreadyInUse() && !Objects.equals(this.borderTopColor, borderTopColor)) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given borderTopColor is already used by another object so a new object or the previous object (if it exists) of BorderTopColor will be used"); } return setCssValue(cssValue); } if (this.borderTopColor != null) { this.borderTopColor.setAlreadyInUse(false); } this.borderTopColor = borderTopColor; if (this.borderTopColor != null) { this.borderTopColor.setStateChangeInformer(this); this.borderTopColor.setAlreadyInUse(true); } if (getStateChangeInformer() != null) { getStateChangeInformer().stateChanged(this); } return this; } BorderTop();  BorderTop(final String cssValue);  BorderTop(final BorderTop borderTop); @Override String getCssName(); @Override String getCssValue(); @Override String toString(); @Override BorderTop setCssValue(final String cssValue); static boolean isValid(final String cssValue); void setAsInitial(); void setAsInherit(); BorderTopColor getBorderTopColor(); BorderTopStyle getBorderTopStyle(); BorderTopWidth getBorderTopWidth(); BorderTop setBorderTopWidth(final BorderTopWidth borderTopWidth); BorderTop setBorderTopStyle(final BorderTopStyle borderTopStyle); BorderTop setBorderTopColor(final BorderTopColor borderTopColor); @Override void stateChanged(final CssProperty stateChangedObject); static final String INITIAL; static final String INHERIT; }
@Test public void testSetBorderTopColor() { BorderTop border = new BorderTop(); border.setCssValue("thick solid green"); assertEquals("thick solid green", border.getCssValue()); final BorderTopColor borderTopColor = border.getBorderTopColor(); assertTrue(borderTopColor.isAlreadyInUse()); assertEquals("green", borderTopColor.getCssValue()); border.setBorderTopColor(new BorderTopColor("blue")); assertEquals("thick solid blue", border.getCssValue()); border.setCssValue("thick solid"); assertNull(border.getBorderTopColor()); assertFalse(borderTopColor.isAlreadyInUse()); assertEquals("thick solid", border.getCssValue()); }
@Test(expected = InvalidValueException.class) public void testSetBorderTopColorInvalidValue() { BorderTop border = new BorderTop(); border.setBorderTopColor(new BorderTopColor()); }