1 22 package org.jboss.test.util.test; 23 24 import org.jboss.test.JBossTestCase; 25 import org.jboss.util.Strings; 26 27 35 public class StringsUnitTestCase extends JBossTestCase 36 { 37 public StringsUnitTestCase(String name) 38 { 39 super(name); 40 } 41 42 47 public void testParseTimePeriod() throws Exception 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 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 e) 91 { 92 getLog().debug("Caught expected NumberFormatException: " + e.getMessage()); 93 } 94 } 95 96 101 public void testParsePositiveTimePeriod() throws Exception 102 { 103 long result; 104 105 try 106 { 107 result = Strings.parsePositiveTimePeriod("-1"); 108 fail("Expected NumberFormatException()"); 109 } 110 catch (NumberFormatException 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 |