KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > util > test > StringsUnitTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.util.test;
23
24 import org.jboss.test.JBossTestCase;
25 import org.jboss.util.Strings;
26
27 /**
28  * Unit tests for jboss Strings utility class
29  *
30  * @see org.jboss.util.Strings
31  *
32  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
33  * @version $Revision: 37406 $
34  */

35 public class StringsUnitTestCase extends JBossTestCase
36 {
37    public StringsUnitTestCase(String JavaDoc name)
38    {
39       super(name);
40    }
41
42    /**
43     * Test Strings.parseTimePeriod()
44     *
45     * @throws Exception
46     */

47    public void testParseTimePeriod() throws Exception JavaDoc
48    {
49       long result;
50       
51       result = Strings.parseTimePeriod("-1");
52       assertTrue("expected -1 msec, got " + result, result == -1);
53       
54       result = Strings.parseTimePeriod("0");
55       assertTrue("expected 0 msec, got " + result, result == 0);
56       
57       result = Strings.parseTimePeriod("1");
58       assertTrue("expected 1 msec, got " + result, result == 1);
59       
60       result = Strings.parseTimePeriod("1msec");
61       assertTrue("expected 1 msec, got " + result, result == 1);
62       
63       result = Strings.parseTimePeriod("1sec");
64       assertTrue("expected 1000 msec, got " + result, result == 1000);
65       
66       result = Strings.parseTimePeriod("1min");
67       assertTrue("expected 60000 msec, got " + result, result == 60000);
68       
69       result = Strings.parseTimePeriod("1h");
70       assertTrue("expected 3600000 msec, got " + result, result == 3600000);
71       
72       result = Strings.parseTimePeriod("666msec");
73       assertTrue("expected 666 msec, got " + result, result == 666);
74       
75       try
76       {
77          result = Strings.parseTimePeriod(null);
78          fail("Expected NumberFormatException()");
79       }
80       catch (NumberFormatException JavaDoc e)
81       {
82          getLog().debug("Caught expected NumberFormatException: " + e.getMessage());
83       }
84       
85       try
86       {
87          result = Strings.parseTimePeriod("bla");
88          fail("Expected NumberFormatException()");
89       }
90       catch (NumberFormatException JavaDoc e)
91       {
92          getLog().debug("Caught expected NumberFormatException: " + e.getMessage());
93       }
94    }
95    
96    /**
97     * Test Strings.parsePositiveTimePeriod()
98     *
99     * @throws Exception
100     */

101    public void testParsePositiveTimePeriod() throws Exception JavaDoc
102    {
103       long result;
104       
105       try
106       {
107          result = Strings.parsePositiveTimePeriod("-1");
108          fail("Expected NumberFormatException()");
109       }
110       catch (NumberFormatException JavaDoc e)
111       {
112          getLog().debug("Caught expected NumberFormatException: " + e.getMessage());
113       }
114
115       result = Strings.parsePositiveTimePeriod("0");
116       assertTrue("expected 0 msec, got " + result, result == 0);
117       
118       result = Strings.parsePositiveTimePeriod("1");
119       assertTrue("expected 1 msec, got " + result, result == 1);
120    }
121       
122 }
123
Popular Tags