@Test public void throwsWebApplicationExceptionWithStatus_BAD_REQUEST_WhenFieldAnnotatedWithCookieParamAnnotationCanNotBeResolved() throws Exception { when(cookieParameterResolver.resolve(isA(Parameter.class), eq(applicationContext))).thenThrow(new Exception()); FieldInjectorImpl fieldInjector = new FieldInjectorImpl(Resource.class.getDeclaredField("cookieParam"), parameterResolverFactory); Resource instance = new Resource(); thrown.expect(webApplicationExceptionWithStatusMatcher(BAD_REQUEST)); fieldInjector.inject(instance, applicationContext); }
@Override public void inject(Object resource, ApplicationContext context) { try { Object value = null; if (annotation != null) { value = parameterResolverFactory.createParameterResolver(annotation).resolve(this, context); } else { DependencySupplier dependencies = context.getDependencySupplier(); if (dependencies != null) { value = dependencies.getInstance(this); } } if (value != null) { if (setter != null) { setter.invoke(resource, value); } else { if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true); } field.set(resource, value); } } } catch (Exception e) { if (annotation != null) { Class<?> annotationType = annotation.annotationType(); if (annotationType == PathParam.class || annotationType == QueryParam.class || annotationType == MatrixParam.class) { throw new WebApplicationException(e, Response.status(NOT_FOUND).build()); } throw new WebApplicationException(e, Response.status(BAD_REQUEST).build()); } throw new WebApplicationException(e, Response.status(INTERNAL_SERVER_ERROR).build()); } }
FieldInjectorImpl implements FieldInjector { @Override public void inject(Object resource, ApplicationContext context) { try { Object value = null; if (annotation != null) { value = parameterResolverFactory.createParameterResolver(annotation).resolve(this, context); } else { DependencySupplier dependencies = context.getDependencySupplier(); if (dependencies != null) { value = dependencies.getInstance(this); } } if (value != null) { if (setter != null) { setter.invoke(resource, value); } else { if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true); } field.set(resource, value); } } } catch (Exception e) { if (annotation != null) { Class<?> annotationType = annotation.annotationType(); if (annotationType == PathParam.class || annotationType == QueryParam.class || annotationType == MatrixParam.class) { throw new WebApplicationException(e, Response.status(NOT_FOUND).build()); } throw new WebApplicationException(e, Response.status(BAD_REQUEST).build()); } throw new WebApplicationException(e, Response.status(INTERNAL_SERVER_ERROR).build()); } } }
FieldInjectorImpl implements FieldInjector { @Override public void inject(Object resource, ApplicationContext context) { try { Object value = null; if (annotation != null) { value = parameterResolverFactory.createParameterResolver(annotation).resolve(this, context); } else { DependencySupplier dependencies = context.getDependencySupplier(); if (dependencies != null) { value = dependencies.getInstance(this); } } if (value != null) { if (setter != null) { setter.invoke(resource, value); } else { if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true); } field.set(resource, value); } } } catch (Exception e) { if (annotation != null) { Class<?> annotationType = annotation.annotationType(); if (annotationType == PathParam.class || annotationType == QueryParam.class || annotationType == MatrixParam.class) { throw new WebApplicationException(e, Response.status(NOT_FOUND).build()); } throw new WebApplicationException(e, Response.status(BAD_REQUEST).build()); } throw new WebApplicationException(e, Response.status(INTERNAL_SERVER_ERROR).build()); } } FieldInjectorImpl(Field field, ParameterResolverFactory parameterResolverFactory); }
FieldInjectorImpl implements FieldInjector { @Override public void inject(Object resource, ApplicationContext context) { try { Object value = null; if (annotation != null) { value = parameterResolverFactory.createParameterResolver(annotation).resolve(this, context); } else { DependencySupplier dependencies = context.getDependencySupplier(); if (dependencies != null) { value = dependencies.getInstance(this); } } if (value != null) { if (setter != null) { setter.invoke(resource, value); } else { if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true); } field.set(resource, value); } } } catch (Exception e) { if (annotation != null) { Class<?> annotationType = annotation.annotationType(); if (annotationType == PathParam.class || annotationType == QueryParam.class || annotationType == MatrixParam.class) { throw new WebApplicationException(e, Response.status(NOT_FOUND).build()); } throw new WebApplicationException(e, Response.status(BAD_REQUEST).build()); } throw new WebApplicationException(e, Response.status(INTERNAL_SERVER_ERROR).build()); } } FieldInjectorImpl(Field field, ParameterResolverFactory parameterResolverFactory); @Override Annotation getAnnotation(); @Override Annotation[] getAnnotations(); @Override String getDefaultValue(); @Override Class<?> getParameterClass(); @Override Type getGenericType(); @Override boolean isEncoded(); @Override String getName(); @Override void inject(Object resource, ApplicationContext context); @Override String toString(); }
FieldInjectorImpl implements FieldInjector { @Override public void inject(Object resource, ApplicationContext context) { try { Object value = null; if (annotation != null) { value = parameterResolverFactory.createParameterResolver(annotation).resolve(this, context); } else { DependencySupplier dependencies = context.getDependencySupplier(); if (dependencies != null) { value = dependencies.getInstance(this); } } if (value != null) { if (setter != null) { setter.invoke(resource, value); } else { if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true); } field.set(resource, value); } } } catch (Exception e) { if (annotation != null) { Class<?> annotationType = annotation.annotationType(); if (annotationType == PathParam.class || annotationType == QueryParam.class || annotationType == MatrixParam.class) { throw new WebApplicationException(e, Response.status(NOT_FOUND).build()); } throw new WebApplicationException(e, Response.status(BAD_REQUEST).build()); } throw new WebApplicationException(e, Response.status(INTERNAL_SERVER_ERROR).build()); } } FieldInjectorImpl(Field field, ParameterResolverFactory parameterResolverFactory); @Override Annotation getAnnotation(); @Override Annotation[] getAnnotations(); @Override String getDefaultValue(); @Override Class<?> getParameterClass(); @Override Type getGenericType(); @Override boolean isEncoded(); @Override String getName(); @Override void inject(Object resource, ApplicationContext context); @Override String toString();  }