Search in sources :

Example 11 with Unchecked

use of org.jdbi.v3.core.internal.exceptions.Unchecked in project jdbi by jdbi.

the class TestGuavaCollectors method testMultimapCollector.

@SuppressWarnings("unchecked")
private <M extends Multimap<Long, String>> void testMultimapCollector(Class<? extends Multimap> erasedType, GenericType<M> genericType) {
    JdbiCollectors registry = h2Extension.getJdbi().getConfig(JdbiCollectors.class);
    assertThat(registry.findElementTypeFor(genericType.getType())).contains(new GenericType<Map.Entry<Long, String>>() {
    }.getType());
    Collector<Map.Entry<Long, String>, ?, M> collector = (Collector<Map.Entry<Long, String>, ?, M>) registry.findFor(genericType.getType()).orElseThrow(() -> new IllegalStateException("Missing collector for " + genericType));
    M map = Stream.of(entry(1L, "foo"), entry(2L, "bar")).collect(collector);
    assertThat(map).isInstanceOf(erasedType).containsAllEntriesOf(ImmutableMultimap.of(1L, "foo", 2L, "bar"));
}
Also used : GenericType(org.jdbi.v3.core.generic.GenericType) JdbiCollectors(org.jdbi.v3.core.collector.JdbiCollectors) Collector(java.util.stream.Collector) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

Map (java.util.Map)5 Optional (java.util.Optional)5 Type (java.lang.reflect.Type)4 GenericType (org.jdbi.v3.core.generic.GenericType)4 Comparator (java.util.Comparator)3 Collector (java.util.stream.Collector)3 JdbiCollectors (org.jdbi.v3.core.collector.JdbiCollectors)3 ColumnMapper (org.jdbi.v3.core.mapper.ColumnMapper)3 BiMap (com.google.common.collect.BiMap)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ResultSet (java.sql.ResultSet)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 PMessage (net.morimekta.providence.PMessage)2 ConfigRegistry (org.jdbi.v3.core.config.ConfigRegistry)2 GenericTypes (org.jdbi.v3.core.generic.GenericTypes)2 Unchecked (org.jdbi.v3.core.internal.exceptions.Unchecked)2