FileDocCategorySizeDatePackage
PagerTest.javaAPI DocGlassfish v2 API6483Fri May 04 22:25:30 BST 2007com.sun.enterprise.cli.framework

PagerTest

public class PagerTest extends TestCase
author
Toby H Ferguson
version
$Revision: 1.5 $

Fields Summary
Pipe
stdout
Constructors Summary
public PagerTest(String name)

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        if (args.length == 0){
            junit.textui.TestRunner.run(PagerTest.class);
        } else {
            junit.textui.TestRunner.run(makeSuite(args));
        }
    
private static junit.framework.TestSuitemakeSuite(java.lang.String[] args)

        final TestSuite ts = new TestSuite();
        for (int i = 0; i < args.length; i++){
            ts.addTest(new PagerTest(args[i]));
        }
        return ts;
    
private voidnyi()

        fail("Not Yet Implemented");
    
protected voidsetUp()

        stdout = new Pipe();
    
protected voidtearDown()

    
public voidtestHasNext()

        final Pager m = new Pager(2, new StringReader("1\n2\n3"),
                                stdout.getWriter());
        assertTrue("Didn't expect anything in the output!",
                   !stdout.ready());
        m.nextPage();
        assertTrue(m.hasNext());
        m.nextPage();
        assertTrue(!m.hasNext());
    
public voidtestMultiplePages()

        final Pager m = new Pager(2, new StringReader("1\n2\n3\n4\n5\n6\n7"), stdout.getWriter());
        assertTrue("Didn't expect anything in the output!", !stdout.ready());
        m.nextPage();
        assertTrue("Expected something on the output!", stdout.ready());
        assertEquals("1", stdout.readLine());
        assertEquals("2", stdout.readLine());
        assertTrue("Expected end of page 1", !stdout.ready());
        m.nextPage();
        assertTrue("Expected page 2 to be ready", stdout.ready());
        assertEquals("3", stdout.readLine());
        assertEquals("4", stdout.readLine());
        assertTrue("Expected to be waiting for page 3", !stdout.ready());
        m.nextPage();
        assertEquals("5", stdout.readLine());
        assertEquals("6", stdout.readLine());
        assertTrue("Expected to be waiting for page 4", !stdout.ready());
        m.nextPage();
        assertEquals("7", stdout.readLine());
        assertTrue("Expected end of page 4", !stdout.ready());
    
public voidtestNegativeLinesPerPage()

        final Pager m = new Pager(-1, new StringReader("1\n2\n3"),
                                stdout.getWriter());
		m.nextPage();
		assertEquals("1", stdout.readLine());
		assertEquals("2", stdout.readLine());
		assertEquals("3", stdout.readLine());
		assertTrue("Output should no longer be ready", !stdout.ready());
  
public voidtestSinglePage()

        final Pager m = new Pager(2, new StringReader("1\n2\n"), stdout.getWriter());
        assertTrue("Didn't expect anything in the output!", !stdout.ready());
        m.nextPage();
        assertTrue("Expected something on the output!", stdout.ready());
        assertEquals("1", stdout.readLine());
        assertEquals("2", stdout.readLine());
        assertTrue("Expected no more output", !stdout.ready());
    
public voidtestZeroLengthPage()

        final Pager m = new Pager(0, new StringReader("1\n2\n3\n4\n5\n6\n7"),
                                stdout.getWriter());
        assertTrue("Didn't expect anything in the output!",
                   !stdout.ready());
        m.nextPage();
        assertTrue("Didn't expect anything in the output!",
                   !stdout.ready());