ProxyUserYamlSwapper implements YamlSwapper<YamlProxyUserConfiguration, ProxyUser> { @Override public ProxyUser swapToObject(final YamlProxyUserConfiguration yamlConfig) { if (Strings.isNullOrEmpty(yamlConfig.getAuthorizedSchemas())) { return new ProxyUser(yamlConfig.getPassword(), Collections.emptyList()); } return new ProxyUser(yamlConfig.getPassword(), Splitter.on(',').trimResults().splitToList(yamlConfig.getAuthorizedSchemas())); }  @Override YamlProxyUserConfiguration swapToYamlConfiguration(final ProxyUser data); @Override ProxyUser swapToObject(final YamlProxyUserConfiguration yamlConfig);  }
@Test public void assertSwapToObject() { YamlProxyUserConfiguration yamlProxyUserConfig = new YamlProxyUserConfiguration(); yamlProxyUserConfig.setAuthorizedSchemas("db1"); yamlProxyUserConfig.setPassword("pwd"); ProxyUser actual = new ProxyUserYamlSwapper().swapToObject(yamlProxyUserConfig); assertThat(actual.getAuthorizedSchemas().iterator().next(), is("db1")); assertThat(actual.getPassword(), is("pwd")); }
@Test public void assertSwapToObjectWithoutAuthorizedSchemas() { YamlProxyUserConfiguration yamlProxyUserConfig = new YamlProxyUserConfiguration(); yamlProxyUserConfig.setPassword("pwd"); ProxyUser actual = new ProxyUserYamlSwapper().swapToObject(yamlProxyUserConfig); assertThat(actual.getAuthorizedSchemas().size(), is(0)); }