Ejemplo n.º 1
0
  @Test
  public void testGetCurrentReturnsStandardByDefault() {
    StringWriter standard = new StringWriter();
    RenderContext renderContext = new RenderContextImpl(standard, null);

    Appendable actual = renderContext.getCurrent();
    assertSame(standard, actual);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 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);
    }
  }
Ejemplo n.º 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);
  }
Ejemplo n.º 8
0
 @Test
 public void testGetStandardWhenStandardIsNull() throws Exception {
   RenderContext renderContext = new RenderContextImpl(null, null);
   String actual = renderContext.getStandard();
   assertNull(actual);
 }