package ma.glasnost.orika.test.optional;

import com.google.common.base.Optional;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.converter.builtin.GuavaOptionalConverter;
import ma.glasnost.orika.metadata.TypeFactory;
import ma.glasnost.orika.test.MappingUtil;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class GuavaOptionalTestCase {

    @Test
    public void testMappingIgnoresEmptyOptionalInDestination() {
        final String expected = "initial";

        final Source source = new Source();
        source.setS(Optional.of(expected));

        final MapperFactory mapperFactory = MappingUtil.getMapperFactory(true);
        mapperFactory.getConverterFactory()
                .registerConverter(new GuavaOptionalConverter<String, String>(TypeFactory.valueOf(String.class), TypeFactory.valueOf(String.class)));

        final Destination actual = mapperFactory.getMapperFacade().map(source, Destination.class);

        assertEquals(expected, actual.getS().get());
    }

    public static class Source {
        private Optional<String> s = Optional.absent();

        public Optional<String> getS() {
            return s;
        }

        public void setS(final Optional<String> s) {
            this.s = s;
        }
    }

    public static class Destination {
        private Optional<String> s = Optional.absent();

        public Optional<String> getS() {
            return s;
        }

        public void setS(final Optional<String> s) {
            this.s = s;
        }
    }

}

@@ -75,16 +75,55 @@
 tional;%0A
+import ma.glasnost.orika.MapperFacade;%0A
 import m
@@ -146,32 +146,32 @@
 .MapperFactory;%0A
-
 import ma.glasno
@@ -379,16 +379,60 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertFalse;
 %0A%0Apublic
@@ -667,24 +667,419 @@
 xpected));%0A%0A
+        final Destination actual = getMapperFacade().map(source, Destination.class);%0A%0A        assertEquals(expected, actual.getS().get());%0A    %7D%0A%0A    @Test%0A    public void testMappingMapEmptyToEmpty() %7B%0A        final Destination actual = getMapperFacade().map(new Source(), Destination.class);%0A%0A        assertFalse(actual.getS().isPresent());%0A    %7D%0A%0A    private MapperFacade getMapperFacade() %7B%0A
         fina
@@ -1336,33 +1336,32 @@
 g.class)));%0A
-%0A
         
 final Destin
@@ -1352,34 +1352,14 @@
     
-final Destination actual =
+return
  map
@@ -1390,93 +1390,8 @@
 de()
-.map(source, Destination.class);%0A%0A        assertEquals(expected, actual.getS().get())
 ;%0A  

Improve code coverage of optional functionality.