Package org.rendersnake.test

Source Code of org.rendersnake.test.PageContextTest

package org.rendersnake.test;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.rendersnake.HtmlCanvas;
import org.rendersnake.PageContext;
import org.rendersnake.tools.Inspector;

import junit.framework.TestCase;

public class PageContextTest extends TestCase {

    private PageContext ctx;
   
    public void setUp() {
        ctx = new PageContext();
    }
    public void testList() {
        List<String> list = new ArrayList<String>();
        list.add("list");
        ctx.setList("strings", list);
        @SuppressWarnings("unchecked")
        List<String> strings = (List<String>) ctx.getList("strings");
        assertEquals(strings.get(0), list.get(0));
    }
    public void testBoolean(){
        ctx.set("boolean", true);
        assertEquals(new Boolean(true), ctx.getBoolean("boolean"));
    }
    public void testInt(){
        ctx.set("int", 42);
        assertEquals(new Integer(42), ctx.getInt("int"));
    }
    public void testString(){
        ctx.set("hello", "world");
        assertEquals("world", ctx.getString("hello"));
    }
    public void testObject(){
        Date now = Calendar.getInstance().getTime();
        ctx.set("now",now);
        assertEquals(now, ctx.get("now"));
    }
    public void testNullKeyString(){
        try {
            ctx.set(null,"null");
            fail("should raise exception");           
        } catch (IllegalArgumentException ex) {
            // got it
        }
    }
    public void testNullKeyInt(){
        try {
            ctx.set(null,42);
            fail("should raise exception");           
        } catch (IllegalArgumentException ex) {
            // got it
        }
    }
    public void testNullKeyBoolean(){
        try {
            ctx.set(null,true);
            fail("should raise exception");           
        } catch (IllegalArgumentException ex) {
            // got it
        }
    }
    public void testNullKeyObject(){
        try {
            ctx.set(null,new ClassNotFoundException());
            fail("should raise exception");           
        } catch (IllegalArgumentException ex) {
            // got it
        }
    } 
    public void testRender() throws Exception {
        HtmlCanvas html = new HtmlCanvas();
        ctx.renderForErrorOn(html);
        ctx.renderForInpectorOn(new Inspector(new PersonalPage()), html);
        assertFalse(html.toHtml().length() == 0);
    }
}
TOP

Related Classes of org.rendersnake.test.PageContextTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.