AnnotatedMethodInvoker { public Object invoke(Method method, Object[] arguments) throws Throwable { AnnotationRetriever retriever = new AnnotationRetriever(FeatureSwitch.class, invoke.getTargetClass()); Object result = null; try { FeatureSwitch featureSwitch = retriever.getAnnotation(method); FeatureResolver resolver = resolverFactory.createResolver(); if(resolver.isFeatureAvailable(featureSwitch)) { result = invoke.invoke(method, arguments); } } catch (AnnotationNotFoundException e) { result = invoke.invoke(method, arguments); } catch (InvokeException e) { throw e.getCause(); } return result; } AnnotatedMethodInvoker(final Object origin, FeatureResolverFactory resolverFactory);  AnnotatedMethodInvoker(MethodInvoke invoke, FeatureResolverFactory resolverFactory); Object invoke(Method method, Object[] arguments);  }
@Test public void invoke_WithFeature_ReturnsOriginalReturnValue() throws Throwable { Method sayHelloWithAnnotation = getMethod("sayHelloWithAnnotation"); when(resolver.isFeatureAvailable((FeatureSwitch)any())).thenReturn(true); assertEquals("result should be orgin value 'hello'", "hello", invoker.invoke(sayHelloWithAnnotation, new Object[]{})); }
@Test public void invoke_WithDisabledFeature_ReturnsNullValue() throws Throwable { Method sayHelloWithAnnotation = getMethod("sayHelloWithAnnotation"); when(resolver.isFeatureAvailable((FeatureSwitch)any())).thenReturn(false); assertNull("result should be null because feature is disabledStatus", invoker.invoke(sayHelloWithAnnotation, new Object[] {})); }
@Test public void invoke_WithoutFeature_ReturnsOrginalReturnValue() throws Throwable { Method sayHelloWithoutAnnotation = getMethod("sayHelloWithoutAnnotation"); assertEquals("result should be origin value 'hello'", "hello", invoker.invoke(sayHelloWithoutAnnotation, new Object[]{})); verify(resolver, times(0)).isFeatureAvailable((FeatureSwitch)any()); }