package org.sfm.map;

import org.junit.Test;
import org.sfm.map.column.FieldMapperColumnDefinition;
import org.sfm.map.mapper.ColumnDefinition;
import org.sfm.reflect.Getter;
import org.sfm.reflect.meta.PropertyMeta;
import org.sfm.samples.SampleFieldKey;
import org.sfm.utils.Predicate;

import java.lang.reflect.Type;
import java.sql.ResultSet;

import static org.junit.Assert.*;

public class FieldMapperColumnDefinitionTest {


    @Test
    public void testCompose() throws Exception {
        GetterFactory<ResultSet, SampleFieldKey> getterFactory = new GetterFactory<ResultSet, SampleFieldKey>() {
            @Override
            public <P> Getter<ResultSet, P> newGetter(Type target, SampleFieldKey key, ColumnDefinition<?, ?> columnDefinition) {
                return null;
            }

            @Override
            public String toString() {
                return "GetterFactory";
            }

        };
        Getter<ResultSet, Integer> getter = new Getter<ResultSet, Integer>() {
            @Override
            public Integer get(ResultSet target) throws Exception {
                return 3;
            }
            @Override
            public String toString() {
                return "Getter";
            }
        };
        FieldMapper<ResultSet, Object> fieldMapper = new FieldMapper<ResultSet, Object>() {
            @Override
            public void mapTo(ResultSet source, Object target, MappingContext<? super ResultSet> mappingContext) throws Exception {
            }

            @Override
            public String toString() {
                return "FieldMapper";
            }
        };
        final Predicate<PropertyMeta<?, ?>> appliesTo = new Predicate<PropertyMeta<?, ?>>() {
            @Override
            public boolean test(PropertyMeta<?, ?> propertyMeta) {
                return false;
            }
        };
        FieldMapperColumnDefinition<SampleFieldKey> compose =
                FieldMapperColumnDefinition.<SampleFieldKey>identity().addRename("blop").addGetter(getter).addFieldMapper(fieldMapper).addGetterFactory(getterFactory).addKey(appliesTo);

        assertEquals("blop", compose.rename(new SampleFieldKey("bar", -1)).getName());
        assertEquals(fieldMapper, compose.getCustomFieldMapper());
        assertEquals(getterFactory, compose.getCustomGetterFactory());
        assertEquals(new Integer(3), compose.getCustomGetter().get(null));

        assertTrue(compose.hasCustomSource());
        assertTrue(compose.hasCustomFactory());
        assertFalse(compose.ignore());
        assertEquals(Integer.class, compose.getCustomSourceReturnType());

        assertTrue(FieldMapperColumnDefinition.<SampleFieldKey>identity().addIgnore().ignore());

        assertEquals("ColumnDefinition{Rename{'blop'}, Getter{Getter}, FieldMapper{FieldMapper}, GetterFactory{GetterFactory}, Key{}, Ignore{}}", compose.addIgnore().toString());

        assertTrue(compose.isKey());
        assertFalse(FieldMapperColumnDefinition.<SampleFieldKey>identity().isKey());
        assertSame(appliesTo, compose.keyAppliesTo());
    }
}

@@ -298,52 +298,53 @@
 ava.
-lang.reflect.Type;%0Aimport java.sql.ResultSet
+io.InputStream;%0Aimport java.lang.reflect.Type
 ;%0A%0Ai
@@ -503,33 +503,35 @@
 tterFactory%3C
-ResultSet
+InputStream
 , SampleFiel
@@ -570,25 +570,27 @@
 Factory%3C
-ResultSet
+InputStream
 , Sample
@@ -655,25 +655,27 @@
  Getter%3C
-ResultSet
+InputStream
 , P%3E new
@@ -939,33 +939,35 @@
      Getter%3C
-ResultSet
+InputStream
 , Integer%3E g
@@ -985,25 +985,27 @@
  Getter%3C
-ResultSet
+InputStream
 , Intege
@@ -1064,25 +1064,27 @@
 ger get(
-ResultSet
+InputStream
  target)
@@ -1278,33 +1278,35 @@
 FieldMapper%3C
-ResultSet
+InputStream
 , Object%3E fi
@@ -1333,25 +1333,27 @@
 dMapper%3C
-ResultSet
+InputStream
 , Object
@@ -1410,25 +1410,27 @@
 d mapTo(
-ResultSet
+InputStream
  source,
@@ -1472,17 +1472,19 @@
 per 
-ResultSet
+InputStream
 %3E ma

remove RS