/**
 * redpen: a text inspection tool
 * Copyright (c) 2014-2015 Recruit Technologies Co., Ltd. and contributors
 * (see CONTRIBUTORS.md)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package cc.redpen.validator.sentence;

import cc.redpen.RedPen;
import cc.redpen.RedPenException;
import cc.redpen.config.Configuration;
import cc.redpen.config.ValidatorConfiguration;
import cc.redpen.model.Document;
import cc.redpen.validator.BaseValidatorTest;
import cc.redpen.validator.ValidationError;
import junit.framework.Assert;
import org.junit.Test;

import java.util.List;
import java.util.Map;

import static java.util.Collections.singletonList;

public class DoubledWordValidatorTest extends BaseValidatorTest {

    public DoubledWordValidatorTest() {
        super("DoubledWord");
    }

    @Test
    public void testDoubledWord() throws RedPenException {
        Document document = prepareSimpleDocument("the good item is a good example.");

        RedPen redPen = new RedPen(config);
        Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
        Assert.assertEquals(1, errors.get(document).size());
        Assert.assertEquals("Found repeated word \"good\".", errors.get(document).get(0).getMessage());
    }

    @Test
    public void testDoubledWordWithDifferentCase() throws RedPenException {
        Document document = prepareSimpleDocument("Good item is a good example.");

        RedPen redPen = new RedPen(config);
        Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
        Assert.assertEquals(1, errors.get(document).size());
        Assert.assertEquals("Found repeated word \"good\".", errors.get(document).get(0).getMessage());
    }

    @Test
    public void testDoubledSkipListWord() throws RedPenException {
        Document document = prepareSimpleDocument("That is true, as far as I know.");

        RedPen redPen = new RedPen(config);
        Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
        Assert.assertEquals(0, errors.get(document).size());
    }

    @Test
    public void testDoubledUserDefinedSkipWord() throws RedPenException {
        config = new Configuration.ConfigurationBuilder()
                .addValidatorConfig(new ValidatorConfiguration(validatorName)
                        .addAttribute("list", "redpen,tool"))
                .setLanguage("en").build();

        Document document = prepareSimpleDocument("RedPen is RedPen right?");

        RedPen redPen = new RedPen(config);
        Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
        Assert.assertEquals(0, errors.get(document).size());
    }

    @Test
    public void testDoubledUserDefinedSkipWordWithoutNormalization() throws RedPenException {
        config = new Configuration.ConfigurationBuilder()
                .addValidatorConfig(new ValidatorConfiguration(validatorName)
                        .addAttribute("list", "RedPen,Tool"))
                .setLanguage("en").build();

        Document document = prepareSimpleDocument("redPen is redPen right?");

        RedPen redPen = new RedPen(config);
        Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
        Assert.assertEquals(0, errors.get(document).size());
    }

    @Test
    public void testDoubledWordInJapaneseSentence() throws RedPenException {
        config = new Configuration.ConfigurationBuilder()
                .addValidatorConfig(new ValidatorConfiguration(validatorName))
                .setLanguage("ja").build();

        Document document = prepareSimpleDocument("それは真実であり，それが正しい");

        RedPen redPen = new RedPen(config);
        Map<Document, List<ValidationError>> errors = redPen.validate(singletonList(document));
        Assert.assertEquals(1, errors.get(document).size());
    }
}

@@ -1001,39 +1001,8 @@
 or;%0A
-import junit.framework.Assert;%0A
 impo
@@ -1020,16 +1020,16 @@
 t.Test;%0A
+
 %0Aimport 
@@ -1117,16 +1117,67 @@
 tonList;
+%0Aimport static junit.framework.Assert.assertEquals;
 %0A%0Apublic
@@ -1611,39 +1611,32 @@
 ment));%0A        
-Assert.
 assertEquals(1, 
@@ -1665,39 +1665,32 @@
 ize());%0A        
-Assert.
 assertEquals(%22Fo
@@ -2079,39 +2079,32 @@
 ment));%0A        
-Assert.
 assertEquals(1, 
@@ -2133,39 +2133,32 @@
 ize());%0A        
-Assert.
 assertEquals(%22Fo
@@ -2541,39 +2541,32 @@
 ment));%0A        
-Assert.
 assertEquals(0, 
@@ -3148,39 +3148,32 @@
 ment));%0A        
-Assert.
 assertEquals(0, 
@@ -3775,39 +3775,32 @@
 ment));%0A        
-Assert.
 assertEquals(0, 
@@ -4316,24 +4316,24 @@
 ment));%0A
+
         
 Assert.a
@@ -4324,23 +4324,16 @@
         
-Assert.
 assertEq

use static import for assertEquals()