1 16 17 package test.types; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.types.Month; 21 22 import java.text.NumberFormat ; 23 24 27 public class TestMonth extends TestCase { 28 29 public TestMonth(String name) { 30 super(name); 31 } 32 33 36 private void runFailTest(int month, String tz) throws Exception { 37 Month oMonth = null; 38 try { 39 oMonth = new Month(month, tz); 40 } 41 catch (Exception e) { } 43 assertNull("validation restriction failed [ month=" + String.valueOf(month) + 45 ",tz=" + tz + "]. did not restrict bad value.", oMonth); 46 } 47 48 private void runFailTest(String source) throws Exception { 49 Month oMonth = null; 50 try { 51 oMonth = new Month(source); 52 } 53 catch (Exception e) { } 55 assertNull("validation restriction failed [ " + source + 57 "]. did not restrict bad value.", oMonth); 58 } 59 60 63 private void runPassTest(int month, String tz) throws Exception { 64 Month oMonth = null; 65 try { 66 oMonth = new Month(month, tz); 67 } 68 catch (Exception e) { assertTrue("Validation exception thrown on valid input", false); 70 } 71 assertEquals("Month month not equal", month, oMonth.getMonth()); 72 assertEquals("Month timezone not equal", tz, oMonth.getTimezone()); 73 } 74 75 private void runPassTest(String source) throws Exception { 76 Month oMonth = null; 77 try { 78 oMonth = new Month(source); 79 } 80 catch (Exception e) { assertTrue("Validation exception thrown on valid input", false); 82 } 83 assertEquals("Month.toString() not equal", source, oMonth.toString()); 84 } 85 86 89 public void testNormal() throws Exception { 90 for (int m=1; m < 13; m++) { 92 runPassTest(m, null); 93 } 94 } 95 public void testNormalString() throws Exception { 96 NumberFormat nf = NumberFormat.getInstance(); 99 nf.setMinimumIntegerDigits(2); 100 for (int m=1; m < 13; m++) { 101 String s = "--" + nf.format(m) + "--"; 102 runPassTest(s); 103 } 104 } 105 public void testNormalTimezone() throws Exception { 106 runPassTest("--01--Z"); 107 } 108 public void testNormalPositiveTimezone() throws Exception { 109 runPassTest("--11--+05:00"); 110 } 111 public void testNormalNegativeTimezone() throws Exception { 112 runPassTest("--11---11:00"); 113 } 114 115 118 public void testBadString() throws Exception { 119 runFailTest("11--"); 120 runFailTest("-11--"); 121 runFailTest("--11-"); 122 runFailTest("--11"); 123 runFailTest("xx07-13"); 124 runFailTest("garbage"); 125 } 126 127 130 public void testBadMonth() throws Exception { 131 runFailTest(13, null); 132 } 133 public void testBadMonthString() throws Exception { 134 runFailTest("--13--"); 135 } 136 public void testBadMonthString2() throws Exception { 137 runFailTest("--1--"); 138 } 139 140 143 public void testBadTimezone() throws Exception { 144 runFailTest(7, "badzone"); 145 } 146 public void testBadTimezoneString() throws Exception { 147 runFailTest("--07--+EDT"); 148 } 149 150 } 151 | Popular Tags |