HeaderParameterResolver implements ParameterResolver<HeaderParam> { @Override public Object resolve(Parameter parameter, ApplicationContext context) throws Exception { String param = this.headerParam.value(); TypeProducer typeProducer = typeProducerFactory.createTypeProducer(parameter.getParameterClass(), parameter.getGenericType()); return typeProducer.createValue(param, context.getHttpHeaders().getRequestHeaders(), parameter.getDefaultValue()); } HeaderParameterResolver(HeaderParam headerParam, TypeProducerFactory typeProducerFactory); @Override Object resolve(Parameter parameter, ApplicationContext context);  }
@Test public void retrievesHeaderFromRequest() throws Exception { when(typeProducer.createValue("foo", headers, null)).thenReturn(headers.getFirst("foo")); Object resolvedHeader = headerParameterResolver.resolve(parameter, applicationContext); assertEquals(headers.getFirst("foo"), resolvedHeader); }
@Test public void retrievesDefaultValueWhenHeaderDoesNotPresentInRequest() throws Exception { when(parameter.getDefaultValue()).thenReturn("default value"); when(typeProducer.createValue("foo", headers, "default value")).thenReturn("default value"); Object resolvedHeader = headerParameterResolver.resolve(parameter, applicationContext); assertEquals("default value", resolvedHeader); }