MemberUtil { public static String getGetterName(String fieldName, CtClass declaring) { String capitalized = capitalize(fieldName); String standardGetter = GETTER_PREFIX + capitalized; String booleanGetter = BOOLEAN_GETTER_PREFIX + capitalized; boolean containsBooleanGetter = JavassistUtil.containsDeclaredMethod(declaring, booleanGetter) || JavassistUtil.containsMethod(declaring, booleanGetter); return containsBooleanGetter ? booleanGetter : standardGetter; } private  MemberUtil(); static List<Member> getMembers(Class<?> clazz, Predicate memberPredicate); static String getFieldName(AnnotatedElement object); static String getFieldName(Member object); static String getDefaultEnumName(String entityClassName, String fieldName); static Class<?> getCorrectType(AnnotatedElement object); static Class<?> getCorrectType(Member object); static Class<?> getGenericType(AnnotatedElement object); static Class<?> getGenericType(AnnotatedElement object, int typeNumber); static Class<?> getGenericType(Member object, int typeNumber); static String getGetterName(String fieldName, CtClass declaring); static String getSetterName(String fieldName); static boolean isGetter(Member member); static boolean isSetter(Member member); static String getFieldNameFromGetterSetterName(String getterSetterName); static Class<?> getDeclaringClass(AccessibleObject ac); static List<AccessibleObject> getFieldAndAccessorsForElement(AccessibleObject ao); static final String GETTER_PREFIX; static final String BOOLEAN_GETTER_PREFIX; static final String SETTER_PREFIX; static final int GET_OR_SET_END_INDEX; static final int IS_END_INDEX; }
@Test public void shouldGetGetterName() { PowerMockito.mockStatic(JavassistUtil.class); PowerMockito.when(JavassistUtil.containsDeclaredMethod(ctClass, "isBooleanField")).thenReturn(true); assertEquals("isBooleanField", MemberUtil.getGetterName("booleanField", ctClass)); PowerMockito.when(JavassistUtil.containsDeclaredMethod(ctClass, "isOtherBoolean")).thenReturn(true); assertEquals("isOtherBoolean", MemberUtil.getGetterName("otherBoolean", ctClass)); PowerMockito.when(JavassistUtil.containsDeclaredMethod(ctClass, "isNotBooleanField")).thenReturn(false); PowerMockito.when(JavassistUtil.containsMethod(ctClass, "isNotBooleanField")).thenReturn(false); assertEquals("getNotBooleanField", MemberUtil.getGetterName("notBooleanField", ctClass)); PowerMockito.when(JavassistUtil.containsDeclaredMethod(ctClass, "isStringField")).thenReturn(false); PowerMockito.when(JavassistUtil.containsMethod(ctClass, "isStringField")).thenReturn(false); assertEquals("getStringField", MemberUtil.getGetterName("stringField", ctClass)); }