Search in sources :

Example 1 with CodecFactory

use of org.jdbi.v3.core.codec.CodecFactory in project jdbi by jdbi.

the class TestCodecFactory method testCollectionCodec.

@Test
public void testCollectionCodec() {
    CodecFactory factory = CodecFactory.forSingleCodec(SET_CODEC_TYPE, new GenericSetCodec());
    Optional<Function<Object, Argument>> result = factory.prepare(SET_CODEC_TYPE, new ConfigRegistry());
    assertTrue(result.isPresent());
    // The TypeResolvingCodecFactory in jdbi3-guava returns true here.
    result = factory.prepare(CONCRETE_TYPE_CODEC_TYPE, new ConfigRegistry());
    assertFalse(result.isPresent());
}
Also used : Function(java.util.function.Function) ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) Test(org.junit.jupiter.api.Test)

Example 2 with CodecFactory

use of org.jdbi.v3.core.codec.CodecFactory in project jdbi by jdbi.

the class TypeResolvingCodecFactoryTest method testNegativeStillWorks.

@Test
public void testNegativeStillWorks() {
    CodecFactory factory = TypeResolvingCodecFactory.forSingleCodec(SET_CODEC_TYPE, new GenericSetCodec());
    QualifiedType<Set<Integer>> integerSetType = QualifiedType.of(new GenericType<Set<Integer>>() {
    });
    Optional<Function<Object, Argument>> result = factory.prepare(integerSetType, new ConfigRegistry());
    assertFalse(result.isPresent());
    QualifiedType<HashSet<Integer>> concreteIntegerType = QualifiedType.of(new GenericType<HashSet<Integer>>() {
    });
    result = factory.prepare(concreteIntegerType, new ConfigRegistry());
    assertFalse(result.isPresent());
    QualifiedType<String> stringType = QualifiedType.of(String.class);
    result = factory.prepare(stringType, new ConfigRegistry());
    assertFalse(result.isPresent());
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Function(java.util.function.Function) ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) CodecFactory(org.jdbi.v3.core.codec.CodecFactory) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with CodecFactory

use of org.jdbi.v3.core.codec.CodecFactory in project jdbi by jdbi.

the class TypeResolvingCodecFactoryTest method testInterfaceCodec.

@Test
public void testInterfaceCodec() {
    CodecFactory factory = TypeResolvingCodecFactory.forSingleCodec(XINTERFACE_CODEC_TYPE, new StringXInterfaceCodec());
    QualifiedType<?> xClassType = QualifiedType.of(XClass.class);
    Optional<Function<Object, Argument>> result = factory.prepare(xClassType, new ConfigRegistry());
    assertTrue(result.isPresent());
    QualifiedType<?> yClassType = QualifiedType.of(YClass.class);
    result = factory.prepare(yClassType, new ConfigRegistry());
    assertTrue(result.isPresent());
    QualifiedType<?> zClassType = QualifiedType.of(ZClass.class);
    result = factory.prepare(zClassType, new ConfigRegistry());
    assertTrue(result.isPresent());
}
Also used : Function(java.util.function.Function) ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) CodecFactory(org.jdbi.v3.core.codec.CodecFactory) Test(org.junit.jupiter.api.Test)

Example 4 with CodecFactory

use of org.jdbi.v3.core.codec.CodecFactory in project jdbi by jdbi.

the class TypeResolvingCodecFactoryTest method testCollectionCodec.

@Test
public void testCollectionCodec() {
    CodecFactory factory = TypeResolvingCodecFactory.forSingleCodec(SET_CODEC_TYPE, new GenericSetCodec());
    Optional<Function<Object, Argument>> result = factory.prepare(SET_CODEC_TYPE, new ConfigRegistry());
    assertTrue(result.isPresent());
    result = factory.prepare(CONCRETE_TYPE_CODEC_TYPE, new ConfigRegistry());
    assertTrue(result.isPresent());
}
Also used : Function(java.util.function.Function) ConfigRegistry(org.jdbi.v3.core.config.ConfigRegistry) CodecFactory(org.jdbi.v3.core.codec.CodecFactory) Test(org.junit.jupiter.api.Test)

Aggregations

Function (java.util.function.Function)4 ConfigRegistry (org.jdbi.v3.core.config.ConfigRegistry)4 Test (org.junit.jupiter.api.Test)4 CodecFactory (org.jdbi.v3.core.codec.CodecFactory)3 HashSet (java.util.HashSet)1 Set (java.util.Set)1