KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tasklist > usertasks > util > DurationFormatTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.tasklist.usertasks.util;
21
22 import junit.framework.TestCase;
23 import junit.framework.*;
24 import java.text.MessageFormat JavaDoc;
25 import java.text.ParseException JavaDoc;
26 import java.util.regex.Matcher JavaDoc;
27 import java.util.regex.Pattern JavaDoc;
28 import org.netbeans.modules.tasklist.usertasks.model.Duration;
29 import org.openide.util.NbBundle;
30
31 /**
32  * Tests for DurationFormat.
33  *
34  * @author tl
35  */

36 public class DurationFormatTest extends TestCase {
37     public DurationFormatTest(String JavaDoc testName) {
38         super(testName);
39     }
40
41     /**
42      * Test of parse method, of class
43      * org.netbeans.modules.tasklist.usertasks.util.DurationFormat.
44      */

45     public void testParse() throws ParseException JavaDoc {
46         DurationFormat instance = new DurationFormat(DurationFormat.Type.SHORT);
47         assertEquals("01:00", instance.format(instance.parse("1:00")));
48         assertEquals("1d 01:03", instance.format(instance.parse("1d 1:03")));
49         assertEquals("1w 2d 21:03", instance.format(instance.parse("1w 2d 21:03")));
50         assertEquals("3w 20:03", instance.format(instance.parse("3w 20:03")));
51         assertEquals("1w", instance.format(instance.parse("1w")));
52         instance = new DurationFormat(DurationFormat.Type.LONG);
53         assertEquals("1 hour", instance.format(instance.parse("1 hour")));
54         assertEquals("2 days", instance.format(instance.parse("2 days")));
55         assertEquals("2 weeks 1 hour", instance.format(instance.parse("2 weeks 1 hour")));
56         assertEquals("2 weeks 1 day 7 hours 4 minutes", instance.format(instance.parse("2 weeks 1 day 7 hours 4 minutes")));
57     }
58 }
59
Popular Tags