WebServiceInterfaceValidator { void validateResponseBeanType(Type beanType, Method method) { if (void.class == beanType) return; boolean isGenericButNotOptional = beanType instanceof ParameterizedType && !GenericTypes.isGenericOptional(beanType); boolean isValueType = beanType instanceof Class && isValueType((Class<?>) beanType); if (isGenericButNotOptional || isValueType) throw new Error(format("response bean type must be bean class or Optional<T>, type={}, method={}", beanType.getTypeName(), Methods.path(method))); if (responseBeanWriter != null) responseBeanWriter.register(beanType, validator); if (responseBeanReader != null) responseBeanReader.register(beanType, validator); } WebServiceInterfaceValidator(Class<?> serviceInterface, BeanClassValidator validator); void validate(); public RequestBeanReader requestBeanReader; public RequestBeanWriter requestBeanWriter; public ResponseBeanReader responseBeanReader; public ResponseBeanWriter responseBeanWriter; }
@Test void validateResponseBeanType() throws NoSuchMethodException { var validator = new WebServiceInterfaceValidator(TestWebService.class, new BeanClassValidator()); var method = TestWebService.class.getDeclaredMethod("get", Integer.class); assertThatThrownBy(() -> validator.validateResponseBeanType(Integer.class, method)) .isInstanceOf(Error.class).hasMessageContaining("response bean type must be bean class or Optional<T>"); assertThatThrownBy(() -> validator.validateResponseBeanType(Types.map(String.class, String.class), method)) .isInstanceOf(Error.class).hasMessageContaining("response bean type must be bean class or Optional<T>"); }