use of org.jdbi.v3.core.qualifier.QualifiedType in project jdbi by jdbi.
the class TestMultipleConfigurationModules method testGlobalModules.
@Test
public void testGlobalModules() {
Injector inj = GuiceTestSupport.createTestInjector(new AbstractJdbiConfigurationModule() {
@Override
public void configureJdbi() {
bindColumnMapper().to(DummyAMapper.class);
bindColumnMapper(A_TYPE).to(DummyAMapper.class);
bindCustomizer().toInstance(jdbi -> {
});
}
}, new AbstractJdbiConfigurationModule() {
@Override
public void configureJdbi() {
bindColumnMapper().to(DummyBMapper.class);
bindColumnMapper(B_TYPE).to(DummyBMapper.class);
bindCustomizer().toInstance(jdbi -> {
});
}
});
assertNotNull(inj);
Map<QualifiedType<?>, ColumnMapper<?>> qualifiedGlobalMappers = inj.getInstance(Key.get(new TypeLiteral<Map<QualifiedType<?>, ColumnMapper<?>>>() {
}, JdbiGlobal.class));
assertEquals(2, qualifiedGlobalMappers.size());
assertTrue(qualifiedGlobalMappers.containsKey(A_TYPE));
assertTrue(qualifiedGlobalMappers.containsKey(B_TYPE));
ColumnMapper<?> aMapper = qualifiedGlobalMappers.get(A_TYPE);
ColumnMapper<?> bMapper = qualifiedGlobalMappers.get(B_TYPE);
Set<ColumnMapper<?>> globalMappers = inj.getInstance(Key.get(new TypeLiteral<Set<ColumnMapper<?>>>() {
}, JdbiGlobal.class));
assertEquals(2, globalMappers.size());
assertTrue(globalMappers.contains(aMapper));
assertTrue(globalMappers.contains(bMapper));
Set<GuiceJdbiCustomizer> customizers = inj.getInstance(Key.get(new TypeLiteral<Set<GuiceJdbiCustomizer>>() {
}, JdbiGlobal.class));
assertEquals(2, customizers.size());
}
use of org.jdbi.v3.core.qualifier.QualifiedType in project jdbi by jdbi.
the class TestMultipleConfigurationModules method testLocalModules.
@Test
public void testLocalModules() {
Injector inj = GuiceTestSupport.createTestInjector(new AbstractJdbiConfigurationModule(Foo.class) {
@Override
public void configureJdbi() {
bindColumnMapper().to(DummyAMapper.class);
bindColumnMapper(A_TYPE).to(DummyAMapper.class);
bindCustomizer().toInstance(jdbi -> {
});
}
}, new AbstractJdbiConfigurationModule(Foo.class) {
@Override
public void configureJdbi() {
bindColumnMapper().to(DummyBMapper.class);
bindColumnMapper(B_TYPE).to(DummyBMapper.class);
bindCustomizer().toInstance(jdbi -> {
});
}
});
assertNotNull(inj);
Map<QualifiedType<?>, ColumnMapper<?>> qualifiedMappers = inj.getInstance(Key.get(new TypeLiteral<Map<QualifiedType<?>, ColumnMapper<?>>>() {
}, Foo.class));
assertEquals(2, qualifiedMappers.size());
assertTrue(qualifiedMappers.containsKey(A_TYPE));
assertTrue(qualifiedMappers.containsKey(B_TYPE));
ColumnMapper<?> aMapper = qualifiedMappers.get(A_TYPE);
ColumnMapper<?> bMapper = qualifiedMappers.get(B_TYPE);
Set<ColumnMapper<?>> globalMappers = inj.getInstance(Key.get(new TypeLiteral<Set<ColumnMapper<?>>>() {
}, Foo.class));
assertEquals(2, globalMappers.size());
assertTrue(globalMappers.contains(aMapper));
assertTrue(globalMappers.contains(bMapper));
Set<GuiceJdbiCustomizer> customizers = inj.getInstance(Key.get(new TypeLiteral<Set<GuiceJdbiCustomizer>>() {
}, Foo.class));
assertEquals(2, customizers.size());
}
use of org.jdbi.v3.core.qualifier.QualifiedType 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());
}
use of org.jdbi.v3.core.qualifier.QualifiedType 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());
}
Aggregations