package seedu.taskitty.model;

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

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

import java.util.*;

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

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));
    }
}

@@ -65,16 +65,58 @@
 ctions;%0A
+import javafx.collections.ObservableList;%0A
 import s
@@ -170,16 +170,16 @@
 leList;%0A
-
 %0Aimport 
@@ -337,26 +337,17 @@
 .Assert.
-assertSame
+*
 ;%0Aimport
@@ -612,16 +612,53 @@
 r%3E list;
+%0A    private Collection%3CInteger%3E col;
 %0A%0A    @B
@@ -835,24 +835,64 @@
 (backing));%0A
+        col = new ArrayList%3CInteger%3E();%0A
     %7D%0A%0A    @
@@ -1657,33 +1657,91 @@
 .setAll(1, 2));%0A
+        %0A        assertThrows(ex, () -%3E list.setAll(col));
 %0A
-
         assertTh
@@ -2609,24 +2609,24 @@
 er.set(3));%0A
-
         asse
@@ -2677,10 +2677,856 @@
 ;%0A    %7D%0A
+    %0A    //@@author A0130853L%0A    @Test%0A    public void hasNullBackingList_ExceptionThrown() throws NullPointerException %7B%0A        thrown.expect(NullPointerException.class);%0A        List%3CInteger%3E backingList = null;%0A        UnmodifiableObservableList newlist = new UnmodifiableObservableList((ObservableList)backingList);%0A    %7D%0A    %0A    @Test%0A    public void unmodifiableObservableList_containsObject_returnsTrue() %7B%0A        assertTrue(list.contains(10));%0A    %7D%0A    %0A    @Test%0A    public void unmodifiableObservableList_containsAll_returnsTrue() %7B%0A        col.add(10);%0A        assertTrue(list.containsAll(col));%0A    %7D%0A    %0A    @Test%0A    public void indexOfObject_returnsTrue() %7B%0A        assertEquals(list.indexOf(10), 0);%0A    %7D%0A    %0A    @Test%0A    public void lastIndexOfObject_returnsTrue() %7B%0A        assertEquals(list.lastIndexOf(10), 0);%0A    %7D%0A
 %7D%0A

Update UnmodifiableObservableListTest to improve coverage