Package ch.pollet.jzic.parser

Source Code of ch.pollet.jzic.parser.RuleParserTest

package ch.pollet.jzic.parser;

import ch.pollet.jzic.parser.RuleParser;
import ch.pollet.jzic.datetime.DateTime;
import ch.pollet.jzic.timezone.Database;
import ch.pollet.jzic.timezone.Rule;
import ch.pollet.jzic.tokenizer.Tokenizer;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Christophe Pollet
*/
public class RuleParserTest {

    @Test
    public void testParse() throws Exception {
        String line;
        Tokenizer t;
        Rule r;
        DateTime dt;

        Database db = new Database();
        RuleParser rp = new RuleParser(db);

        //-- Test 1
        line = "Rule1 2009 2010 - Sep lastSun 2:00w 1:30 -";
        t = new Tokenizer(line, "\t ", null, 0);
        rp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDay(27);
        dt.setHour(2);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        assertTrue(db.getRules().containsKey("Rule1"));
        assertEquals(1, db.getRules().get("Rule1").size());
        r = db.getRules().get("Rule1").get(0);
        assertEquals(2009, r.getFromYear());
        assertEquals(2010, r.getToYear());
        assertEquals(null, r.getType());
        r.getAt().setYear(2009);
        assertEquals(dt, r.getAt());
        assertEquals(5400, r.getOffset());
        assertEquals("", r.getFormat());

        //-- Test 2
        line = "Rule2 2009 2010 - Sep 1 2:00w 1:30:30 S";
        t = new Tokenizer(line, "\t ", null, 0);
        rp.parse(t);

        dt = new DateTime();
        dt.setYear(2009);
        dt.setMonth(9);
        dt.setDay(1);
        dt.setHour(2);
        dt.setMinute(0);
        dt.setSecond(0);
        dt.setType(DateTime.Type.WALL);

        assertTrue(db.getRules().containsKey("Rule2"));
        assertEquals(1, db.getRules().get("Rule2").size());
        r = db.getRules().get("Rule2").get(0);
        assertEquals(2009, r.getFromYear());
        assertEquals(2010, r.getToYear());
        assertEquals(null, r.getType());
        r.getAt().setYear(2009);
        assertEquals(dt, r.getAt());
        assertEquals(5430, r.getOffset());
        assertEquals("S", r.getFormat());

    }

}
TOP

Related Classes of ch.pollet.jzic.parser.RuleParserTest

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.