package seedu.address.storage;

import static org.junit.Assert.assertEquals;
import static seedu.address.commons.time.TypicalLocalDateTimes.UNIX_EPOCH;

import org.junit.BeforeClass;
import org.junit.Test;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.task.DeadlineTask;
import seedu.address.model.task.Name;

public class JsonDeadlineTaskMixinTest {

    private static ObjectMapper objectMapper;

    public static final DeadlineTask TEST_DEADLINE;
    public static final String TEST_DEADLINE_JSON = "{\"name\":\"deadline name\",\"due\":[1970,1,2,0,0]}";

    static {
        try {
            TEST_DEADLINE = new DeadlineTask(new Name("deadline name"), UNIX_EPOCH.plusDays(1));
        } catch (IllegalValueException e) {
            throw new RuntimeException(e);
        }
    }

    @BeforeClass
    public static void setupObjectMapper() {
        final SimpleModule module = new SimpleModule();
        module.setMixInAnnotation(Name.class, JsonNameMixin.class);
        module.setMixInAnnotation(DeadlineTask.class, JsonDeadlineTaskMixin.class);
        objectMapper = new ObjectMapper();
        objectMapper.findAndRegisterModules().registerModule(module);
    }

    @Test
    public void serialize() throws Exception {
        final String expected = TEST_DEADLINE_JSON;
        final String actual = objectMapper.writeValueAsString(TEST_DEADLINE);
        assertEquals(expected, actual);
    }

    @Test
    public void deserialize() throws Exception {
        final DeadlineTask expected = TEST_DEADLINE;
        final DeadlineTask actual = objectMapper.readValue(TEST_DEADLINE_JSON, DeadlineTask.class);
        assertEquals(expected, actual);
    }

}

@@ -595,24 +595,78 @@
 EST_DEADLINE
+1;%0A    public static final DeadlineTask TEST_DEADLINE2
 ;%0A    public
@@ -695,24 +695,25 @@
 EST_DEADLINE
+1
 _JSON = %22%7B%5C%22
@@ -734,16 +734,17 @@
 ine name
+1
 %5C%22,%5C%22due
@@ -760,16 +760,276 @@
 1,2,0,0%5D
+,%22%0A                                                    + %22%5C%22finished%5C%22:false%7D%22;%0A    public static final String TEST_DEADLINE2_JSON = %22%7B%5C%22name%5C%22:%5C%22deadline name2%5C%22,%5C%22due%5C%22:%5B1970,1,2,0,0%5D,%22%0A                                                    + %22%5C%22finished%5C%22:true
 %7D%22;%0A%0A   
@@ -1077,16 +1077,17 @@
 DEADLINE
+1
  = new D
@@ -1121,16 +1121,17 @@
 ine name
+1
 %22), UNIX
@@ -1151,16 +1151,121 @@
 ys(1));%0A
+            TEST_DEADLINE2 = new DeadlineTask(new Name(%22deadline name2%22), UNIX_EPOCH.plusDays(1), true);%0A
         
@@ -1828,32 +1828,33 @@
  String expected
+1
  = TEST_DEADLINE
@@ -1849,24 +1849,79 @@
 EST_DEADLINE
+1_JSON;%0A        final String expected2 = TEST_DEADLINE2
 _JSON;%0A     
@@ -1938,24 +1938,25 @@
 tring actual
+1
  = objectMap
@@ -1991,16 +1991,97 @@
 DEADLINE
+1);%0A        final String actual2 = objectMapper.writeValueAsString(TEST_DEADLINE2
 );%0A     
@@ -2100,32 +2100,33 @@
 als(expected
+1
 , actual
 );%0A    %7D%0A%0A  
@@ -2105,32 +2105,75 @@
 xpected1, actual
+1);%0A        assertEquals(expected2, actual2
 );%0A    %7D%0A%0A    @T
@@ -2260,16 +2260,17 @@
 expected
+1
  = TEST_
@@ -2277,16 +2277,72 @@
 DEADLINE
+1;%0A        final DeadlineTask expected2 = TEST_DEADLINE2
 ;%0A      
@@ -2368,16 +2368,17 @@
 k actual
+1
  = objec
@@ -2408,16 +2408,119 @@
 DEADLINE
+1_JSON, DeadlineTask.class);%0A        final DeadlineTask actual2 = objectMapper.readValue(TEST_DEADLINE2
 _JSON, D
@@ -2568,24 +2568,25 @@
 expected
+1
 , actual
 );%0A    %7D
@@ -2577,16 +2577,59 @@
 , actual
+1);%0A        assertEquals(expected2, actual2
 );%0A    %7D

update JsonFloatingTaskMixinTest