コード例 #1
0
  @Test
  public void shouldBuildFont() throws Exception {
    styledText = new StyledText("Blah");
    styledText.setupStyles(
        new HashMap<String, RichStyle>(), new RichStyle(), new MockStyleObserver());
    styledText.getStyle().setFontFace("Courier");
    styledText.getStyle().setFontStyle("plain");
    styledText.getStyle().setFontSize(12);

    Font font = styledText.getFont();

    final String name = font.getFontName();
    assertTrue(
        "Expected 'Courier' or 'Monospace.plain' but got '" + name + "'",
        "Courier".equals(name) || "Monospaced.plain".equals(name));
    assertEquals(12, font.getSize());
    assertEquals(true, font.isPlain());
  }
コード例 #2
0
  @Test
  public void shouldTeardownStyles() throws Exception {
    makeSampleStyles();
    styledText = new StyledText("Some Text", "fizz", "bang");
    styledText.setupStyles(styles, defaultStyle, new MockStyleObserver());

    styledText.teardownStyles();

    RichStyle style = styledText.getStyle();
    assertEquals(false, style1.hasObserver(style));
    assertEquals(false, style2.hasObserver(style));
    assertEquals(false, defaultStyle.hasObserver(style));
  }
コード例 #3
0
  @Test
  public void shouldNotBuildStylesMoreThanOnce() throws Exception {
    makeSampleStyles();
    StyleObserver observer = new MockStyleObserver();

    styledText = new StyledText("Some Text", "fizz", "bang");
    styledText.setupStyles(styles, defaultStyle, observer);
    styledText.setupStyles(styles, defaultStyle, observer);

    RichStyle style = styledText.getStyle();
    assertEquals(3, style.getExtentions().size());
    assertEquals(1, style.getObservers().size());
  }
コード例 #4
0
  @Test
  public void shouldBuildStyles() throws Exception {
    makeSampleStyles();
    StyleObserver observer = new MockStyleObserver();

    styledText = new StyledText("Some Text", "fizz", "bang");
    styledText.setupStyles(styles, defaultStyle, observer);

    RichStyle style = styledText.getStyle();
    assertSame(style1, style.getExtention(0));
    assertSame(style2, style.getExtention(1));
    assertSame(defaultStyle, style.getExtention(2));
    assertEquals(true, style.hasObserver(observer));
  }