ShardingSpringBootCondition extends SpringBootCondition { @Override public ConditionOutcome getMatchOutcome(final ConditionContext conditionContext, final AnnotatedTypeMetadata annotatedTypeMetadata) { return PropertyUtil.containPropertyPrefix(conditionContext.getEnvironment(), SHARDING_PREFIX) ? ConditionOutcome.match() : ConditionOutcome.noMatch("Can't find ShardingSphere sharding rule configuration in local file."); }  @Override ConditionOutcome getMatchOutcome(final ConditionContext conditionContext, final AnnotatedTypeMetadata annotatedTypeMetadata);  }
@Test public void assertNotMatch() { MockEnvironment mockEnvironment = new MockEnvironment(); mockEnvironment.setProperty("spring.shardingsphere.rules.encrypt.encryptors.aes_encryptor.type", "AES"); ConditionContext context = mock(ConditionContext.class); AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class); when(context.getEnvironment()).thenReturn(mockEnvironment); ShardingSpringBootCondition condition = new ShardingSpringBootCondition(); ConditionOutcome matchOutcome = condition.getMatchOutcome(context, metadata); assertFalse(matchOutcome.isMatch()); }
@Test public void assertMatch() { MockEnvironment mockEnvironment = new MockEnvironment(); mockEnvironment.setProperty("spring.shardingsphere.rules.sharding.binding-tables", "t_order"); ConditionContext context = mock(ConditionContext.class); AnnotatedTypeMetadata metadata = mock(AnnotatedTypeMetadata.class); when(context.getEnvironment()).thenReturn(mockEnvironment); ShardingSpringBootCondition condition = new ShardingSpringBootCondition(); ConditionOutcome matchOutcome = condition.getMatchOutcome(context, metadata); assertTrue(matchOutcome.isMatch()); }