com.pureinfo.force.util.TimerUtilTest.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.force.util.TimerUtilTest.java

Source

/**
 * PureInfo Force
 * @(#)TimerUtilTest.java   1.0 Dec 29, 2005
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.force.util;

import java.util.TimerTask;

import junit.framework.TestCase;

import org.apache.commons.lang.time.DateUtils;

/**
 * <P>
 * Created on Dec 29, 2005 10:40:04 AM <BR>
 * Last modified on Dec 29, 2005
 * </P>
 * 
 * @author Freeman.Hu
 * @version 1.0, Dec 29, 2005
 * @since Force 1.0
 */
public class TimerUtilTest extends TestCase {
    public void testGetNext() {
        long[] datas = { //
                // start,now,period,expected
                10, 20, 3, 22, //
                10, 19, 3, 22, //
                10, 18, 3, 19, //
                20, 10, 3, 20, //
                21, 10, 3, 21, //
                22, 10, 3, 22, //
        };
        for (int i = 0; i < datas.length; i += 4) {
            assertEquals(String.valueOf(i / 4), datas[i + 3],
                    TimerUtil.getNext(datas[i], datas[i + 1], datas[i + 2]));
        }
    }

    public void testScheduleFrom() throws InterruptedException {
        TimerUtil.scheduleFrom("11:20", DateUtils.MILLIS_PER_SECOND, new TimerTask() {
            private int i = 0;

            public void run() {
                System.out.println(i++);
                // if (i == 5) timer.cancel();
            }
        });
        Thread.sleep(10000);
    }
}