package com.bbn.bue.common.serialization.jackson;

import com.bbn.bue.common.evaluation.FMeasureCounts;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableMap;
import junit.framework.TestCase;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertEquals;

public class TestSerialization extends TestCase {
    private ObjectMapper mapper;

    @Override
    protected void setUp() {
        mapper = new ObjectMapper();
        mapper.findAndRegisterModules();
        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    }

    @Test
    public void testFMeasureCounts() throws IOException {
        final RootObject foo = new RootObject();
        foo.o = ImmutableMap.of("Hello",
                FMeasureCounts.from(1, 2, 3));
        final File tmp = File.createTempFile("foo", "bar");
        tmp.deleteOnExit();
        mapper.writeValue(tmp, foo);
        final Map<String, FMeasureCounts> bar = (Map<String,FMeasureCounts>)mapper.readValue(tmp,
                RootObject.class).o;
        assertEquals(foo.o, bar);
    }

    public static class RootObject {

        public RootObject() {
            o = null;
        }

        @JsonCreator
        public RootObject(@JsonProperty("obj") Object o) {
            this.o = o;
        }

        @JsonProperty("obj")
        public Object obj() {
            return o;
        }

        public Object o;
    }
}
@@ -624,230 +624,79 @@
 ate 
-ObjectMapper mapper;%0A%0A    @Override%0A    protected void setUp() %7B%0A        mapper = new ObjectMapper();%0A        mapper.findAndRegisterModules();%0A        mapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);%0A    %7D
+final JacksonSerializer serializer = JacksonSerializer.forNormalJSON();
 %0A%0A  
@@ -779,56 +779,39 @@
 nal 
-RootObject foo = new RootObject();%0A       
+Map%3CString, FMeasureCounts%3E
  foo
-.o
  = I
@@ -973,557 +973,102 @@
 ();%0A
-        mapper.writeValue(tmp, foo);%0A        final Map%3CString, FMeasureCounts%3E bar = (Map%3CString,FMeasureCounts%3E)mapper.readValue(tmp,%0A                RootObject.class).o;%0A        assertEquals(foo.o, bar);%0A    %7D%0A%0A    public static class RootObject %7B%0A%0A        public RootObject() %7B%0A            o = null;%0A        %7D%0A%0A        @JsonCreator%0A        public RootObject(@JsonProperty(%22obj%22) Object o) %7B%0A            this.o = o;%0A        %7D%0A%0A        @JsonProperty(%22obj%22)%0A        public Object obj() %7B%0A            return o;%0A        %7D%0A%0A        public Object o;%0A    %7D
+%0A        assertEquals(foo, JacksonTestUtils.roundTripThroughSerializer(foo, serializer));%0A    %7D%0A
 %0A%7D

Fix Jackson serialization test for changes to Jackson serialization wrpaper