package com.grayben.riskExtractor.htmlScorer;

import com.grayben.riskExtractor.htmlScorer.partScorers.Scorer;
import com.grayben.riskExtractor.htmlScorer.partScorers.tagScorers.MapScorer;
import com.grayben.riskExtractor.htmlScorer.partScorers.tagScorers.TagEmphasisScorer;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Tag;
import org.jsoup.select.NodeTraversor;
import org.jsoup.select.NodeVisitor;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
import org.mockito.Mockito;
import org.mockito.internal.matchers.Any;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static junit.framework.TestCase.fail;

/**
 * Created by beng on 28/11/2015.
 */
@RunWith(MockitoJUnitRunner.class)
public class TreeHtmlScorerTest
        extends HtmlScorerTest {

    TreeHtmlScorer treeHtmlScorerSUT;

    private <T extends Object> MapScorer<T>
    stubScorerMethods(Class<T> clazz, MapScorer<T> scorerMock, Map<T, Integer> scoreMap){
        //TODO: check that the label was defined (I didn't construct the object!)
        Mockito.doCallRealMethod().when(scorerMock.getScoreLabel());

        Mockito.doAnswer(invocationOnMock -> {
            T argument = (T)(invocationOnMock.getArguments())[0];
            return scoreMap.get(argument);
        }).when(scorerMock.score(Mockito.any(clazz)));

        return scorerMock;
    }

    private TagEmphasisScorer stubTagEmphasisScorer(Map<Tag, Integer> scoreMap){
        TagEmphasisScorer scorer = Mockito.mock(TagEmphasisScorer.class);
        scorer = stubScorerMethods(Tag.class, scorer, scoreMap);
        return scorer;
    }

    @Before
    public void setUp() throws Exception {
        Set<Scorer<Element>> elementScorers = new HashSet<>();
        Map<Tag, Integer> tagEmphasisScores = TagEmphasisScorer.defaultMap();
        TagEmphasisScorer tagEmphasisScorer
                = new Mockito().mock(TagEmphasisScorer.class);



        Mockito.doCallRealMethod().when(tagEmphasisScorer.getScoreLabel());
        NodeVisitor nv = new ScoringAndFlatteningNodeVisitor()
        NodeTraversor nt = new NodeTraversor()
        setHtmlScorerSUT(new TreeHtmlScorer());
        super.setUp();
    }

    @After
    public void tearDown() throws Exception {
        setHtmlScorerSUT(null);
    }

    @Test
    public void
    test_InitThrowsNullPointerException_WhenNodeTraversorIsNull
            () throws Exception {
        fail("Test not implemented");
    }

    @Override
    @Test
    public void
    test_ScoreHtmlReturnsExpected_WhenTextInputIsSimple
            () throws Exception {
        fail("Test not implemented");
    }

    @Override
    @Test
    public void
    test_ScoreHtmlReturnsExpected_WhenTextInputIsComplicated
            () throws Exception {
        fail("Test not implemented");
    }
}
@@ -108,86 +108,8 @@
 er;%0A
-import com.grayben.riskExtractor.htmlScorer.partScorers.tagScorers.MapScorer;%0A
 impo
@@ -456,133 +456,14 @@
 to.M
-atchers;%0Aimport org.mockito.Mockito;%0Aimport org.mockito.internal.matchers.Any;%0Aimport org.mockito.invocation.InvocationOnM
 ock
+ito
 ;%0Aim
@@ -510,44 +510,8 @@
 ner;
-%0Aimport org.mockito.stubbing.Answer;
 %0A%0Aim
@@ -811,790 +811,8 @@
 T;%0A%0A
-    private %3CT extends Object%3E MapScorer%3CT%3E%0A    stubScorerMethods(Class%3CT%3E clazz, MapScorer%3CT%3E scorerMock, Map%3CT, Integer%3E scoreMap)%7B%0A        //TODO: check that the label was defined (I didn't construct the object!)%0A        Mockito.doCallRealMethod().when(scorerMock.getScoreLabel());%0A%0A        Mockito.doAnswer(invocationOnMock -%3E %7B%0A            T argument = (T)(invocationOnMock.getArguments())%5B0%5D;%0A            return scoreMap.get(argument);%0A        %7D).when(scorerMock.score(Mockito.any(clazz)));%0A%0A        return scorerMock;%0A    %7D%0A%0A    private TagEmphasisScorer stubTagEmphasisScorer(Map%3CTag, Integer%3E scoreMap)%7B%0A        TagEmphasisScorer scorer = Mockito.mock(TagEmphasisScorer.class);%0A        scorer = stubScorerMethods(Tag.class, scorer, scoreMap);%0A        return scorer;%0A    %7D%0A%0A
     
@@ -1250,17 +1250,22 @@
 Visitor(
-)
+null);
 %0A       
@@ -1302,17 +1302,20 @@
 aversor(
-)
+nv);
 %0A       

Remove stub helpers - its too complicated. Let's just use the real collaborators.