alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Friki example source code file (FilterTest.java)

This example Friki source code file (FilterTest.java) 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.

Java - Friki tags/keywords

contentfilter, filtertest, filtertest, inmemoryrepository, io, pagerepository, pagerepository, string, string, stringreader, stringwriter, stringwriter, testcase

The Friki FilterTest.java 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");
	}
}

Other Friki examples (source code examples)

Here is a short list of links related to this Friki FilterTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.