/*
 * Created on 31-Mar-2005
 */
package org.bodington.servlet;

import java.io.IOException;
import java.io.StringWriter;

import junit.framework.TestCase;

/**
 * @author buckett
 */
public class EscapedHtmlWriterTest extends TestCase
{

    private StringWriter output;
    private EscapedHtmlWriter writer;
    
    /*
     * @see TestCase#setUp()
     */
    protected void setUp() throws Exception
    {
        super.setUp();
        output = new StringWriter();
        writer = new EscapedHtmlWriter(output);
    }
    
    public void testWrite() throws IOException
    {
        writer.write("hello");
        writer.flush();
        assertEquals( "hello", output.toString());
    }
    
    public void testWriteMultiple() throws IOException
    {
        writer.write("hello");
        writer.write(" ");
        writer.write("world");
        writer.flush();
        assertEquals("hello world", output.toString());
    }
    
    public void testWriteAmp() throws IOException
    {
        writer.print("&");
        writer.flush();
        assertEquals("&amp;", output.toString());
    }
    
    public void testWriteLess() throws IOException
    {
        writer.write("<");
        writer.flush();
        assertEquals("&lt;", output.toString());
    }
    
    public void testWriteMore() throws IOException
    {
        writer.write(">");
        writer.flush();
        assertEquals("&gt;", output.toString());
    }
    
    public void testWriteQuote() throws IOException
    {
        writer.write("\"");
        writer.flush();
        assertEquals("&quot;", output.toString());
    }
    
    public void testWriteHTML() throws IOException
    {
        writer.write("<h1 class=\"test\">Me & Java</h1>");
        writer.flush();
        assertEquals("&lt;h1 class=&quot;test&quot;&gt;Me &amp; Java&lt;/h1&gt;", output.toString());
    }

}
