1 package org.pojomatic.internal; 2 3 import static org.testng.Assert.*; 4 5 import java.lang.reflect.Method; 6 7 import org.testng.annotations.Test; 8 9 public class PropertyAccessorTest { 10 11 public static class MethodHolder { 12 public int getFoo() { return 0; } 13 public int isFoo() { return 0; } 14 public boolean getBar() { return true; } 15 public boolean isBar() { return true; } 16 } 17 18 @Test 19 public void testGetter() { 20 assertEquals(new PropertyAccessor(getMethod("getFoo"), "").getName(), "foo"); 21 } 22 23 @Test 24 public void testBooleanGetter() { 25 assertEquals(new PropertyAccessor(getMethod("getBar"), "").getName(), "bar"); 26 } 27 28 @Test 29 public void testNonBooleanIs() { 30 assertEquals(new PropertyAccessor(getMethod("isFoo"), "").getName(), "isFoo"); 31 } 32 33 @Test 34 public void testBooleanIs() { 35 assertEquals(new PropertyAccessor(getMethod("isBar"), "").getName(), "bar"); 36 } 37 38 39 private Method getMethod(String methodName) { 40 for (Method m: MethodHolder.class.getMethods()) { 41 if (methodName.equals(m.getName())) { 42 return m; 43 } 44 } 45 throw new IllegalArgumentException("No method named " + methodName); 46 } 47 }