SubscribeMethodInterceptor implements InstanceMethodsAroundInterceptor { @SuppressWarnings("unchecked") @Override public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) { ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo) objInst.getSkyWalkingDynamicField(); if (argumentsTypes[0] == Pattern.class) { requiredInfo.setTopics(Collections.singletonList(((Pattern) allArguments[0]).pattern())); } else { requiredInfo.setTopics((Collection<String>) allArguments[0]); } objInst.setSkyWalkingDynamicField(requiredInfo); }  @SuppressWarnings("unchecked") @Override void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        MethodInterceptResult result); @Override Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
        Object ret); @Override void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments,
        Class<?>[] argumentsTypes, Throwable t);  }
@Test public void testOnConsumer() { constructorInterceptor.beforeMethod(enhancedInstance, null, new Object[] {mockTopics}, new Class[] {Collection.class}, null); ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo) enhancedInstance.getSkyWalkingDynamicField(); assertThat(requiredInfo.getTopics(), is("test;test-1")); }
@Test public void testSubscribeForPattern() { constructorInterceptor.beforeMethod(enhancedInstance, null, new Object[] {mockTopicPattern}, new Class[] {Pattern.class}, null); ConsumerEnhanceRequiredInfo requiredInfo = (ConsumerEnhanceRequiredInfo) enhancedInstance.getSkyWalkingDynamicField(); assertThat(requiredInfo.getTopics(), is("test-.*")); }