@Test public void testIsSetter() { assertAll( () -> assertThat("Set is fine", isSetter("set", String.class), is(true)), () -> assertThat("Any string is fine as long as it has a single parameter and void return", isSetter("nastav", String.class), is(true)), () -> assertThat("Wrong return type to be a setter", isSetter("setVal", String.class), is(false)), () -> assertThat("Wrong number of params to be a setter", isSetter("setVal2", String.class, String.class), is(false)), () -> assertThat("Wrong number of params to be a setter", isSetter("init2", String.class, String.class), is(false)), () -> assertThat("Correct setter definition", isSetter("setValue", String.class), is(true)), () -> assertThat("Correct setter definition", isSetter("init", String.class), is(true)) ); }
static boolean isSetter(Class<?> type, Method method) { if (method.getParameterCount() != 1) { return false; } if (method.isAnnotationPresent(Value.class)) { return true; } if (method.getDeclaringClass().equals(Object.class)) { return false; } if (method.getReturnType().equals(void.class)) { return true; } return method.getReturnType().equals(type); }
ReflectionUtil { static boolean isSetter(Class<?> type, Method method) { if (method.getParameterCount() != 1) { return false; } if (method.isAnnotationPresent(Value.class)) { return true; } if (method.getDeclaringClass().equals(Object.class)) { return false; } if (method.getReturnType().equals(void.class)) { return true; } return method.getReturnType().equals(type); } }
ReflectionUtil { static boolean isSetter(Class<?> type, Method method) { if (method.getParameterCount() != 1) { return false; } if (method.isAnnotationPresent(Value.class)) { return true; } if (method.getDeclaringClass().equals(Object.class)) { return false; } if (method.getReturnType().equals(void.class)) { return true; } return method.getReturnType().equals(type); } private  ReflectionUtil(); }
ReflectionUtil { static boolean isSetter(Class<?> type, Method method) { if (method.getParameterCount() != 1) { return false; } if (method.isAnnotationPresent(Value.class)) { return true; } if (method.getDeclaringClass().equals(Object.class)) { return false; } if (method.getReturnType().equals(void.class)) { return true; } return method.getReturnType().equals(type); } private  ReflectionUtil();  }
ReflectionUtil { static boolean isSetter(Class<?> type, Method method) { if (method.getParameterCount() != 1) { return false; } if (method.isAnnotationPresent(Value.class)) { return true; } if (method.getDeclaringClass().equals(Object.class)) { return false; } if (method.getReturnType().equals(void.class)) { return true; } return method.getReturnType().equals(type); } private  ReflectionUtil();   }