LineMessageHandlerSupport { @VisibleForTesting void refresh() { final Map<String, Object> handlerBeanMap = applicationContext.getBeansWithAnnotation(LineMessageHandler.class); final List<HandlerMethod> collect = handlerBeanMap .values().stream() .flatMap((Object bean) -> { final Method[] uniqueDeclaredMethods = ReflectionUtils.getUniqueDeclaredMethods(bean.getClass()); return Arrays.stream(uniqueDeclaredMethods) .map(method -> getMethodHandlerMethodFunction(bean, method)) .filter(Objects::nonNull); }) .sorted(HANDLER_METHOD_PRIORITY_COMPARATOR) .collect(Collectors.toList()); log.info("Registered LINE Messaging API event handler: count = {}", collect.size()); collect.forEach(item -> log.info("Mapped \"{}\" onto {}", item.getSupportType(), item.getHandler().toGenericString())); eventConsumerList = collect; } @Autowired  LineMessageHandlerSupport(
            final ReplyByReturnValueConsumer.Factory returnValueConsumerFactory,
            final ConfigurableApplicationContext applicationContext); @PostMapping("${line.bot.handler.path:/callback}") void callback(@LineBotMessages List<Event> events);  }
@Test public void testRefreshForOneItem() throws Exception { when(applicationContext.getBeansWithAnnotation(LineMessageHandler.class)) .thenReturn(singletonMap("bean", new MessageHandler())); target.refresh(); assertThat(target.eventConsumerList).hasSize(1); HandlerMethod handlerMethod = target.eventConsumerList.get(0); assertThat(handlerMethod.getSupportType()) .isInstanceOf(Predicate.class); assertThat(handlerMethod.getHandler()) .isInstanceOf(Method.class); }
@Test public void testPrioritySelection() throws Exception { when(applicationContext.getBeansWithAnnotation(LineMessageHandler.class)) .thenReturn(ImmutableMap.of("bean", new MessageHandler(), "anothrer", new AnotherMessageHandler())); target.refresh(); assertThat(target.eventConsumerList).hasSize(3); assertThat(target.eventConsumerList.get(0).getHandler().getName()) .isEqualTo("textMessageEventHandler"); assertThat(target.eventConsumerList.get(1).getHandler().getName()) .isEqualTo("generalMessageHandler"); assertThat(target.eventConsumerList.get(2).getHandler().getName()) .isEqualTo("defaultEventHandler"); }