@Test(expectedExceptions = RuntimeException.class, expectedExceptionsMessageRegExp = "healthcheck annotation on non-getter .*getVoid\\(\\)") public void testInvalidGetter() { HealthBean.forTarget(new Object() { @HealthCheck("Void") public void getVoid() { } }); }
public static HealthBean forTarget(Object target) { requireNonNull(target, "target is null"); ImmutableList.Builder<HealthBeanAttribute> attributes = ImmutableList.builder(); for (Map.Entry<Method, Method> entry : AnnotationUtils.findAnnotatedMethods(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class).entrySet()) { Method concreteMethod = entry.getKey(); Method annotatedMethod = entry.getValue(); if (!isValidGetter(concreteMethod)) { throw new RuntimeException("healthcheck annotation on non-getter " + annotatedMethod.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withConcreteGetter(concreteMethod) .withAnnotatedGetter(annotatedMethod) .build()); } for (Field field : AnnotationUtils.findAnnotatedFields(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class)) { if (!AtomicReference.class.isAssignableFrom(field.getType())) { throw new RuntimeException("healthcheck annotation on non-AtomicReference field " + field.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withField(field) .build()); } return new AutoValue_HealthBean(attributes.build()); }
HealthBean { public static HealthBean forTarget(Object target) { requireNonNull(target, "target is null"); ImmutableList.Builder<HealthBeanAttribute> attributes = ImmutableList.builder(); for (Map.Entry<Method, Method> entry : AnnotationUtils.findAnnotatedMethods(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class).entrySet()) { Method concreteMethod = entry.getKey(); Method annotatedMethod = entry.getValue(); if (!isValidGetter(concreteMethod)) { throw new RuntimeException("healthcheck annotation on non-getter " + annotatedMethod.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withConcreteGetter(concreteMethod) .withAnnotatedGetter(annotatedMethod) .build()); } for (Field field : AnnotationUtils.findAnnotatedFields(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class)) { if (!AtomicReference.class.isAssignableFrom(field.getType())) { throw new RuntimeException("healthcheck annotation on non-AtomicReference field " + field.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withField(field) .build()); } return new AutoValue_HealthBean(attributes.build()); } }
HealthBean { public static HealthBean forTarget(Object target) { requireNonNull(target, "target is null"); ImmutableList.Builder<HealthBeanAttribute> attributes = ImmutableList.builder(); for (Map.Entry<Method, Method> entry : AnnotationUtils.findAnnotatedMethods(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class).entrySet()) { Method concreteMethod = entry.getKey(); Method annotatedMethod = entry.getValue(); if (!isValidGetter(concreteMethod)) { throw new RuntimeException("healthcheck annotation on non-getter " + annotatedMethod.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withConcreteGetter(concreteMethod) .withAnnotatedGetter(annotatedMethod) .build()); } for (Field field : AnnotationUtils.findAnnotatedFields(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class)) { if (!AtomicReference.class.isAssignableFrom(field.getType())) { throw new RuntimeException("healthcheck annotation on non-AtomicReference field " + field.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withField(field) .build()); } return new AutoValue_HealthBean(attributes.build()); }  }
HealthBean { public static HealthBean forTarget(Object target) { requireNonNull(target, "target is null"); ImmutableList.Builder<HealthBeanAttribute> attributes = ImmutableList.builder(); for (Map.Entry<Method, Method> entry : AnnotationUtils.findAnnotatedMethods(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class).entrySet()) { Method concreteMethod = entry.getKey(); Method annotatedMethod = entry.getValue(); if (!isValidGetter(concreteMethod)) { throw new RuntimeException("healthcheck annotation on non-getter " + annotatedMethod.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withConcreteGetter(concreteMethod) .withAnnotatedGetter(annotatedMethod) .build()); } for (Field field : AnnotationUtils.findAnnotatedFields(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class)) { if (!AtomicReference.class.isAssignableFrom(field.getType())) { throw new RuntimeException("healthcheck annotation on non-AtomicReference field " + field.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withField(field) .build()); } return new AutoValue_HealthBean(attributes.build()); }  abstract Collection<HealthBeanAttribute> getAttributes(); static HealthBean forTarget(Object target); }
HealthBean { public static HealthBean forTarget(Object target) { requireNonNull(target, "target is null"); ImmutableList.Builder<HealthBeanAttribute> attributes = ImmutableList.builder(); for (Map.Entry<Method, Method> entry : AnnotationUtils.findAnnotatedMethods(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class).entrySet()) { Method concreteMethod = entry.getKey(); Method annotatedMethod = entry.getValue(); if (!isValidGetter(concreteMethod)) { throw new RuntimeException("healthcheck annotation on non-getter " + annotatedMethod.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withConcreteGetter(concreteMethod) .withAnnotatedGetter(annotatedMethod) .build()); } for (Field field : AnnotationUtils.findAnnotatedFields(target.getClass(), HealthCheck.class, HealthCheckRemoveFromRotation.class, HealthCheckRestartDesired.class)) { if (!AtomicReference.class.isAssignableFrom(field.getType())) { throw new RuntimeException("healthcheck annotation on non-AtomicReference field " + field.toGenericString()); } attributes.addAll(new HealthBeanAttributeBuilder() .onInstance(target) .withField(field) .build()); } return new AutoValue_HealthBean(attributes.build()); }  abstract Collection<HealthBeanAttribute> getAttributes(); static HealthBean forTarget(Object target);  }