package com.grayben.riskExtractor.headingMarker;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;

import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.function.UnaryOperator;

/**
 * Created by beng on 30/11/2015.
 */
public class TextCandidatesTest {

    @Mock
    List<TextCandidate> listOfCandidates;

    @Mock
    Collection<String> collectionOfStrings;

    TextCandidates textCandidatesSUT;

    List<String> textListReturned;

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

    @Before
    public void setUp() throws Exception {
        textCandidatesSUT = new TextCandidates(listOfCandidates);
        textListReturned = textCandidatesSUT.getTextList();
    }

    @After
    public void tearDown() throws Exception {

    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenAddObject
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.add(new String());
    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenAddObjectWithIndex
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.add(0, new String());
    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenAddAllCollection
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.addAll(collectionOfStrings);
    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenAddAllCollectionWithIndex
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.addAll(0, collectionOfStrings);
    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenClear
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.clear();
    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenRemoveAll
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.removeAll(collectionOfStrings);
    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenReplaceAll
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.replaceAll(new UnaryOperator<String>() {
            @Override
            public String apply(String s) {
                return null;
            }
        });
    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenRetainAll
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.retainAll(collectionOfStrings);
    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenSet
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.set(0, "cow");
    }

    @Test
    public void
    test_ReturnedTextListThrowsUnsupportedOperationException_WhenSort
            () throws Exception {
        thrown.expect(UnsupportedOperationException.class);
        textListReturned.sort(new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.hashCode() - o2.hashCode();
            }
        });
    }
}
@@ -176,24 +176,57 @@
 dException;%0A
+import org.junit.runner.RunWith;%0A
 import org.m
@@ -242,67 +242,84 @@
 ck;%0A
-%0A
 import 
-java.util.Collection;%0Aimport java.util.Comparato
+org.mockito.Mockito;%0Aimport org.mockito.runners.MockitoJUnitRunne
 r;%0A
+%0A
 impo
@@ -331,20 +331,17 @@
 va.util.
-List
+*
 ;%0Aimport
@@ -418,16 +418,51 @@
 15.%0A */%0A
+@RunWith(MockitoJUnitRunner.class)%0A
 public c
@@ -488,26 +488,16 @@
 Test %7B%0A%0A
-    @Mock%0A
     List
@@ -583,16 +583,112 @@
 fStrings
+Mock;%0A%0A    @Mock%0A    List%3CString%3E stringListMock;%0A%0A    @Mock%0A    TextCandidate textCandidateMock
 ;%0A%0A    T
@@ -840,58 +840,409 @@
     
-@Before%0A    public void setUp() throws Exception %7B
+private void initListOfCandidates()%7B%0A        listOfCandidates = new ArrayList%3C%3E();%0A        listOfCandidates.add(textCandidateMock);%0A        listOfCandidates.add(textCandidateMock);%0A        listOfCandidates.add(textCandidateMock);%0A    %7D%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A        initListOfCandidates();%0A        Mockito.when(textCandidateMock.getList()).thenReturn(stringListMock);
 %0A   
@@ -2185,32 +2185,36 @@
 lectionOfStrings
+Mock
 );%0A    %7D%0A%0A    @T
@@ -2464,32 +2464,36 @@
 lectionOfStrings
+Mock
 );%0A    %7D%0A%0A    @T
@@ -2959,32 +2959,36 @@
 lectionOfStrings
+Mock
 );%0A    %7D%0A%0A    @T
@@ -3620,16 +3620,20 @@
 fStrings
+Mock
 );%0A    %7D

Add test setup