FileDocCategorySizeDatePackage
StringAlignTest.javaAPI DocExample1597Sun Feb 22 09:43:18 GMT 2004None

StringAlignTest

public class StringAlignTest extends TestCase
StringAlign Test program.

Fields Summary
String[]
mesg
protected StringAlign
sa
The object being tested
Constructors Summary
public StringAlignTest(String name)
JUnit test classes require(?) this constructor


	       
	   
		super(name);
	
Methods Summary
voiddump(int x, int len, java.lang.String mesg)

		System.out.println(mesg);
	
public voidtestCentre()

		for (int i=0; i<mesg.length; i++) {
			assertEquals(mesg[i].substring(0, 5),
				new StringAlign(5, StringAlign.JUST_CENTER).format(mesg[i]).trim());
			assertEquals(" " + mesg[i],
				new StringAlign(10, StringAlign.JUST_CENTER).format(mesg[i]).substring(0, mesg[i].length()+1));
		}
	
public voidtestLeft()

		for (int i=0; i<mesg.length; i++) {
			assertEquals(mesg[i].substring(0, 5),
				new StringAlign(5, StringAlign.JUST_LEFT).format(mesg[i]));
			String result = new StringAlign(10, StringAlign.JUST_LEFT).
					format(mesg[i]);
			assertEquals(mesg[i], result.trim());
			assertEquals(result.length(), 10);
		}
	
public voidtestNullString()

		assertEquals("     ", new StringAlign(5, StringAlign.JUST_RIGHT).format(""));
	
public voidtestRight()

		for (int i=0; i<mesg.length; i++) {
			System.out.println("Input String \"" + mesg[i] + "\"");
			assertEquals(mesg[i].substring(0, 5),
				new StringAlign(5, StringAlign.JUST_RIGHT).format(mesg[i]).trim());
			// XXX need to test this more.
			dump(StringAlign.JUST_RIGHT, 10,
				new StringAlign(10, StringAlign.JUST_RIGHT).format(mesg[i]));
		}