@Override public void beforeInvocation( IInvokedMethod method, ITestResult testResult, ITestContext context) { int failed = findFailed(context); if (failed > 0) { LOG.error("Masking will not proceed. {} Configurations have failed", failed); return; } Method rmethod = method.getTestMethod().getConstructorOrMethod().getMethod(); if (rmethod.getAnnotation(Test.class) != null || rmethod.getAnnotation(BeforeClass.class) != null || rmethod.getAnnotation(BeforeTest.class) != null) { if (rmethod.getAnnotation(RunsWithController.class) != null || rmethod.getDeclaringClass().getAnnotation(RunsWithController.class) != null) { LOG.warn("Method or Class of {} asks Controller to be masked", rmethod.getName()); AnnotationsHelper p = SteviaContext.getSpringContext().getBean(AnnotationsHelper.class); try { p.maskExistingController(rmethod); masked = true; } catch (Throwable e) { throw new IllegalStateException("failed to replace controller", e); } } } }
@Override public void afterInvocation(IInvokedMethod method, ITestResult testResult, ITestContext context) { if (masked) { AnnotationsHelper p = SteviaContext.getSpringContext().getBean(AnnotationsHelper.class); try { p.controllerUnmask(); masked = false; } catch (Throwable e) { throw new IllegalStateException("failed to replace masked controller", e); } } }