1 20 package org.apache.cactus.sample.servlet.unit; 21 22 import java.io.Serializable ; 23 24 import org.apache.cactus.ServletTestCase; 25 import org.apache.cactus.internal.client.AssertionFailedErrorWrapper; 26 import org.apache.cactus.internal.client.ServletExceptionWrapper; 27 import org.apache.cactus.internal.util.JUnitVersionHelper; 28 29 import junit.framework.AssertionFailedError; 30 import junit.framework.ComparisonFailure; 31 32 40 public class TestServerSideExceptions extends ServletTestCase 41 { 42 45 public class NotSerializableException extends Exception 46 { 47 50 public NotSerializableException(String theMessage) 51 { 52 super(theMessage); 53 } 54 } 55 56 59 public class SerializableException extends Exception 60 implements Serializable 61 { 62 65 public SerializableException(String theMessage) 66 { 67 super(theMessage); 68 } 69 } 70 71 76 private boolean checkName(String theTestName) 77 { 78 return JUnitVersionHelper.getTestCaseName(this).equals( 79 theTestName); 80 } 81 82 87 public void runBare() throws Throwable 88 { 89 try 90 { 91 super.runBare(); 92 } 93 catch (AssertionFailedErrorWrapper e) 94 { 95 if (checkName("testAssertionFailedError")) 99 { 100 assertEquals(AssertionFailedError.class.getName(), 101 e.getWrappedClassName()); 102 assertEquals("test assertion failed error", e.getMessage()); 103 return; 104 } 105 106 else if (checkName("testComparisonFailure")) 110 { 111 assertEquals(ComparisonFailure.class.getName(), 112 e.getWrappedClassName()); 113 assertEquals("test comparison failure expected:<some...> " 114 + "but was:<other...>", e.getMessage()); 115 return; 116 } 117 } 118 catch (ServletExceptionWrapper e) 119 { 120 if (checkName("testExceptionNotSerializable")) 126 { 127 assertEquals(NotSerializableException.class.getName(), 128 e.getWrappedClassName()); 129 assertEquals("test non serializable exception", 130 e.getMessage()); 131 return; 132 } 133 134 else if (checkName("testExceptionSerializable")) 139 { 140 assertEquals(SerializableException.class.getName(), 141 e.getWrappedClassName()); 142 assertEquals("test serializable exception", e.getMessage()); 143 return; 144 } 145 } 146 147 throw new AssertionFailedError("Unexpected test [" 148 + JUnitVersionHelper.getTestCaseName(this) + "]"); 149 } 150 151 153 160 public void testAssertionFailedError() 161 { 162 throw new AssertionFailedError("test assertion failed error"); 163 } 164 165 167 177 public void testExceptionNotSerializable() 178 throws NotSerializableException 179 { 180 throw new NotSerializableException("test non serializable exception"); 181 } 182 183 185 194 public void testExceptionSerializable() throws SerializableException 195 { 196 throw new SerializableException("test serializable exception"); 197 } 198 199 201 206 public void testComparisonFailure() 207 { 208 throw new ComparisonFailure("test comparison failure", "some value", 209 "other value"); 210 } 211 212 } 213 | Popular Tags |