public ElementStyle findElementStyle(Element element) { ElementStyle style = new ElementStyle("").background("#dddddd").color("#000000").shape(Shape.Box); if (element != null) { for (String tag : element.getTagsAsSet()) { ElementStyle elementStyle = findElementStyle(tag); if (elementStyle != null) { if (elementStyle.getBackground() != null && elementStyle.getBackground().trim().length() > 0) { style.setBackground(elementStyle.getBackground()); } if (elementStyle.getColor() != null && elementStyle.getColor().trim().length() > 0) { style.setColor(elementStyle.getColor()); } if (elementStyle.getShape() != null) { style.setShape(elementStyle.getShape()); } } } } return style; }
protected String backgroundOf(View view, Element element) { return view.getViewSet().getConfiguration().getStyles().findElementStyle(element).getBackground(); }
@Test public void test_background_SetsTheBackgroundProperty_WhenAValidHexColorCodeIsSpecified() { ElementStyle style = new ElementStyle(); style.background("#ffffff"); assertEquals("#ffffff", style.getBackground()); style.background("#FFFFFF"); assertEquals("#ffffff", style.getBackground()); style.background("#123456"); assertEquals("#123456", style.getBackground()); }
@Test public void test_setBackground_SetsTheBackgroundProperty_WhenAValidHexColorCodeIsSpecified() { ElementStyle style = new ElementStyle(); style.setBackground("#ffffff"); assertEquals("#ffffff", style.getBackground()); style.setBackground("#FFFFFF"); assertEquals("#ffffff", style.getBackground()); style.setBackground("#123456"); assertEquals("#123456", style.getBackground()); }
@Test public void test_findElementStyle_ReturnsTheDefaultStyle_WhenPassedNull() { ElementStyle style = styles.findElementStyle(null); assertEquals("#dddddd", style.getBackground()); assertEquals("#000000", style.getColor()); assertEquals(Shape.Box, style.getShape()); }
@Test public void test_findElementStyle_ReturnsTheDefaultStyle_WhenNoStylesAreDefined() { SoftwareSystem element = model.addSoftwareSystem("Name", "Description"); ElementStyle style = styles.findElementStyle(element); assertEquals("#dddddd", style.getBackground()); assertEquals("#000000", style.getColor()); assertEquals(Shape.Box, style.getShape()); }
@Test public void test_findElementStyle_ReturnsTheCorrectStyle_WhenStylesAreDefined() { SoftwareSystem element = model.addSoftwareSystem("Name", "Description"); element.addTags("Some Tag"); styles.addElementStyle(Tags.SOFTWARE_SYSTEM).background("#ff0000").color("#ffffff"); styles.addElementStyle("Some Tag").color("#0000ff").shape(Shape.RoundedBox); ElementStyle style = styles.findElementStyle(element); assertEquals("#ff0000", style.getBackground()); assertEquals("#0000ff", style.getColor()); assertEquals(Shape.RoundedBox, style.getShape()); }