use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testErrorHandlers.
@Test
public void testErrorHandlers() {
MapperFactory mapperFactory = new MapperFactory();
FieldMapperErrorHandler<SampleFieldKey> fieldMapperErrorHandler = new FieldMapperErrorHandler<SampleFieldKey>() {
@Override
public void errorMappingField(SampleFieldKey key, Object source, Object target, Exception error) throws MappingException {
}
};
MapperBuilderErrorHandler mapperBuilderErrorHandler = new MapperBuilderErrorHandler() {
@Override
public void accessorNotFound(String msg) {
}
@Override
public void propertyNotFound(Type target, String property) {
}
@Override
public void customFieldError(FieldKey<?> key, String message) {
}
};
ConsumerErrorHandler consumerErrorHandler = new ConsumerErrorHandler() {
@Override
public void handlerError(Throwable error, Object target) {
}
};
mapperFactory.fieldMapperErrorHandler(fieldMapperErrorHandler);
mapperFactory.mapperBuilderErrorHandler(mapperBuilderErrorHandler);
mapperFactory.consumerErrorHandler(consumerErrorHandler);
MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = mapperFactory.mapperConfig();
assertEquals(fieldMapperErrorHandler, mapperConfig.fieldMapperErrorHandler());
assertEquals(mapperBuilderErrorHandler, mapperConfig.mapperBuilderErrorHandler());
assertEquals(consumerErrorHandler, mapperConfig.consumerErrorHandler());
Assert.assertEquals(consumerErrorHandler, mapperFactory.consumerErrorHandler());
mapperFactory = new MapperFactory();
assertTrue(mapperFactory.ignorePropertyNotFound().mapperConfig().mapperBuilderErrorHandler() instanceof IgnoreMapperBuilderErrorHandler);
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class AbstractMapperFactoryTest method testAsmSettings.
@Test
public void testAsmSettings() {
ReflectionService reflectionService = new MapperFactory().useAsm(false).getReflectionService();
assertFalse(reflectionService.isAsmActivated());
MapperConfig<SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> mapperConfig = new MapperFactory().asmMapperNbFieldsLimit(33).failOnAsm(true).maxMethodSize(13).mapperConfig();
assertEquals(33, mapperConfig.asmMapperNbFieldsLimit());
assertEquals(13, mapperConfig.maxMethodSize());
assertEquals(true, mapperConfig.failOnAsm());
reflectionService = new ReflectionService(null);
assertSame(reflectionService, new MapperFactory().reflectionService(reflectionService).getReflectionService());
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class ConstantTargetFieldMapperFactoryImplTest method testGetterNotFound.
@Test
public void testGetterNotFound() {
ConstantTargetFieldMapperFactory<Appendable, SampleFieldKey> factory = ConstantTargetFieldMapperFactoryImpl.<Appendable, SampleFieldKey>newInstance(setterFactory, Appendable.class);
try {
PropertyMeta<Object, Object> pm = mock(PropertyMeta.class);
PropertyMapping<Object, Object, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> propertyMapping = new PropertyMapping<Object, Object, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>>(pm, new SampleFieldKey("hh", 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
factory.newFieldMapper(propertyMapping, null, RethrowMapperBuilderErrorHandler.INSTANCE);
fail();
} catch (MapperBuildingException e) {
}
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class FieldMapperColumnDefinitionProviderImplTest method testProvides.
@Test
public void testProvides() {
final Object prop1 = "prop1";
final Object prop2 = "prop2";
final ConstantUnaryFactory<SampleFieldKey, Object> prop1Fact = ConstantUnaryFactory.<SampleFieldKey, Object>of(prop1);
final ConstantUnaryFactory<SampleFieldKey, Object> prop2Fact = ConstantUnaryFactory.<SampleFieldKey, Object>of(prop2);
FieldMapperColumnDefinitionProviderImpl<SampleFieldKey> provider = new FieldMapperColumnDefinitionProviderImpl<SampleFieldKey>();
final Predicate<SampleFieldKey> prop1Predicate = new Predicate<SampleFieldKey>() {
@Override
public boolean test(SampleFieldKey sampleFieldKey) {
return sampleFieldKey.getIndex() == 0;
}
};
final Predicate<SampleFieldKey> prop2Predicate = new Predicate<SampleFieldKey>() {
@Override
public boolean test(SampleFieldKey sampleFieldKey) {
return sampleFieldKey.getIndex() == 1;
}
};
provider.addColumnProperty(prop1Predicate, prop1Fact);
provider.addColumnProperty(prop2Predicate, prop2Fact);
List<AbstractColumnDefinitionProvider.PredicatedColunnPropertyFactory<FieldMapperColumnDefinition<SampleFieldKey>, SampleFieldKey>> properties = provider.getProperties();
assertEquals(2, properties.size());
assertEquals(prop1Predicate, properties.get(0).getPredicate());
assertEquals(prop2Predicate, properties.get(1).getPredicate());
assertEquals(prop1Fact, properties.get(0).getColumnPropertyFactory());
assertEquals(prop2Fact, properties.get(1).getColumnPropertyFactory());
final ArrayList<String> props = new ArrayList<String>();
provider.addColumnProperty(prop1Predicate, new Object());
provider.forEach(String.class, new BiConsumer<Predicate<? super SampleFieldKey>, String>() {
@Override
public void accept(Predicate<? super SampleFieldKey> predicate, String s) {
if (s == prop1) {
assertEquals(predicate, prop1Predicate);
}
if (s == prop2) {
assertEquals(predicate, prop2Predicate);
}
props.add(s);
}
});
assertArrayEquals(new String[] { "prop1", "prop2" }, props.toArray(new String[0]));
assertArrayEquals(new String[] { "prop1" }, provider.getColumnDefinition(new SampleFieldKey("", 0)).lookForAll(String.class));
}
use of org.simpleflatmapper.test.map.SampleFieldKey in project SimpleFlatMapper by arnaudroger.
the class MappingContextFactoryBuilderTest method testKeysAndSuppliers.
@Test
public void testKeysAndSuppliers() {
builder.addSupplier(1, new ConstantSupplier<String>("hh"));
builder.addKey(new SampleFieldKey("k1", 0));
assertFalse(builder.hasNoKeys());
MappingContextFactory<Object[]> mappingContextFactory = builder.newFactory();
assertTrue(mappingContextFactory instanceof BreakDetectorMappingContextFactory);
assertEquals("hh", mappingContextFactory.newContext().context(1));
assertNull(mappingContextFactory.newContext().context(0));
}
Aggregations