DefaultMethodEndpointAdapter extends AbstractMethodEndpointAdapter implements BeanClassLoaderAware, InitializingBean { private boolean supportsReturnType(MethodParameter methodReturnType) { if (Void.TYPE.equals(methodReturnType.getParameterType())) { return true; } for (MethodReturnValueHandler methodReturnValueHandler : methodReturnValueHandlers) { if (methodReturnValueHandler.supportsReturnType(methodReturnType)) { return true; } } return false; }  List<MethodArgumentResolver> getMethodArgumentResolvers(); void setMethodArgumentResolvers(List<MethodArgumentResolver> methodArgumentResolvers); List<MethodArgumentResolver> getCustomMethodArgumentResolvers(); void setCustomMethodArgumentResolvers(List<MethodArgumentResolver> customMethodArgumentResolvers); List<MethodReturnValueHandler> getMethodReturnValueHandlers(); void setMethodReturnValueHandlers(List<MethodReturnValueHandler> methodReturnValueHandlers); List<MethodReturnValueHandler> getCustomMethodReturnValueHandlers(); void setCustomMethodReturnValueHandlers(List<MethodReturnValueHandler> customMethodReturnValueHandlers); @Override void setBeanClassLoader(ClassLoader classLoader); @Override void afterPropertiesSet();  }
@Test public void supportsSupported() throws Exception { expect(argumentResolver1.supportsParameter(isA(MethodParameter.class))).andReturn(true); expect(argumentResolver1.supportsParameter(isA(MethodParameter.class))).andReturn(false); expect(argumentResolver2.supportsParameter(isA(MethodParameter.class))).andReturn(true); expect(returnValueHandler.supportsReturnType(isA(MethodParameter.class))).andReturn(true); replay(argumentResolver1, argumentResolver2, returnValueHandler); boolean result = adapter.supports(supportedEndpoint); assertTrue("adapter does not support method", result); verify(argumentResolver1, argumentResolver2, returnValueHandler); }
@Test public void supportsUnsupportedReturnType() throws Exception { expect(argumentResolver1.supportsParameter(isA(MethodParameter.class))).andReturn(true); expect(returnValueHandler.supportsReturnType(isA(MethodParameter.class))).andReturn(false); replay(argumentResolver1, argumentResolver2, returnValueHandler); boolean result = adapter.supports(unsupportedEndpoint); assertFalse("adapter does not support method", result); verify(argumentResolver1, argumentResolver2, returnValueHandler); }
@Test public void invokeSupported() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage("<root xmlns='http: MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); String value = "Foo"; expect(argumentResolver1.supportsParameter(isA(MethodParameter.class))).andReturn(true); expect(argumentResolver1.resolveArgument(eq(messageContext), isA(MethodParameter.class))).andReturn(value); expect(argumentResolver1.supportsParameter(isA(MethodParameter.class))).andReturn(false); expect(argumentResolver2.supportsParameter(isA(MethodParameter.class))).andReturn(true); expect(argumentResolver2.resolveArgument(eq(messageContext), isA(MethodParameter.class))) .andReturn(new Integer(42)); expect(returnValueHandler.supportsReturnType(isA(MethodParameter.class))).andReturn(true); returnValueHandler.handleReturnValue(eq(messageContext), isA(MethodParameter.class), eq(value)); replay(argumentResolver1, argumentResolver2, returnValueHandler); adapter.invoke(messageContext, supportedEndpoint); assertEquals("Invalid argument passed", value, supportedArgument); verify(argumentResolver1, argumentResolver2, returnValueHandler); }
@Test public void invokeNullReturnValue() throws Exception { MockWebServiceMessage request = new MockWebServiceMessage("<root xmlns='http: MessageContext messageContext = new DefaultMessageContext(request, new MockWebServiceMessageFactory()); String value = "Foo"; expect(argumentResolver1.supportsParameter(isA(MethodParameter.class))).andReturn(true); expect(argumentResolver1.resolveArgument(eq(messageContext), isA(MethodParameter.class))).andReturn(value); expect(returnValueHandler.supportsReturnType(isA(MethodParameter.class))).andReturn(true); returnValueHandler.handleReturnValue(eq(messageContext), isA(MethodParameter.class), isNull()); replay(argumentResolver1, argumentResolver2, returnValueHandler); adapter.invoke(messageContext, nullReturnValue); assertEquals("Invalid argument passed", value, supportedArgument); verify(argumentResolver1, argumentResolver2, returnValueHandler); }