@Override public Object invoke(MethodInvocation invocation) throws Throwable { String methodName = invocation.getMethod().getName(); if (ordered && methodName.equals("getOrder")) { return invocation.proceed(); } Set<MethodInvoker> invokers = invokerMap.get(methodName); if (invokers == null) { return null; } ExitStatus status = null; for (MethodInvoker invoker : invokers) { Object retVal = invoker.invokeMethod(invocation.getArguments()); if (retVal instanceof ExitStatus) { if (status != null) { status = status.and((ExitStatus) retVal); } else { status = (ExitStatus) retVal; } } } // The only possible return values are ExitStatus or int (from Ordered) return status; }
@Test public void testMethod() throws Exception{ Method method = TestClass.class.getMethod("before"); MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, method); methodInvoker.invokeMethod(value); assertTrue(testClass.beforeCalled); }
@Test(expected=IllegalArgumentException.class) public void testMethodWithTooManyArguments() throws Exception{ Method method = TestClass.class.getMethod("beforeWithTooManyArguments", String.class, int.class); MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, method); methodInvoker.invokeMethod(value); assertFalse(testClass.beforeCalled); }
@Test public void testMethodWithArgument() throws Exception{ MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, "argumentTest", Object.class); methodInvoker.invokeMethod(new Object()); assertTrue(testClass.argumentTestCalled); }
@Test public void testMethodWithExecution() throws Exception{ Method method = TestClass.class.getMethod("beforeWithArgument", String.class); MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, method); methodInvoker.invokeMethod(value); assertTrue(testClass.beforeCalled); }
@Test(expected=IllegalArgumentException.class) public void testMethodByNameWithTooManyArguments() throws Exception{ MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, "beforeWithTooManyArguments", String.class); methodInvoker.invokeMethod(value); assertFalse(testClass.beforeCalled); }
@Test public void testMethodByName() throws Exception{ MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, "before", String.class); methodInvoker.invokeMethod(value); assertTrue(testClass.beforeCalled); }
@Test public void testMethodByNameWithExecution() throws Exception{ MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, "beforeWithArgument", String.class); methodInvoker.invokeMethod(value); assertTrue(testClass.beforeCalled); }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { String methodName = invocation.getMethod().getName(); if (ordered && methodName.equals("getOrder")) { return invocation.proceed(); } Set<MethodInvoker> invokers = invokerMap.get(methodName); if (invokers == null) { return null; } ExitStatus status = null; for (MethodInvoker invoker : invokers) { Object retVal = invoker.invokeMethod(invocation.getArguments()); if (retVal instanceof ExitStatus) { if (status != null) { status = status.and((ExitStatus) retVal); } else { status = (ExitStatus) retVal; } } } // The only possible return values are ExitStatus or int (from Ordered) return status; }
public Object invoke(MethodInvocation invocation) throws Throwable { String methodName = invocation.getMethod().getName(); if (ordered && methodName.equals("getOrder")) { return invocation.proceed(); } Set<MethodInvoker> invokers = invokerMap.get(methodName); if (invokers == null) { return null; } ExitStatus status = null; for (MethodInvoker invoker : invokers) { Object retVal = invoker.invokeMethod(invocation.getArguments()); if (retVal instanceof ExitStatus) { if (status != null) { status = status.and((ExitStatus) retVal); } else { status = (ExitStatus) retVal; } } } // The only possible return values are ExitStatus or int (from Ordered) return status; }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { String methodName = invocation.getMethod().getName(); if (ordered && methodName.equals("getOrder")) { return invocation.proceed(); } Set<MethodInvoker> invokers = invokerMap.get(methodName); if (invokers == null) { return null; } ExitStatus status = null; for (MethodInvoker invoker : invokers) { Object retVal = invoker.invokeMethod(invocation.getArguments()); if (retVal instanceof ExitStatus) { if (status != null) { status = status.and((ExitStatus) retVal); } else { status = (ExitStatus) retVal; } } } // The only possible return values are ExitStatus or int (from Ordered) return status; }
@Override public Object invoke(MethodInvocation invocation) throws Throwable { String methodName = invocation.getMethod().getName(); if (ordered && methodName.equals("getOrder")) { return invocation.proceed(); } Set<MethodInvoker> invokers = invokerMap.get(methodName); if (invokers == null) { return null; } ExitStatus status = null; for (MethodInvoker invoker : invokers) { Object retVal = invoker.invokeMethod(invocation.getArguments()); if (retVal instanceof ExitStatus) { if (status != null) { status = status.and((ExitStatus) retVal); } else { status = (ExitStatus) retVal; } } } // The only possible return values are ExitStatus or int (from Ordered) return status; }