JsTopicInterceptor implements Serializable { @AroundInvoke public Object processJsTopic(InvocationContext ctx) throws Exception { Method method = ctx.getMethod(); String topic = getStaticTopic(method); boolean jsonPayload = isJsonPayload(method); if (null == topic || topic.isEmpty()) { topic = getDynamicTopic(method, ctx.getParameters()); } if (null != topic && !topic.isEmpty()) { return proceedAndSendMessage(ctx, topic, jsonPayload); } throw new IllegalArgumentException("Topic name can't be empty."); }  @AroundInvoke Object processJsTopic(InvocationContext ctx);  }
@Test public void testProcessJsTopic() throws Exception { System.out.println("processJsTopic"); InvocationContext ctx = mock(InvocationContext.class); doReturn("STATICTOPIC").doReturn("").doReturn(null).when(instance).getStaticTopic(any(Method.class)); doReturn("DYNTOPIC").when(instance).getDynamicTopic(any(Method.class), any(Object[].class)); doReturn(false).when(instance).isJsonPayload(any(Method.class)); instance.processJsTopic(ctx); instance.processJsTopic(ctx); instance.processJsTopic(ctx); ArgumentCaptor<String> captors = ArgumentCaptor.forClass(String.class); verify(instance, times(3)).proceedAndSendMessage(eq(ctx), captors.capture(), eq(false)); List<String> topics = captors.getAllValues(); assertThat(topics.get(0)).isEqualTo("STATICTOPIC"); assertThat(topics.get(1)).isEqualTo("DYNTOPIC"); assertThat(topics.get(2)).isEqualTo("DYNTOPIC"); }