1 15 package org.apache.tapestry.form.validator; 16 17 import java.util.List ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 import org.apache.hivemind.Location; 21 import org.apache.tapestry.IBinding; 22 import org.apache.tapestry.binding.BindingTestCase; 23 import org.apache.tapestry.coerce.ValueConverter; 24 import org.easymock.MockControl; 25 26 33 public class TestValidatorsBinding extends BindingTestCase 34 { 35 public void testSuccess() 36 { 37 Location l = newLocation(); 38 List validators = (List ) newMock(List .class); 39 ValueConverter vc = newValueConverter(); 40 41 MockControl control = newControl(ValidatorFactory.class); 42 ValidatorFactory vf = (ValidatorFactory) control.getMock(); 43 44 vf.constructValidatorList("required"); 45 control.setReturnValue(validators); 46 47 replayControls(); 48 49 ValidatorsBindingFactory factory = new ValidatorsBindingFactory(); 50 factory.setValueConverter(vc); 51 factory.setValidatorFactory(vf); 52 53 IBinding binding = factory.createBinding(null, "my desc", "required", l); 54 55 assertSame(validators, binding.getObject()); 56 assertSame(l, binding.getLocation()); 57 assertEquals("my desc", binding.getDescription()); 58 59 verifyControls(); 60 } 61 62 public void testFailure() 63 { 64 Throwable t = new RuntimeException ("Boom!"); 65 Location l = newLocation(); 66 67 ValueConverter vc = newValueConverter(); 68 69 MockControl control = newControl(ValidatorFactory.class); 70 ValidatorFactory vf = (ValidatorFactory) control.getMock(); 71 72 vf.constructValidatorList("required"); 73 control.setThrowable(t); 74 75 replayControls(); 76 77 ValidatorsBindingFactory factory = new ValidatorsBindingFactory(); 78 factory.setValueConverter(vc); 79 factory.setValidatorFactory(vf); 80 81 try 82 { 83 factory.createBinding(null, "my desc", "required", l); 84 unreachable(); 85 } 86 catch (ApplicationRuntimeException ex) 87 { 88 assertEquals("Boom!", ex.getMessage()); 89 assertSame(t, ex.getRootCause()); 90 assertSame(l, ex.getLocation()); 91 } 92 93 verifyControls(); 94 } 95 } 96 | Popular Tags |