1 16 17 package test.types; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.types.YearMonth; 21 22 25 public class TestYearMonth extends TestCase { 26 27 public TestYearMonth(String name) { 28 super(name); 29 } 30 31 34 private void runFailTest(int year, int month, String tz) throws Exception { 35 YearMonth oYearMonth = null; 36 try { 37 oYearMonth = new YearMonth(year, month, tz); 38 } 39 catch (Exception e) { } 41 assertNull("validation restriction failed [ year=" + 43 String.valueOf(year) + ",month=" + String.valueOf(month) + 44 ",tz=" + tz + "]. did not restrict bad value.", oYearMonth); 45 } 46 47 private void runFailTest(String source) throws Exception { 48 YearMonth oYearMonth = null; 49 try { 50 oYearMonth = new YearMonth(source); 51 } 52 catch (Exception e) { } 54 assertNull("validation restriction failed [ " + source + 56 "]. did not restrict bad value.", oYearMonth); 57 } 58 59 62 private void runPassTest(int year, int month, String tz) throws Exception { 63 YearMonth oYearMonth = null; 64 try { 65 oYearMonth = new YearMonth(year, month, tz); 66 } 67 catch (Exception e) { assertTrue("Validation exception thrown on valid input", false); 69 } 70 assertEquals("YearMonth year not equal", year, oYearMonth.getYear()); 71 assertEquals("YearMonth month not equal", month, oYearMonth.getMonth()); 72 assertEquals("YearMonth timezone not equal", tz, oYearMonth.getTimezone()); 73 } 74 75 private void runPassTest(String source) throws Exception { 76 YearMonth oYearMonth = null; 77 try { 78 oYearMonth = new YearMonth(source); 79 } 80 catch (Exception e) { assertTrue("Validation exception thrown on valid input", false); 82 } 83 assertEquals("YearMonth.toString() not equal", source, oYearMonth.toString()); 84 } 85 86 89 public void testNormal() throws Exception { 90 runPassTest(2002, 8, null); 91 } 92 public void testNormalString() throws Exception { 93 runPassTest("9999-12"); 94 } 95 public void testNormalString2() throws Exception { 96 runPassTest("0001-01Z"); 98 } 99 public void testNegativeYear() throws Exception { 100 runPassTest(-1955, 4, null); 101 } 102 public void testNegativeYearString() throws Exception { 103 runPassTest("-1955-04+05:00"); 104 } 105 public void testNegativeYearString2() throws Exception { 106 runPassTest("-0055-04+05:00"); 108 } 109 public void testBigYear() throws Exception { 110 runPassTest(12000, 4, null); 112 } 113 public void testBigYearString() throws Exception { 114 runPassTest("-27000-04+05:00"); 115 } 116 117 121 public void testBadYear() throws Exception { 122 runFailTest(0, 7, null); 123 } 124 public void testBadYearString() throws Exception { 125 runFailTest("0000-7"); 126 } 127 128 131 public void testBadMonth() throws Exception { 132 runFailTest(1999, 13, null); 133 } 134 public void testBadMonthString() throws Exception { 135 runFailTest("1999-13"); 136 } 137 138 141 public void testBadTimezone() throws Exception { 142 runFailTest(1966, 7, "badzone"); 143 } 144 public void testBadTimezoneString() throws Exception { 145 runFailTest("1966-07+EDT"); 146 } 147 148 151 public void testMaxYear() throws Exception { 152 runPassTest(9999, 1, null); 153 } 154 155 } 156 | Popular Tags |