package seedu.ezdo.model;

import static org.junit.Assert.assertSame;
import static seedu.ezdo.testutil.TestUtil.assertThrows;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import javafx.collections.FXCollections;
import seedu.ezdo.commons.core.UnmodifiableObservableList;

public class UnmodifiableObservableListTest {

    @Rule
    public ExpectedException thrown = ExpectedException.none();

    private List<Integer> backing;
    private UnmodifiableObservableList<Integer> list;

    @Before
    public void setUp() {
        backing = new ArrayList<>();
        backing.add(10);
        list = new UnmodifiableObservableList<>(FXCollections.observableList(backing));
    }

    @Test
    public void transformationListGenerators_correctBackingList() {
        assertSame(list.sorted().getSource(), list);
        assertSame(list.filtered(i -> true).getSource(), list);
    }

    @Test
    public void mutatingMethods_disabled() {

        final Class<UnsupportedOperationException> ex = UnsupportedOperationException.class;

        assertThrows(ex, () -> list.add(0, 2));
        assertThrows(ex, () -> list.add(3));

        assertThrows(ex, () -> list.addAll(2, 1));
        assertThrows(ex, () -> list.addAll(backing));
        assertThrows(ex, () -> list.addAll(0, backing));

        assertThrows(ex, () -> list.set(0, 2));

        assertThrows(ex, () -> list.setAll(new ArrayList<Number>()));
        assertThrows(ex, () -> list.setAll(1, 2));

        assertThrows(ex, () -> list.remove(0, 1));
        assertThrows(ex, () -> list.remove(null));
        assertThrows(ex, () -> list.remove(0));

        assertThrows(ex, () -> list.removeAll(backing));
        assertThrows(ex, () -> list.removeAll(1, 2));

        assertThrows(ex, () -> list.retainAll(backing));
        assertThrows(ex, () -> list.retainAll(1, 2));

        assertThrows(ex, () -> list.replaceAll(i -> 1));

        assertThrows(ex, () -> list.sort(Comparator.naturalOrder()));

        assertThrows(ex, () -> list.clear());

        final Iterator<Integer> iter = list.iterator();
        iter.next();
        assertThrows(ex, iter::remove);

        final ListIterator<Integer> liter = list.listIterator();
        liter.next();
        assertThrows(ex, liter::remove);
        assertThrows(ex, () -> liter.add(5));
        assertThrows(ex, () -> liter.set(3));
        assertThrows(ex, () -> list.removeIf(i -> true));
    }
}

@@ -57,19 +57,107 @@
 t.assert
-Sam
+Equals;%0Aimport static org.junit.Assert.assertSame;%0Aimport static org.junit.Assert.assertTru
 e;%0Aimpor
@@ -233,24 +233,53 @@
 .ArrayList;%0A
+import java.util.Collection;%0A
 import java.
@@ -375,16 +375,74 @@
 terator;
+%0Aimport java.util.PriorityQueue;%0Aimport java.util.TreeSet;
 %0A%0Aimport
@@ -1781,24 +1781,204 @@
 umber%3E()));%0A
+        assertThrows(ex, () -%3E list.setAll(new PriorityQueue%3CNumber%3E()));%0A        Collection treeSet = new TreeSet%3CNumber%3E();%0A        assertThrows(ex, () -%3E list.setAll(treeSet));%0A
         asse
@@ -2902,24 +2902,24 @@
 er.set(3));%0A
-
         asse
@@ -2960,20 +2960,1128 @@
  -%3E true));%0A
+        if (liter.hasPrevious()) %7B%0A            Integer a = liter.previous();%0A            assertTrue(a == 10);%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void contains_true() %7B%0A        assertTrue(list.contains(10));%0A        assertTrue(list.containsAll(new ArrayList%3CInteger%3E(10)));%0A    %7D%0A%0A    @Test%0A    public void subList_equals() %7B%0A        assertTrue(list.subList(0, 1).containsAll(new ArrayList%3CInteger%3E(10)));%0A    %7D%0A%0A    @Test%0A    public void indexOf_correct() %7B%0A        assertTrue(0 == list.indexOf(10));%0A    %7D%0A%0A    @Test%0A    public void hashCode_equals() %7B%0A        List%3CInteger%3E backing;%0A        UnmodifiableObservableList%3CInteger%3E list;%0A        backing = new ArrayList%3C%3E();%0A        backing.add(10);%0A        list = new UnmodifiableObservableList%3C%3E(FXCollections.observableList(backing));%0A        assertEquals(list.hashCode(), this.list.hashCode());%0A    %7D%0A%0A    @Test%0A    public void toArray_correct() %7B%0A        Integer%5B%5D arr = backing.toArray(new Integer%5B1%5D);%0A        Integer%5B%5D arr2 = new Integer%5B%5D%7B10%7D;%0A        for (int i = 0; i %3C arr.length; i++) %7B%0A            assertTrue(arr%5Bi%5D.equals(arr2%5Bi%5D));%0A        %7D%0A
     %7D%0A%7D%0A

Add tests