Skip to content

Commit

Permalink
refs: #248 Don't discriminate against common sense converters
Browse files Browse the repository at this point in the history
rather fix the existing TCK test
  • Loading branch information
struberg committed Nov 17, 2017
1 parent 12368e9 commit 152029b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
Expand Up @@ -47,11 +47,11 @@ public class AutoDiscoveredConfigSourceTest extends Arquillian {
public static WebArchive deploy() {
JavaArchive testJar = ShrinkWrap
.create(JavaArchive.class, "customConfigSourceTest.jar")
.addClasses(AutoDiscoveredConfigSourceTest.class, CustomDbConfigSource.class, Pizza.class, PizzaConverter.class)
.addClasses(AutoDiscoveredConfigSourceTest.class, CustomDbConfigSource.class, Pizza.class, PizzaConverter.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsServiceProvider(ConfigSource.class, CustomDbConfigSource.class)
.addAsServiceProvider(Converter.class, PizzaConverter.class)
.as(JavaArchive.class);
.as(JavaArchive.class);

WebArchive war = ShrinkWrap
.create(WebArchive.class, "customConfigSourceTest.war")
Expand All @@ -66,23 +66,17 @@ public void testAutoDiscoveredConfigureSources() {
}
@Test
public void testAutoDiscoveredConverterManuallyAdded() {

Config config = ConfigProviderResolver.instance().getBuilder().addDefaultSources().addDiscoveredSources().addDiscoveredConverters().build();
Pizza dVaule = config.getValue("tck.config.test.customDbConfig.key3", Pizza.class);
Assert.assertEquals(dVaule.getSize(), "big");
Assert.assertEquals(dVaule.getFlavor(), "cheese");
}
@Test
public void testAutoDiscoveredConverterNotAddedAutomatically() {

@Test(expectedExceptions = IllegalArgumentException.class)
public void testAutoDiscoveredConverterNotAddedAutomatically() {
Config config = ConfigProviderResolver.instance().getBuilder().addDefaultSources().addDiscoveredSources().build();
try {
Pizza dVaule = config.getValue("tck.config.test.customDbConfig.key3", Pizza.class);
Assert.fail("The auto discovered converter should not be added automatically.");
}
catch (Exception e) {
Assert.assertTrue( e instanceof IllegalArgumentException);
}

Pizza dVaule = config.getValue("tck.config.test.customDbConfig.key3", Pizza.class);
Assert.fail("The auto discovered converter should not be added automatically.");
}
}
Expand Up @@ -27,19 +27,15 @@ public class Pizza {
private String size;


public Pizza(String value) {
String[] parts = value.split(":");
if (parts.length ==2) {
size = parts[0];
flavor = parts[1];
}

public Pizza(String flavour, String size) {
this.flavor = flavour;
this.size = size;
}

public String getSize() {
return size;
}

public String getFlavor() {
return flavor;
}
Expand Down
Expand Up @@ -28,6 +28,13 @@ public class PizzaConverter implements Converter<Pizza> {

@Override
public Pizza convert(String value) {
return new Pizza(value);
String[] parts = value.split(":");
if (parts.length ==2) {
String size = parts[0];
String flavor = parts[1];
return new Pizza(flavor, size);
}

return null;
}
}

0 comments on commit 152029b

Please sign in to comment.