All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mockrunner.test.web.MockJspWriterTest Maven / Gradle / Ivy

Go to download

Mockrunner is a lightweight framework for unit testing applications in the J2EE environment. It supports servlets, filters, tag classes and Struts actions. It includes a JDBC a JMS and a JCA test framework and can be used to test EJB based applications.

The newest version!
package com.mockrunner.test.web;

import java.io.IOException;
import java.io.StringWriter;

import com.mockrunner.mock.web.MockJspWriter;

import junit.framework.TestCase;

public class MockJspWriterTest extends TestCase
{
    public void testWithDefaultWriter() throws Exception
    {
        MockJspWriter writer = new MockJspWriter();
        writer.print("test1");
        writer.clear();
        writer.print("test2");
        writer.clearBuffer();
        writer.print("test3");
        assertEquals("test3", writer.getOutputAsString());
    }
    
    public void testWithProvidedWriter() throws Exception
    {
        StringWriter providedWriter = new StringWriter();
        MockJspWriter writer = new MockJspWriter(providedWriter);
        writer.print("test1");
        try
        {
            writer.clear();
            fail();
        } 
        catch(IOException exc)
        {
            //should throw exception
        }
        writer.print("test2");
        writer.clearBuffer();
        writer.print("test3");
        assertEquals("", writer.getOutputAsString());
        writer.flush();
        assertEquals("test1test2test3", providedWriter.toString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy