MonitorComponentConditional implements ConfigurationCondition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { Environment env = context.getEnvironment(); MultiValueMap<String, Object> map = metadata .getAllAnnotationAttributes(ConditionalOnMonitorComponent.class.getName()); List<Object> value = map.get("value"); if (CollectionUtils.isEmpty(value)) { return false; } String componentName = (String) value.get(0); List<String> activeComponents = getComponents(context); boolean active = activeComponents.contains(componentName); active = active ? isActiveByZoneInfo(env, componentName) : false; LOGGER.info("monitor component:{}, active:{}", componentName, active); return active; }  @Override ConfigurationPhase getConfigurationPhase(); @Override boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata);  }
@Test public void testMatch() { MonitorComponentConditional m = new MonitorComponentConditional(); ConditionContext context = Mockito.mock(ConditionContext.class); MockEnvironment env = new MockEnvironment(); env.setProperty("components.active", "metrics"); when(context.getEnvironment()).thenReturn(env); AnnotatedTypeMetadata atm = Mockito.mock(AnnotatedTypeMetadata.class); MultiValueMap<String, Object> map = new LinkedMultiValueMap(); map.put("value", Lists.newArrayList("metrics")); when(atm.getAllAnnotationAttributes(anyString())).thenReturn(map); Assert.assertTrue(m.matches(context, atm)); }