### Question:
RequiredDataAdvice implements MethodBeforeAdvice { protected static boolean isHandlerMarkedAsDisabled(Class<? extends RequiredDataHandler> handlerType, Field field) { if (!field.isAnnotationPresent(DisableHandlers.class)) { return false; } else { for (Class<? extends RequiredDataHandler> h : field.getAnnotation(DisableHandlers.class).handlerTypes()) { if (h.isAssignableFrom(handlerType)) { return true; } } } return false; }  @Override @SuppressWarnings("unchecked") void before(Method method, Object[] args, Object target); static void recursivelyHandle(Class<H> handlerType, OpenmrsObject openmrsObject,
	        String reason); @SuppressWarnings("unchecked") static void recursivelyHandle(Class<H> handlerType, OpenmrsObject openmrsObject,
	        User currentUser, Date currentDate, String other, List<OpenmrsObject> alreadyHandled);  }### Answer:
@Test public void isHandlerMarkedAsDisabled_shouldReturnTrueIfHandlerDisabled() { Field persons = null; for (Field field : Reflect.getAllFields(ClassWithDisableHandlersAnnotation.class)) { if (field.getName().equals("persons")) { persons = field; } } Assert.assertTrue(RequiredDataAdvice.isHandlerMarkedAsDisabled(SaveHandler.class, persons)); Assert.assertTrue(RequiredDataAdvice.isHandlerMarkedAsDisabled(VoidHandler.class, persons)); }
@Test public void isHandlerMarkedAsDisabled_shouldReturnFalseIfHandlerNotDisabled() { Field persons = null; for (Field field : Reflect.getAllFields(ClassWithDisableHandlersAnnotation.class)) { if (field.getName().equals("persons")) { persons = field; } } Assert.assertFalse(RequiredDataAdvice.isHandlerMarkedAsDisabled(RetireHandler.class, persons)); }
@Test public void isHandlerMarkedAsDisabled_shouldReturnFalseIfFieldNotAnnotated() { Field persons = null; for (Field field : Reflect.getAllFields(ClassWithDisableHandlersAnnotation.class)) { if (field.getName().equals("notAnnotatedPersons")) { persons = field; } } Assert.assertFalse(RequiredDataAdvice.isHandlerMarkedAsDisabled(RetireHandler.class, persons)); }
@Test public void isHandlerMarkedAsDisabled_shouldReturnTrueIfSupertypeHandlerDisabled() { Field persons = null; for (Field field : Reflect.getAllFields(ClassWithDisableHandlersAnnotationForSupertype.class)) { if (field.getName().equals("persons")) { persons = field; } } Assert.assertTrue(RequiredDataAdvice.isHandlerMarkedAsDisabled(SaveHandler.class, persons)); Assert.assertTrue(RequiredDataAdvice.isHandlerMarkedAsDisabled(VoidHandler.class, persons)); Assert.assertTrue(RequiredDataAdvice.isHandlerMarkedAsDisabled(UnvoidHandler.class, persons)); Assert.assertTrue(RequiredDataAdvice.isHandlerMarkedAsDisabled(RetireHandler.class, persons)); Assert.assertTrue(RequiredDataAdvice.isHandlerMarkedAsDisabled(UnretireHandler.class, persons)); }
@Test public void isHandlerMarkedAsDisabled_shouldReturnTrueIfHandlerDisabledOnMetadata() { Field persons = null; for (Field field : Reflect.getAllFields(MetadataClassWithDisableHandlersAnnotation.class)) { if (field.getName().equals("concepts")) { persons = field; } } Assert.assertTrue(RequiredDataAdvice.isHandlerMarkedAsDisabled(UnretireHandler.class, persons)); }
@Test public void isHandlerMarkedAsDisabled_shouldReturnFalseIfHandlerNotDisabledOnMetatdata() { Field persons = null; for (Field field : Reflect.getAllFields(MetadataClassWithDisableHandlersAnnotation.class)) { if (field.getName().equals("concepts")) { persons = field; } } Assert.assertFalse(RequiredDataAdvice.isHandlerMarkedAsDisabled(RetireHandler.class, persons)); }