devdaily home | apple | java | perl | unix | directory | blog

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

package tests;

import java.io.*;

import junit.framework.*;

import com.efsol.friki.*;

public class FilterTest extends TestCase
{
	protected PageRepository rep;
	protected ContentFilter filter;

	public FilterTest(String name)
	{
		super(name);
	}

	public void setUp()
	{
		rep = new PageRepository(new InMemoryRepository());
	}

	protected void setFilter(ContentFilter filter)
	{
		this.filter = filter;
	}

	protected String convert(String content)
	{
		StringWriter out = new StringWriter();
		try
		{
			filter.filter(new StringReader(content), out);
		}
		catch(IOException ioe)
		{
			ioe.printStackTrace();
		}

		return out.toString();
	}


	protected void check(String name, String expected, String source, boolean log)
	{
		String result = convert(source);
		if (log)
		{
			System.out.println(name + ":\n  '" + source + "'->'" + result + "' expected (" + expected + ")");
		}
		assertEquals(name, expected, result);
	}

	protected void check(String name, String expected, String source)
	{
		check(name, expected, source, false);
	}

	public void testEmpty()
	{
		check("FilterTest.empty 1", "", "");
	}

	public void testOneLine()
	{
		check("FilterTest.oneline 1", "hello", "hello");
	}

	public void testTwoLines()
	{
		check("FilterTest.twolines 1", "hello\nthere", "hello\nthere");
	}

	public void testTwoParagraphs()
	{
		check("FilterTest.twoparas 1", "hello\n<p/>\nthere",
			"hello\n\nthere");
		check("FilterTest.twoparas 2", "hello\n<p/>\nthere",
			"hello\n  \nthere");
		check("FilterTest.twoparas 3", "hello\n<p/>\nthere",
			"hello\r\n\r\nthere");
	}

	public void testLT()
	{
		check("FilterTest.lt 1", "a < b",
			"a < b");
	}

	public void testGT()
	{
		check("FilterTest.gt 1", "a > b",
			"a > b");
	}
}




Copyright 1998-2008 Alvin Alexander
All Rights Reserved.
 
devdaily.com is based in louisville, kentucky, and this web site is hosted by godaddy.com