package tests;

import static org.junit.Assert.assertEquals;

import java.time.LocalDate;
import java.util.Optional;

import org.eclipse.egit.github.core.Milestone;
import org.junit.Test;

import backend.resource.TurboLabel;
import backend.resource.TurboMilestone;
import backend.resource.serialization.SerializableLabel;
import backend.resource.serialization.SerializableMilestone;

public class SerializationTests {

    @Test
    public void testSerializableLabelNoColorColorToString() {
        TurboLabel label = new TurboLabel("dummy/dummy", "label.name");
        SerializableLabel serializedLabel = new SerializableLabel(label);

        assertEquals(serializedLabel.toString(), "Label: {name: label.name, color: ffffff}");
    }

    @Test
    public void testSerializableLabelWithColorToString() {
        TurboLabel label = new TurboLabel("dummy/dummy", "abcdef", "label.name");
        SerializableLabel serializedLabel = new SerializableLabel(label);

        assertEquals(serializedLabel.toString(), "Label: {name: label.name, color: abcdef}");
    }

    @Test
    public void testSerializableMilestoneNoDueDateToString() {
        Milestone milestone = new Milestone();
        milestone.setNumber(1);
        milestone.setTitle("test milestone");
        milestone.setState("open");

        TurboMilestone turboMilestone = new TurboMilestone("dummy/dummy", milestone);
        turboMilestone.setDueDate(Optional.<LocalDate>empty());
        turboMilestone.setDescription("test description");
        turboMilestone.setOpen(false);
        turboMilestone.setOpenIssues(0);
        turboMilestone.setClosedIssues(0);

        SerializableMilestone serializedMilestone = new SerializableMilestone(turboMilestone);

        String formatter = "Milestone: {%n"
                + "  id: 1%n"
                + "  title: test milestone%n"
                + "  dueDate: %n"
                + "  description: test description%n"
                + "  isOpen: false%n"
                + "  openIssues: 0%n"
                + "  closedIssues: 0%n"
                + "}";

        assertEquals(serializedMilestone.toString(), String.format(formatter));
    }

    @Test
    public void testSerializableMilestoneWithDueDateToString() {
        Milestone milestone = new Milestone();
        milestone.setNumber(1);
        milestone.setTitle("test milestone");
        milestone.setState("open");

        TurboMilestone turboMilestone = new TurboMilestone("dummy/dummy", milestone);
        turboMilestone.setDueDate(Optional.of(LocalDate.of(1, 1, 1)));
        turboMilestone.setDescription("test description");
        turboMilestone.setOpen(true);
        turboMilestone.setOpenIssues(0);
        turboMilestone.setClosedIssues(0);

        SerializableMilestone serializedMilestone = new SerializableMilestone(turboMilestone);

        String formatter = "Milestone: {%n"
                + "  id: 1%n"
                + "  title: test milestone%n"
                + "  dueDate: 0001-01-01%n"
                + "  description: test description%n"
                + "  isOpen: true%n"
                + "  openIssues: 0%n"
                + "  closedIssues: 0%n"
                + "}";

        assertEquals(serializedMilestone.toString(), String.format(formatter));
    }
}

@@ -254,24 +254,59 @@
 oMilestone;%0A
+import backend.resource.TurboUser;%0A
 import backe
@@ -410,16 +410,72 @@
 lestone;
+%0Aimport backend.resource.serialization.SerializableUser;
 %0A%0Apublic
@@ -1876,32 +1876,33 @@
       + %22  id: 1
+,
 %25n%22%0A            
@@ -1923,32 +1923,33 @@
 : test milestone
+,
 %25n%22%0A            
@@ -1966,16 +1966,17 @@
 ueDate: 
+,
 %25n%22%0A    
@@ -2013,32 +2013,33 @@
 test description
+,
 %25n%22%0A            
@@ -2060,16 +2060,17 @@
 n: false
+,
 %25n%22%0A    
@@ -2091,32 +2091,33 @@
 %22  openIssues: 0
+,
 %25n%22%0A            
@@ -2132,32 +2132,33 @@
  closedIssues: 0
+,
 %25n%22%0A            
@@ -2998,16 +2998,17 @@
 %22  id: 1
+,
 %25n%22%0A    
@@ -3045,16 +3045,17 @@
 ilestone
+,
 %25n%22%0A    
@@ -3090,16 +3090,17 @@
 01-01-01
+,
 %25n%22%0A    
@@ -3145,16 +3145,17 @@
 cription
+,
 %25n%22%0A    
@@ -3183,16 +3183,17 @@
 en: true
+,
 %25n%22%0A    
@@ -3214,32 +3214,33 @@
 %22  openIssues: 0
+,
 %25n%22%0A            
@@ -3263,16 +3263,17 @@
 ssues: 0
+,
 %25n%22%0A    
@@ -3377,11 +3377,383 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testSerializableUserToString() %7B%0A        TurboUser user = new TurboUser(%22dummy/dummy%22, %22alice123%22, %22Alice%22);%0A        String expectedString = %22User: %7BloginName: alice123, realName: Alice, avatarURL: %7D%22;%0A%0A        SerializableUser serializedUser = new SerializableUser(user);%0A%0A        assertEquals(expectedString, serializedUser.toString());%0A    %7D
 %0A%7D%0A

Add tests for SerializableUser's toString