ShardingStrategyConfigurationYamlSwapper implements YamlSwapper<YamlShardingStrategyConfiguration, ShardingStrategyConfiguration> { @Override public ShardingStrategyConfiguration swapToObject(final YamlShardingStrategyConfiguration yamlConfig) { int shardingStrategyConfigCount = 0; ShardingStrategyConfiguration result = null; if (null != yamlConfig.getStandard()) { shardingStrategyConfigCount++; result = createStandardShardingStrategyConfiguration(yamlConfig.getStandard()); } if (null != yamlConfig.getComplex()) { shardingStrategyConfigCount++; result = createComplexShardingStrategyConfiguration(yamlConfig.getComplex()); } if (null != yamlConfig.getHint()) { shardingStrategyConfigCount++; result = createHintShardingStrategyConfiguration(yamlConfig.getHint()); } if (null != yamlConfig.getNone()) { shardingStrategyConfigCount++; result = new NoneShardingStrategyConfiguration(); } Preconditions.checkArgument(shardingStrategyConfigCount <= 1, "Only allowed 0 or 1 sharding strategy configuration."); return result; }  @Override YamlShardingStrategyConfiguration swapToYamlConfiguration(final ShardingStrategyConfiguration data); @Override ShardingStrategyConfiguration swapToObject(final YamlShardingStrategyConfiguration yamlConfig);  }
@Test public void assertSwapToObjectWithNone() { NoneShardingStrategyConfiguration actual = (NoneShardingStrategyConfiguration) shardingStrategyConfigurationYamlSwapper.swapToObject(createNoneShardingStrategyConfiguration()); assertThat(actual, instanceOf(NoneShardingStrategyConfiguration.class)); }
@Test public void assertSwapToObjectWithNull() { assertNull(shardingStrategyConfigurationYamlSwapper.swapToObject(new YamlShardingStrategyConfiguration())); }