Skip to content

Commit

Permalink
Merge pull request #65 from jmesnil/63_multi_value_collection
Browse files Browse the repository at this point in the history
[#63] A multi-value config get operation
  • Loading branch information
kenfinnigan authored Dec 14, 2018
2 parents 8369341 + 970f15d commit cc0fc35
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> 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<String> 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"));
}
}

0 comments on commit cc0fc35

Please sign in to comment.