001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.util.test;
023:
024: import org.jboss.test.JBossTestCase;
025: import org.jboss.util.Strings;
026:
027: /**
028: * Unit tests for jboss Strings utility class
029: *
030: * @see org.jboss.util.Strings
031: *
032: * @author <a href="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
033: * @version $Revision: 57211 $
034: */
035: public class StringsUnitTestCase extends JBossTestCase {
036: public StringsUnitTestCase(String name) {
037: super (name);
038: }
039:
040: /**
041: * Test Strings.parseTimePeriod()
042: *
043: * @throws Exception
044: */
045: public void testParseTimePeriod() throws Exception {
046: long result;
047:
048: result = Strings.parseTimePeriod("-1");
049: assertTrue("expected -1 msec, got " + result, result == -1);
050:
051: result = Strings.parseTimePeriod("0");
052: assertTrue("expected 0 msec, got " + result, result == 0);
053:
054: result = Strings.parseTimePeriod("1");
055: assertTrue("expected 1 msec, got " + result, result == 1);
056:
057: result = Strings.parseTimePeriod("1msec");
058: assertTrue("expected 1 msec, got " + result, result == 1);
059:
060: result = Strings.parseTimePeriod("1sec");
061: assertTrue("expected 1000 msec, got " + result, result == 1000);
062:
063: result = Strings.parseTimePeriod("1min");
064: assertTrue("expected 60000 msec, got " + result,
065: result == 60000);
066:
067: result = Strings.parseTimePeriod("1h");
068: assertTrue("expected 3600000 msec, got " + result,
069: result == 3600000);
070:
071: result = Strings.parseTimePeriod("666msec");
072: assertTrue("expected 666 msec, got " + result, result == 666);
073:
074: try {
075: result = Strings.parseTimePeriod(null);
076: fail("Expected NumberFormatException()");
077: } catch (NumberFormatException e) {
078: getLog().debug(
079: "Caught expected NumberFormatException: "
080: + e.getMessage());
081: }
082:
083: try {
084: result = Strings.parseTimePeriod("bla");
085: fail("Expected NumberFormatException()");
086: } catch (NumberFormatException e) {
087: getLog().debug(
088: "Caught expected NumberFormatException: "
089: + e.getMessage());
090: }
091: }
092:
093: /**
094: * Test Strings.parsePositiveTimePeriod()
095: *
096: * @throws Exception
097: */
098: public void testParsePositiveTimePeriod() throws Exception {
099: long result;
100:
101: try {
102: result = Strings.parsePositiveTimePeriod("-1");
103: fail("Expected NumberFormatException()");
104: } catch (NumberFormatException e) {
105: getLog().debug(
106: "Caught expected NumberFormatException: "
107: + e.getMessage());
108: }
109:
110: result = Strings.parsePositiveTimePeriod("0");
111: assertTrue("expected 0 msec, got " + result, result == 0);
112:
113: result = Strings.parsePositiveTimePeriod("1");
114: assertTrue("expected 1 msec, got " + result, result == 1);
115: }
116:
117: }
|