### Question:
LookoutSubscriber implements EventSubscriber { @Override public void onEvent(Event event) { if (null == event) { return; } Class eventClass = event.getClass(); if (eventClass == SubscriberProcessEvent.class) { SubscriberProcessEvent subscriberProcessEvent = (SubscriberProcessEvent) event; Subscriber subscriber = subscriberProcessEvent.getSubscriber(); if (null == subscriber) { return; } RegistryClientConfig config = subscriberProcessEvent.getConfig(); if (null == config) { return; } Id id = Lookout .registry() .createId(REGISTRY_PROCESS_SUBSCRIBER) .withTag(METRIC_DATA_ID_NAME, StringUtils.defaultString(subscriber.getDataId())) .withTag(METRIC_INSTANCE_ID_NAME, StringUtils.defaultString(config.getInstanceId())); MixinMetric mixin = Lookout.registry().mixinMetric(id); mixin.counter(METRIC_COUNT_NAME).inc(); mixin.timer(METRIC_TIME_NAME).record( subscriberProcessEvent.getEnd() - subscriberProcessEvent.getStart(), TimeUnit.MILLISECONDS); if (null == subscriberProcessEvent.getThrowable()) { mixin.counter(METRIC_SUCCESS_NAME).inc(); } } else if (eventClass == ConfiguratorProcessEvent.class) { ConfiguratorProcessEvent configuratorProcessEvent = (ConfiguratorProcessEvent) event; Configurator configurator = configuratorProcessEvent.getConfigurator(); if (null == configurator) { return; } RegistryClientConfig config = configuratorProcessEvent.getConfig(); Id id = Lookout .registry() .createId(REGISTRY_PROCESS_CONFIGURATOR) .withTag(METRIC_DATA_ID_NAME, StringUtils.defaultString(configurator.getDataId())) .withTag(METRIC_INSTANCE_ID_NAME, StringUtils.defaultString(config.getInstanceId())); MixinMetric mixin = Lookout.registry().mixinMetric(id); mixin.counter(METRIC_COUNT_NAME).inc(); mixin.timer(METRIC_TIME_NAME).record( configuratorProcessEvent.getEnd() - configuratorProcessEvent.getStart(), TimeUnit.MILLISECONDS); if (null == configuratorProcessEvent.getThrowable()) { mixin.counter(METRIC_SUCCESS_NAME).inc(); } } }  @Override boolean isSync(); @Override void onEvent(Event event);  }### Answer:
@Test public void onSubscriberProcessEvent() { lookoutSubscriber = new LookoutSubscriber(); SubscriberProcessEvent event = new SubscriberProcessEvent(); Subscriber subscriber = mock(Subscriber.class); event.setSubscriber(subscriber); event.setConfig(DefaultRegistryClientConfigBuilder.start().setInstanceId("000001").build()); event.setStart(System.currentTimeMillis()); event.setEnd(System.currentTimeMillis() + 1); event.setThrowable(null); when(subscriber.getDataId()).thenReturn("test-dataId"); lookoutSubscriber.onEvent(event); verify(subscriber, times(1)).getDataId(); }
@Test public void onConfiguratorProcessEvent() { lookoutSubscriber = new LookoutSubscriber(); ConfiguratorProcessEvent event = new ConfiguratorProcessEvent(); Configurator configurator = mock(Configurator.class); event.setConfigurator(configurator); event.setConfig(DefaultRegistryClientConfigBuilder.start().setInstanceId("000001").build()); event.setStart(System.currentTimeMillis()); event.setEnd(System.currentTimeMillis() + 1); event.setThrowable(null); when(configurator.getDataId()).thenReturn("test-dataId"); lookoutSubscriber.onEvent(event); verify(configurator, times(1)).getDataId(); }