From 970f15df2bac8bfc27bf0ca016ee90d282e73c8d Mon Sep 17 00:00:00 2001 From: Jeff Mesnil Date: Fri, 14 Dec 2018 18:33:24 +0100 Subject: [PATCH] [#63] A multi-value config get operation * add tests issue: https://github.com/smallrye/smallrye-config/issues/63 --- .../smallrye/config/MultiValueTestCase.java | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 implementation/src/test/java/io/smallrye/config/MultiValueTestCase.java diff --git a/implementation/src/test/java/io/smallrye/config/MultiValueTestCase.java b/implementation/src/test/java/io/smallrye/config/MultiValueTestCase.java new file mode 100644 index 000000000..e1a1a8c10 --- /dev/null +++ b/implementation/src/test/java/io/smallrye/config/MultiValueTestCase.java @@ -0,0 +1,60 @@ +package io.smallrye.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Properties; +import java.util.Set; +import java.util.TreeSet; + +import org.eclipse.microprofile.config.Config; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class MultiValueTestCase { + + SmallRyeConfig config; + + @Before + public void setUp() { + Properties properties = new Properties(); + properties.put("my.pets", "snake,dog,cat,cat"); + + config = (SmallRyeConfig)SmallRyeConfigProviderResolver.instance().getBuilder() + .withSources(new PropertiesConfigSource(properties, "my properties")) + .build(); + } + + @Test + public void testGetValuesAsList() { + List pets = config.getValues("my.pets", String.class, ArrayList::new); + assertNotNull(pets); + assertEquals(4, pets.size()); + assertEquals(pets, Arrays.asList("snake", "dog", "cat", "cat")); + } + + @Test + public void testGetValuesAsSet() { + Set pets = config.getValues("my.pets", String.class, HashSet::new); + assertNotNull(pets); + assertEquals(3, pets.size()); + assertTrue(pets.contains("snake")); + assertTrue(pets.contains("dog")); + assertTrue(pets.contains("cat")); + } + + @Test + public void testGetValuesAsSortedSet() { + Set pets = config.getValues("my.pets", String.class, s -> new TreeSet<>(String.CASE_INSENSITIVE_ORDER)); + assertNotNull(pets); + assertEquals(3, pets.size()); + assertEquals(new ArrayList(pets), Arrays.asList("cat", "dog", "snake")); + } +}