Search in sources :

Example 1 with FieldKey

use of org.simpleflatmapper.map.FieldKey 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);
}
Also used : FieldMapperColumnDefinition(org.simpleflatmapper.map.property.FieldMapperColumnDefinition) RethrowMapperBuilderErrorHandler(org.simpleflatmapper.map.error.RethrowMapperBuilderErrorHandler) IgnoreMapperBuilderErrorHandler(org.simpleflatmapper.map.IgnoreMapperBuilderErrorHandler) MapperBuilderErrorHandler(org.simpleflatmapper.map.MapperBuilderErrorHandler) IgnoreMapperBuilderErrorHandler(org.simpleflatmapper.map.IgnoreMapperBuilderErrorHandler) MappingException(org.simpleflatmapper.map.MappingException) Type(java.lang.reflect.Type) RethrowConsumerErrorHandler(org.simpleflatmapper.map.error.RethrowConsumerErrorHandler) ConsumerErrorHandler(org.simpleflatmapper.map.ConsumerErrorHandler) AbstractMapperFactory(org.simpleflatmapper.map.mapper.AbstractMapperFactory) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) FieldMapperErrorHandler(org.simpleflatmapper.map.FieldMapperErrorHandler) FieldKey(org.simpleflatmapper.map.FieldKey) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) Test(org.junit.Test)

Example 2 with FieldKey

use of org.simpleflatmapper.map.FieldKey in project SimpleFlatMapper by arnaudroger.

the class AbstractMapperFactoryTest method testPropertyNameMatcherFactory.

@Test
public void testPropertyNameMatcherFactory() {
    PropertyNameMatcherFactory factory = new PropertyNameMatcherFactory() {

        @Override
        public PropertyNameMatcher newInstance(FieldKey<?> key) {
            return null;
        }
    };
    assertSame(factory, new MapperFactory().propertyNameMatcherFactory(factory).mapperConfig().propertyNameMatcherFactory());
}
Also used : DefaultPropertyNameMatcherFactory(org.simpleflatmapper.map.mapper.DefaultPropertyNameMatcherFactory) PropertyNameMatcherFactory(org.simpleflatmapper.map.PropertyNameMatcherFactory) AbstractMapperFactory(org.simpleflatmapper.map.mapper.AbstractMapperFactory) FieldKey(org.simpleflatmapper.map.FieldKey) SampleFieldKey(org.simpleflatmapper.test.map.SampleFieldKey) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 FieldKey (org.simpleflatmapper.map.FieldKey)2 AbstractMapperFactory (org.simpleflatmapper.map.mapper.AbstractMapperFactory)2 SampleFieldKey (org.simpleflatmapper.test.map.SampleFieldKey)2 Type (java.lang.reflect.Type)1 ConsumerErrorHandler (org.simpleflatmapper.map.ConsumerErrorHandler)1 FieldMapperErrorHandler (org.simpleflatmapper.map.FieldMapperErrorHandler)1 IgnoreMapperBuilderErrorHandler (org.simpleflatmapper.map.IgnoreMapperBuilderErrorHandler)1 MapperBuilderErrorHandler (org.simpleflatmapper.map.MapperBuilderErrorHandler)1 MappingException (org.simpleflatmapper.map.MappingException)1 PropertyNameMatcherFactory (org.simpleflatmapper.map.PropertyNameMatcherFactory)1 RethrowConsumerErrorHandler (org.simpleflatmapper.map.error.RethrowConsumerErrorHandler)1 RethrowMapperBuilderErrorHandler (org.simpleflatmapper.map.error.RethrowMapperBuilderErrorHandler)1 DefaultPropertyNameMatcherFactory (org.simpleflatmapper.map.mapper.DefaultPropertyNameMatcherFactory)1 FieldMapperColumnDefinition (org.simpleflatmapper.map.property.FieldMapperColumnDefinition)1