1 15 package org.apache.tapestry.annotations; 16 17 import java.lang.reflect.Method ; 18 19 import org.apache.hivemind.ApplicationRuntimeException; 20 21 27 public class TestAnnotationUtils extends BaseAnnotationTestCase 28 { 29 private String attemptGetPropertyName(Class clazz, String name) 30 { 31 Method m = findMethod(clazz, name); 32 33 return AnnotationUtils.getPropertyName(m); 34 } 35 36 public void testGetPropertyName() 37 { 38 assertEquals("stringValue", attemptGetPropertyName(Target.class, "getStringValue")); 39 assertEquals("intValue", attemptGetPropertyName(Target.class, "setIntValue")); 40 assertEquals("booleanValue", attemptGetPropertyName(Target.class, "isBooleanValue")); 41 } 42 43 public void testGetPropertyNameNotAGetter() 44 { 45 try 46 { 47 attemptGetPropertyName(Target.class, "notAGetter"); 48 unreachable(); 49 } 50 catch (ApplicationRuntimeException ex) 51 { 52 assertEquals( 53 "Annotated method public abstract java.lang.String org.apache.tapestry.annotations.Target.notAGetter() " 54 + "should be an accessor (no parameters), or a mutator (single parameter, returns void).", 55 ex.getMessage()); 56 } 57 } 58 59 public void testGetPropertyNameSetterNoParameters() 60 { 61 try 62 { 63 attemptGetPropertyName(Target.class, "setNoParameters"); 64 unreachable(); 65 } 66 catch (ApplicationRuntimeException ex) 67 { 68 assertEquals( 69 "Annotated method public abstract void org.apache.tapestry.annotations.Target.setNoParameters() is named like a mutator method," 70 + " but takes an incorrect number of parameters (it should have exactly one parameter).", 71 ex.getMessage()); 72 } 73 } 74 75 public void testNonVoidSetter() 76 { 77 try 78 { 79 attemptGetPropertyName(Target.class, "setNonVoidMethod"); 80 unreachable(); 81 } 82 catch (ApplicationRuntimeException ex) 83 { 84 assertEquals( 85 "Annotated method public abstract java.lang.String org.apache.tapestry.annotations.Target.setNonVoidMethod(java.lang.String) " 86 + "is named like a mutator method, but does not return void.", 87 ex.getMessage()); 88 } 89 } 90 91 public void testGetterWithParameters() 92 { 93 try 94 { 95 attemptGetPropertyName(Target.class, "getHasParameters"); 96 unreachable(); 97 } 98 catch (ApplicationRuntimeException ex) 99 { 100 assertEquals( 101 "Annotated method public abstract java.lang.String org.apache.tapestry.annotations.Target.getHasParameters(java.lang.String) " 102 + "is expected to be an accessor, and should have no parameters.", 103 ex.getMessage()); 104 } 105 } 106 107 public void testGetterReturnsVoid() 108 { 109 try 110 { 111 attemptGetPropertyName(Target.class, "isVoidGetter"); 112 unreachable(); 113 } 114 catch (ApplicationRuntimeException ex) 115 { 116 assertEquals( 117 "Annotated method public abstract void org.apache.tapestry.annotations.Target.isVoidGetter() " 118 + "is named like an accessor method, but returns void.", 119 ex.getMessage()); 120 } 121 } 122 123 } 124 | Popular Tags |