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