BorderTop extends AbstractCssProperty<BorderTop> implements StateChangeInformer<CssProperty> { public BorderTop setBorderTopWidth(final BorderTopWidth borderTopWidth) { final StringBuilder cssValueBuilder = new StringBuilder(); if (borderTopWidth != null) { final String borderTopWidthCssValue = borderTopWidth.getCssValue(); if (BorderTopWidth.INITIAL.equals(borderTopWidthCssValue) || BorderTopWidth.INHERIT.equals(borderTopWidthCssValue)) { throw new InvalidValueException( "borderTopWidth cannot have initial/inherit as its cssValue"); } cssValueBuilder.append(borderTopWidth.getCssValue()).append(' '); } if (borderTopStyle != null) { cssValueBuilder.append(borderTopStyle.getCssValue()).append(' '); } if (borderTopColor != null) { cssValueBuilder.append(borderTopColor.getCssValue()).append(' '); } final String trimmedCssValue = StringBuilderUtil .getTrimmedString(cssValueBuilder).toString(); cssValue = trimmedCssValue.isEmpty() ? INHERIT : trimmedCssValue; if (borderTopWidth != null && borderTopWidth.isAlreadyInUse() && !Objects.equals(this.borderTopWidth, borderTopWidth)) { if (LOGGER.isLoggable(Level.WARNING)) { LOGGER.warning( "the given borderTopWidth is already used by another object so a new object or the previous object (if it exists) of BorderTopWidth will be used"); } return setCssValue(cssValue); } if (this.borderTopWidth != null) { this.borderTopWidth.setAlreadyInUse(false); } this.borderTopWidth = borderTopWidth; if (this.borderTopWidth != null) { this.borderTopWidth.setStateChangeInformer(this); this.borderTopWidth.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 testSetBorderTopWidth() { BorderTop border = new BorderTop(); border.setCssValue("thick solid green"); assertEquals("thick solid green", border.getCssValue()); final BorderTopWidth borderTopWidth = border.getBorderTopWidth(); assertTrue(borderTopWidth.isAlreadyInUse()); assertEquals("thick", borderTopWidth.getCssValue()); border.setBorderTopWidth(new BorderTopWidth()); border.setCssValue("solid green"); assertNull(border.getBorderTopWidth()); assertFalse(borderTopWidth.isAlreadyInUse()); assertEquals("solid green", border.getCssValue()); }
@Test(expected = InvalidValueException.class) public void testSetBorderTopWidthInvalidValue() { BorderTop border = new BorderTop(); border.setBorderTopWidth(new BorderTopWidth("initial")); }