JsfBeansAnnotationPostProcessor implements BeanPostProcessor { @Override public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { ReflectionUtils.doWithFields(bean.getClass(), field -> this.suppliers.forEach((annotation, supplier) -> { if (AnnotatedElementUtils.hasAnnotation(field, annotation)) { ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, bean, supplier.get()); } }), this::isAutowiredField); return bean; } JsfBeansAnnotationPostProcessor(JsfBeansAutoConfiguration jsfBeansAutoConfiguration); @Override Object postProcessBeforeInitialization(Object bean, String beanName);  }
@Test public void testApplicationMap() { HashMap<String, Object> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.applicationMap()).thenReturn(map); Object bean = new Object() { @Autowired @ApplicationMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).applicationMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testFlowMap() { HashMap<Object, Object> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.flowScope()).thenReturn(map); Object bean = new Object() { @Autowired @FlowMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).flowScope(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testHeaderMap() { HashMap<String, String> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.headerMap()).thenReturn(map); Object bean = new Object() { @Autowired @HeaderMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).headerMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testHeaderValuesMap() { HashMap<String, String[]> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.headerValuesMap()).thenReturn(map); Object bean = new Object() { @Autowired @HeaderValuesMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).headerValuesMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testInitParameterMap() { HashMap<String, String> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.initParameterMap()).thenReturn(map); Object bean = new Object() { @Autowired @InitParameterMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).initParameterMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testRequestCookieMap() { HashMap<String, Object> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.requestCookieMap()).thenReturn(map); Object bean = new Object() { @Autowired @RequestCookieMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).requestCookieMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testRequestMap() { HashMap<String, Object> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.requestMap()).thenReturn(map); Object bean = new Object() { @Autowired @RequestMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).requestMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testRequestParameterMap() { HashMap<String, String> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.requestParameterMap()).thenReturn(map); Object bean = new Object() { @Autowired @RequestParameterMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).requestParameterMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testRequestParameterValuesMap() { HashMap<String, String[]> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.requestParameterValuesMap()).thenReturn(map); Object bean = new Object() { @Autowired @RequestParameterValuesMap private Map<String, Object> map; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).requestParameterValuesMap(); assertThat(bean).hasFieldOrPropertyWithValue("map", map); }
@Test public void testSessionMap() { HashMap<String, Object> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.sessionMap()).thenReturn(map); Object bean = new Object() { @Autowired @SessionMap private Map<String, Object> sessionMap; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).sessionMap(); assertThat(bean).hasFieldOrPropertyWithValue("sessionMap", map); }
@Test public void testViewMap() { HashMap<String, Object> map = new HashMap<>(); when(this.jsfBeansAutoConfiguration.sessionMap()).thenReturn(map); Object bean = new Object() { @Inject @ViewMap private Map<String, Object> viewMap; }; this.jsfBeansAnnotationPostProcessor.postProcessBeforeInitialization(bean, ""); verify(this.jsfBeansAutoConfiguration).viewMap(); assertThat(bean).hasFieldOrPropertyWithValue("viewMap", map); }