/* ======================================================================
   Parts Copyright 2006 University of Leeds, Oxford University, University of the Highlands and Islands.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

====================================================================== */

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());
    }

}
