use of org.simpleflatmapper.map.MapperBuilderErrorHandler in project SimpleFlatMapper by arnaudroger.
the class CsvWriterTest method testWriterWithCustomMapperConfig.
@Test
public void testWriterWithCustomMapperConfig() throws Exception {
CsvWriter.CsvWriterDSL<DbObject> from = CsvWriter.from(DbObject.class);
from = from.mapperConfig(from.mapperConfig().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) {
}
}));
from.columns("nonexistent");
}
use of org.simpleflatmapper.map.MapperBuilderErrorHandler 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.map.MapperBuilderErrorHandler in project SimpleFlatMapper by arnaudroger.
the class PropertyMappingsBuilderTest method testSelfPropertyInvalidation.
@Test
public void testSelfPropertyInvalidation() {
final ClassMeta<DbObject> classMeta = ReflectionService.newInstance().getClassMeta(DbObject.class);
MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);
PropertyMappingsBuilder<DbObject, SampleFieldKey, FieldMapperColumnDefinition<SampleFieldKey>> builder = PropertyMappingsBuilder.of(classMeta, MapperConfig.<SampleFieldKey>fieldMapperConfig().mapperBuilderErrorHandler(errorHandler), ConstantPredicate.<PropertyMeta<?, ?>>truePredicate());
builder.addProperty(new SampleFieldKey("self", 0), FieldMapperColumnDefinition.<SampleFieldKey>identity());
verify(errorHandler, never()).customFieldError(any(FieldKey.class), any(String.class));
verify(errorHandler, never()).accessorNotFound(any(String.class));
verify(errorHandler, never()).propertyNotFound(any(Type.class), any(String.class));
builder.addProperty(new SampleFieldKey("id", 1), FieldMapperColumnDefinition.<SampleFieldKey>identity());
verify(errorHandler).propertyNotFound(DbObject.class, "self");
}
use of org.simpleflatmapper.map.MapperBuilderErrorHandler in project SimpleFlatMapper by arnaudroger.
the class JdbcMapperErrorTest method testHandleMapperErrorSetterNotFound.
@Test
public void testHandleMapperErrorSetterNotFound() throws NoSuchMethodException, SecurityException, IOException {
MapperBuilderErrorHandler errorHandler = mock(MapperBuilderErrorHandler.class);
JdbcMapperBuilder<DbObject> builder = JdbcMapperFactoryHelper.asm().mapperBuilderErrorHandler(errorHandler).newBuilder(DbObject.class);
builder.addMapping("id", 1);
builder.addMapping("notthere1", 2);
verify(errorHandler).propertyNotFound(DbObject.class, "notthere1");
builder.addMapping("notthere3");
verify(errorHandler).propertyNotFound(DbObject.class, "notthere3");
}
use of org.simpleflatmapper.map.MapperBuilderErrorHandler in project SimpleFlatMapper by arnaudroger.
the class CsvMapperBuilderTest method testMapDbObjectWrongName.
@Test
public void testMapDbObjectWrongName() throws Exception {
MapperBuilderErrorHandler mapperBuilderErrorHandler = mock(MapperBuilderErrorHandler.class);
CsvMapperBuilder<DbFinalObject> builder = csvMapperFactory.mapperBuilderErrorHandler(mapperBuilderErrorHandler).newBuilder(DbFinalObject.class);
builder.addMapping("id");
builder.addMapping("No_prop");
verify(mapperBuilderErrorHandler).propertyNotFound(DbFinalObject.class, "No_prop");
}
Aggregations