package com.wizzardo.http.framework.template;

import org.junit.Assert;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class RenderResultTest {

    @Test
    public void test_write() throws IOException {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        new RenderResult()
                .append("foo")
                .append("bar".getBytes(StandardCharsets.UTF_8))
                .write(out);

        Assert.assertEquals("foobar", out.toString());
    }

    @Test
    public void test_compact() throws IOException {
        RenderResult result = new RenderResult()
                .append("foo")
                .append("bar".getBytes(StandardCharsets.UTF_8));

        Assert.assertEquals(2, result.renders.size());

        Assert.assertEquals("foobar", new String(result.bytes()));
        Assert.assertEquals(null, result.renders);

        result.compact();
        Assert.assertEquals("foobar", new String(result.bytes()));
        Assert.assertEquals(null, result.renders);

        result.append("qwe");
        Assert.assertEquals(null, result.bytes);
        Assert.assertEquals("foobarqwe", result.toString());
    }
}
@@ -196,16 +196,66 @@
 harsets;
+%0Aimport java.util.concurrent.atomic.AtomicInteger;
 %0A%0Apublic
@@ -1293,10 +1293,249 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void test_provide_bytes_empty() %7B%0A        AtomicInteger counter = new AtomicInteger();%0A        new RenderResult().provideBytes(bytes -%3E counter.incrementAndGet());%0A        Assert.assertEquals(0, counter.get());%0A    %7D
 %0A%7D

improve tests