1 15 package org.apache.hivemind.impl; 16 17 import hivemind.test.FrameworkTestCase; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.hivemind.ApplicationRuntimeException; 21 import org.apache.hivemind.ErrorHandler; 22 import org.apache.hivemind.Location; 23 import org.apache.hivemind.Resource; 24 import org.apache.hivemind.util.ClasspathResource; 25 26 31 public class TestErrorHandler extends FrameworkTestCase 32 { 33 public void testDefaultErrorHandlerWithLocation() 34 { 35 Log log = (Log) newMock(Log.class); 36 37 Resource r = new ClasspathResource(getClassResolver(), "/foo/bar/Baz.module"); 38 Location l = new LocationImpl(r, 13); 39 40 Throwable ex = new IllegalArgumentException (); 41 42 log.error("Error at classpath:/foo/bar/Baz.module, line 13: Bad frob value.", ex); 43 44 replayControls(); 45 46 ErrorHandler eh = new DefaultErrorHandler(); 47 48 eh.error(log, "Bad frob value.", l, ex); 49 50 verifyControls(); 51 } 52 53 public void testDefaultErrorHandlerWithNoLocation() 54 { 55 Log log = (Log) newMock(Log.class); 56 57 Throwable ex = new IllegalArgumentException (); 58 59 log.error("Error: Bad frob value.", ex); 60 61 replayControls(); 62 63 ErrorHandler eh = new DefaultErrorHandler(); 64 65 eh.error(log, "Bad frob value.", null, ex); 66 67 verifyControls(); 68 } 69 70 public void testStrictErrorHandler() 71 { 72 ErrorHandler eh = new StrictErrorHandler(); 73 Throwable cause = new NullPointerException (); 74 75 try 76 { 77 eh.error(null, "An error message.", null, cause); 78 unreachable(); 79 } 80 catch (ApplicationRuntimeException ex) 81 { 82 assertEquals("Error: An error message.", ex.getMessage()); 83 assertSame(cause, ex.getRootCause()); 84 } 85 } 86 87 public void testStrictErrorHandlerWithLocation() 88 { 89 ErrorHandler eh = new StrictErrorHandler(); 90 Throwable cause = new NullPointerException (); 91 Location l = newLocation(); 92 93 try 94 { 95 eh.error(null, "An error message.", l, cause); 96 unreachable(); 97 } 98 catch (ApplicationRuntimeException ex) 99 { 100 assertEquals("Error at " + l + ": An error message.", ex.getMessage()); 101 assertSame(l, ex.getLocation()); 102 assertSame(cause, ex.getRootCause()); 103 } 104 } 105 } 106 | Popular Tags |