package com.grayben.riskExtractor.htmlScorer;

import com.grayben.riskExtractor.htmlScorer.partScorers.Scorer;
import com.grayben.riskExtractor.htmlScorer.partScorers.elementScorers.EmphasisElementScorer;
import com.grayben.riskExtractor.htmlScorer.partScorers.elementScorers.SegmentationElementScorer;
import com.grayben.riskExtractor.htmlScorer.partScorers.tagScorers.TagAndAttributeScorer;
import com.grayben.riskExtractor.htmlScorer.partScorers.tagScorers.TagEmphasisScorer;
import com.grayben.riskExtractor.htmlScorer.partScorers.tagScorers.TagSegmentationScorer;
import org.jsoup.nodes.Element;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import java.util.HashSet;
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;

    @Before
    public void setUp() throws Exception {
        Set<Scorer<Element>> elementScorers = new HashSet<>();
        elementScorers.add(
                new EmphasisElementScorer(
                        new TagEmphasisScorer(TagEmphasisScorer.defaultMap()),
                        new TagAndAttributeScorer(TagAndAttributeScorer.defaultMap())
                )
        );
        elementScorers.add(
                new SegmentationElementScorer(
                        new TagSegmentationScorer(TagSegmentationScorer.defaultMap())
                )
        );
        ScoringAndFlatteningNodeVisitor nv = new ScoringAndFlatteningNodeVisitor(elementScorers);

        //TODO: inject the NodeTraversor into the TreeHtmlScorer constructor
        setHtmlScorerSUT(new TreeHtmlScorer(nv));
        super.setUp();
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
        this.treeHtmlScorerSUT = null;
    }

    @Test
    public void
    test_InitThrowsNullPointerException_WhenNodeVisitorIsNull
            () throws Exception {
        ScoringAndFlatteningNodeVisitor nv = null;

        thrown.expect(NullPointerException.class);

        treeHtmlScorerSUT = new TreeHtmlScorer(nv);
    }

    @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");
    }
}
@@ -594,16 +594,45 @@
 lement;%0A
+import org.jsoup.parser.Tag;%0A
 import o
@@ -797,19 +797,67 @@
 til.Hash
-Set
+Map;%0Aimport java.util.HashSet;%0Aimport java.util.Map
 ;%0Aimport
@@ -2470,32 +2470,33 @@
 Exception %7B%0A
+%0A
         
 fail(%22Test n
@@ -2487,35 +2487,615 @@
     
-fail(%22Test not implemented%22
+int positiveScore = 42;%0A%0A        Map%3CTag, Integer%3E tagSegmentationScores = new HashMap%3C%3E();%0A        tagSegmentationScores.put(Tag.valueOf(%22li%22), positiveScore);%0A%0A        Set%3CScorer%3CElement%3E%3E elementScorers = new HashSet%3C%3E();%0A        elementScorers.add(%0A                new SegmentationElementScorer(%0A                        new TagSegmentationScorer(%0A                                tagSegmentationScores%0A                        )%0A                )%0A        );%0A        ScoringAndFlatteningNodeVisitor nv = new ScoringAndFlatteningNodeVisitor(elementScorers);%0A        treeHtmlScorerSUT = new TreeHtmlScorer(nv
 );%0A 

Add simplified elementScorer to nodeVisitor