package com.github.ferstl.depgraph.dot;

import org.junit.Test;
import static org.junit.Assert.assertEquals;


public class LabelBuilderTest {

  @Test
  public void mixed() {
    String label = new LabelBuilder()
        .bold("bold text")
        .text("intermediate text")
        .italic("italic text")
        .newLine()
        .underline("underlined text")
        .text("intermediate text")
        .font()
        .color("red")
        .size(20)
        .name("Sans")
        .text("special")
        .text("intermediate text")
        .build();

    assertEquals(
        "<<b>bold text</b>"
            + "intermediate text"
            + "<i>italic text</i>"
            + "<br/>"
            + "<u>underlined text</u>"
            + "intermediate text"
            + "<font color=\"red\" face=\"Sans\" point-size=\"20\">special</font>"
            + "intermediate text>",
        label);
  }

  @Test
  public void htmlEscape() {
    String label = new LabelBuilder()
        .text("<foo>")
        .underline("&bar&")
        .build();

    assertEquals("<&lt;foo&gt;<u>&amp;bar&amp;</u>>", label);
  }
}

package com.github.ferstl.depgraph.dot;

import org.junit.Test;
import static org.junit.Assert.assertEquals;


public class LabelBuilderTest {

  @Test
  public void mixed() {
    String label = new LabelBuilder()
        .bold("bold text")
        .text("intermediate text")
        .italic("italic text")
        .newLine()
        .underline("underlined text")
        .text("intermediate text")
        .font()
        .color("red")
        .size(20)
        .name("Sans")
        .text("special")
        .text("intermediate text")
        .build();

    assertEquals(
        "<<b>bold text</b>"
            + "intermediate text"
            + "<i>italic text</i>"
            + "<br/>"
            + "<u>underlined text</u>"
            + "intermediate text"
            + "<font color=\"red\" face=\"Sans\" point-size=\"20\">special</font>"
            + "intermediate text>",
        label);
  }

  @Test
  public void htmlEscape() {
    String label = new LabelBuilder()
        .text("<foo>")
        .underline("&bar&")
        .build();

    assertEquals("<&lt;foo&gt;<u>&amp;bar&amp;</u>>", label);
  }

  @Test
  public void fontName() {
    String label = new LabelBuilder()
        .font()
        .name("Helvetica")
        .text("text")
        .build();

    assertEquals("<<font face=\"Helvetica\">text</font>>", label);
  }

  @Test
  public void fontSize() {
    String label = new LabelBuilder()
        .font()
        .size(10)
        .text("text")
        .build();

    assertEquals("<<font point-size=\"10\">text</font>>", label);
  }

  @Test(expected = IllegalArgumentException.class)
  public void fontSizeNegative() {
    new LabelBuilder()
        .font()
        .size(-1);
  }

  @Test
  public void fontColor() {
    String label = new LabelBuilder()
        .font()
        .color("red")
        .text("text")
        .build();

    assertEquals("<<font color=\"red\">text</font>>", label);
  }

  @Test
  public void fontAll() {
    String label = new LabelBuilder()
        .font()
        .name("Helvetica")
        .color("green")
        .size(12)
        .text("text")
        .build();

    assertEquals("<<font color=\"green\" face=\"Helvetica\" point-size=\"12\">text</font>>", label);
  }
}

Add tests for fonts