1 19 20 21 package org.apache.james.util; 22 23 import junit.framework.TestCase; 24 25 public class TimeConverterTest extends TestCase { 26 27 private final long AMOUNT = 2; 28 29 30 public TimeConverterTest(String arg0) { 31 super(arg0); 32 } 33 34 35 public void testGetMilliSecondsMsec() { 36 long time = 2; 37 String unit = "msec"; 38 39 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 40 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 41 } 42 43 public void testGetMilliSecondsMsecs() { 44 long time = 2; 45 String unit = "msecs"; 46 47 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 48 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 49 } 50 51 public void testGetMilliSecondsSec() { 52 long time = 2000; 53 String unit = "sec"; 54 55 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 56 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 57 } 58 59 public void testGetMilliSecondsSecs() { 60 long time = 2000; 61 String unit = "secs"; 62 63 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 64 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 65 } 66 67 public void testGetMilliSecondsMinute() { 68 long time = 120000; 69 String unit = "minute"; 70 71 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 72 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 73 } 74 75 public void testGetMilliSecondsMinutes() { 76 long time = 120000; 77 String unit = "minutes"; 78 79 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 80 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 81 } 82 83 public void testGetMilliSecondsHour() { 84 long time = 7200000; 85 String unit = "hour"; 86 87 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 88 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 89 } 90 91 public void testGetMilliSecondsHours() { 92 long time = 7200000; 93 String unit = "hours"; 94 95 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 96 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 97 } 98 99 public void testGetMilliSecondsDay() { 100 long time = 172800000; 101 String unit = "day"; 102 103 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 104 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 105 } 106 107 public void testGetMilliSecondsDays() { 108 long time = 172800000; 109 String unit = "days"; 110 111 assertEquals(TimeConverter.getMilliSeconds(AMOUNT,unit),time); 112 assertEquals(TimeConverter.getMilliSeconds(AMOUNT +" " + unit),time); 113 } 114 115 public void testIllegalUnit() { 116 boolean exceptionThrown = false; 117 try { 118 TimeConverter.getMilliSeconds(2,"week"); 119 TimeConverter.getMilliSeconds(2 +" week"); 120 } catch (NumberFormatException e) { 121 exceptionThrown = true; 122 } 123 124 assertTrue(exceptionThrown); 125 } 126 127 public void testIllegalPattern() { 128 boolean exceptionThrown = false; 129 try { 130 TimeConverter.getMilliSeconds("illegal pattern"); 131 } catch (NumberFormatException e) { 132 exceptionThrown = true; 133 } 134 135 assertTrue(exceptionThrown); 136 } 137 138 } 139 | Popular Tags |