package tests;

import backend.resource.TurboIssue;
import org.eclipse.egit.github.core.Issue;
import org.eclipse.egit.github.core.Label;
import org.eclipse.egit.github.core.User;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Date;

import static org.junit.Assert.assertEquals;

public class TurboIssueTest {

    @Test
    public void turboIssueTest() {
        Issue issue = new Issue();
        issue.setNumber(1);
        issue.setUser(new User().setLogin("test_user"));
        issue.setCreatedAt(new Date());
        issue.setUpdatedAt(new Date());
        issue.setState("open");
        ArrayList<Label> labels = new ArrayList<>();
        labels.add(new Label().setName("test label"));
        issue.setLabels(labels);
        TurboIssue turboIssue = new TurboIssue("dummy/dummy", issue);
        assertEquals(1, turboIssue.getId());
        assertEquals("test_user", turboIssue.getCreator());
        assertEquals(true, turboIssue.isOpen());
        assertEquals("test label", turboIssue.getLabels().get(0));
    }

}

@@ -197,16 +197,48 @@
 .Test;%0A%0A
+import java.time.LocalDateTime;%0A
 import j
@@ -279,16 +279,43 @@
 il.Date;
+%0Aimport java.util.Optional;
 %0A%0Aimport
@@ -357,38 +357,179 @@
 ls;%0A
-%0Apublic class TurboIssueTest %7B
+import static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;%0A%0Apublic class TurboIssueTest %7B%0A    private static String REPO = %22testrepo/testrepo%22;
 %0A%0A  
@@ -1242,10 +1242,1149 @@
 %0A    %7D%0A%0A
+    /**%0A     * Tests TurboIssue's isCurrentRead method%0A     */%0A    @Test%0A    public void testReadState() %7B%0A        TurboIssue issue = new TurboIssue(REPO, 1, %22%22, %22%22,%0A                LocalDateTime.of(2011, 1, 1, 1, 1, 1), false);%0A%0A        // An issue is not read if it doesn't record any markedReadAt time%0A        assertFalse(issue.isCurrentlyRead());%0A%0A        // An issue is read if it has no updatedAt time%0A        // and its markedAsRead time is after its createdAt time%0A        issue.setMarkedReadAt(Optional.of(LocalDateTime.of(2015, 1, 6, 12, 15)));%0A        issue.setUpdatedAt(null);%0A        assertTrue(issue.isCurrentlyRead());%0A%0A        // An issue is not read if its markedAsRead time is before its updatedAt time%0A        issue.setUpdatedAt(LocalDateTime.of(2015, 2, 17, 2, 10));%0A        issue.setMarkedReadAt(Optional.of(LocalDateTime.of(2015, 1, 6, 12, 15)));%0A        assertFalse(issue.isCurrentlyRead());%0A%0A        // An issue is marked as read if its markedAsRead time is after its updated Time%0A        issue.setMarkedReadAt(Optional.of(LocalDateTime.of(2015, 3, 6, 12, 15)));%0A        assertTrue(issue.isCurrentlyRead());%0A    %7D%0A%0A
 %7D%0A

Add test for new isCurrentlyRead method