package edu.asu.conceptpower.validation;

import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;

import edu.asu.conceptpower.web.ConceptSearchBean;
import edu.mit.jwi.item.POS;
import junit.framework.Assert;

public class ConceptSearchValidatorTest {

    private ConceptSearchValidator conceptSearchValidator = new ConceptSearchValidator();

    private ConceptSearchBean testForWord;
    private ConceptSearchBean testForPos;
    private ConceptSearchBean testForPosWord;

    @Before
    public void init() {
        MockitoAnnotations.initMocks(this);

        testForWord = new ConceptSearchBean();
        testForWord.setWord("");

        testForPos = new ConceptSearchBean();
        testForPos.setWord("pony");

        testForPosWord = new ConceptSearchBean();
        POS pos = POS.NOUN;
        testForPosWord.setPos(pos);
        testForPosWord.setWord("pony");

    }

    @Test
    public void testWord() {
        Errors errors = new BindException(testForWord, "conceptSearchBean");
        ValidationUtils.invokeValidator(conceptSearchValidator, testForWord, errors);
        Assert.assertEquals(2, errors.getFieldErrorCount());
        Assert.assertEquals(errors.getFieldError("word").getCode(), "name.required");
        Assert.assertEquals(errors.getFieldError("pos").getCode(), "pos.required");

    }

    @Test
    public void testPos() {
        Errors errors = new BindException(testForPos, "conceptListAddForm");
        ValidationUtils.invokeValidator(conceptSearchValidator, testForPos, errors);
        Assert.assertEquals(1, errors.getFieldErrorCount());
        Assert.assertNull(errors.getFieldError("word"));
        Assert.assertEquals(errors.getFieldError("pos").getCode(), "pos.required");
    }

    @Test
    public void testSucessForWordPos() {
        Errors errors = new BindException(testForPosWord, "conceptListAddForm");
        ValidationUtils.invokeValidator(conceptSearchValidator, testForPosWord, errors);
        Assert.assertEquals(0, errors.getFieldErrorCount());
        Assert.assertNull(errors.getFieldError("word"));
        Assert.assertNull(errors.getFieldError("pos"));

    }

}

@@ -630,55 +630,8 @@
 os;%0D
-%0A    private ConceptSearchBean testForPosWord;%0D
 %0A%0D%0A 
@@ -889,168 +889,8 @@
 %0D%0A%0D%0A
-        testForPosWord = new ConceptSearchBean();%0D%0A        POS pos = POS.NOUN;%0D%0A        testForPosWord.setPos(pos);%0D%0A        testForPosWord.setWord(%22pony%22);%0D%0A%0D%0A
     
@@ -1767,420 +1767,7 @@
 %0D%0A%0D%0A
-    @Test%0D%0A    public void testSucessForWordPos() %7B%0D%0A        Errors errors = new BindException(testForPosWord, %22conceptListAddForm%22);%0D%0A        ValidationUtils.invokeValidator(conceptSearchValidator, testForPosWord, errors);%0D%0A        Assert.assertEquals(0, errors.getFieldErrorCount());%0D%0A        Assert.assertNull(errors.getFieldError(%22word%22));%0D%0A        Assert.assertNull(errors.getFieldError(%22pos%22));%0D%0A%0D%0A    %7D%0D%0A%0D%0A
 %7D%0D%0A

Build issues fix