示例#1
0
  @Test
  public void testGetCurrentReturnsStandardByDefault() {
    StringWriter standard = new StringWriter();
    RenderContext renderContext = new RenderContextImpl(standard, null);

    Appendable actual = renderContext.getCurrent();
    assertSame(standard, actual);
  }
示例#2
0
  @Test
  public void testPushScriptSwithCurrentToScript() {
    StringWriter script = new StringWriter();
    RenderContext renderContext = new RenderContextImpl(null, script);

    renderContext.pushScript();

    Appendable actual = renderContext.getCurrent();
    assertSame(script, actual);
  }
示例#3
0
  @Test
  public void testGetScriptReturnsScriptContentWhenCurrentIsStandard() {
    String expected = "script content";
    StringWriter script = new StringWriter();
    script.append(expected);
    // current is standard by default
    RenderContext renderContext = new RenderContextImpl(null, script);

    String actual = renderContext.getScript();
    assertEquals(expected, actual);
  }
示例#4
0
  @Test
  public void testGetStandardRetunsStandardContent() throws Exception {
    String expected = "standard content";
    StringWriter standard = new StringWriter();
    RenderContext renderContext = new RenderContextImpl(standard, null);

    Appendable current = renderContext.getCurrent();
    current.append(expected);

    String actual = renderContext.getStandard();
    assertEquals(expected, actual);
  }
示例#5
0
  @Test
  public void testPopScriptSwitchCurrentToStandard() {
    StringWriter standard = new StringWriter();
    StringWriter script = new StringWriter();
    RenderContext renderContext = new RenderContextImpl(standard, script);
    renderContext.pushScript();

    renderContext.popScript();

    Appendable actual = renderContext.getCurrent();
    assertSame(standard, actual);
  }
示例#6
0
  @Test
  public void testExceptionIsThrownWhenPopScriptMoreThanPush() {
    StringWriter script = new StringWriter();
    RenderContext renderContext = new RenderContextImpl(null, script);

    try {
      renderContext.popScript();
    } catch (Exception e) {
      String expectedMessage = "Script popped too many times";
      this.checkExceptionFull(e, RuntimeException.class, expectedMessage);
    }
  }
示例#7
0
  @Test
  public void testGetScriptReturnsScriptContent() throws Exception {
    String expected = "script content";
    StringWriter script = new StringWriter();
    RenderContext renderContext = new RenderContextImpl(null, script);

    renderContext.pushScript();
    Appendable current = renderContext.getCurrent();
    current.append(expected);

    String actual = renderContext.getScript();
    assertEquals(expected, actual);
  }
示例#8
0
 @Test
 public void testGetStandardWhenStandardIsNull() throws Exception {
   RenderContext renderContext = new RenderContextImpl(null, null);
   String actual = renderContext.getStandard();
   assertNull(actual);
 }