/**
 * Multimud Helper.
 * 
 * Copyright (C) 2009 Benjamin Lerman<br>
 * Copyright (C) 2009 Jacques ???
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package net.ambre.multimud_helper.parser;

import static org.junit.Assert.assertEquals;

import java.util.Iterator;
import java.util.Set;

import javax.annotation.Resource;

import net.ambre.multimud_helper.bean.TrainedSkill;
import net.ambre.multimud_helper.config.TestBase;

import org.junit.Test;
import org.springframework.transaction.annotation.Transactional;

/**
 * Testing {@link TrainedSkill}.
 */
public class TrainedSkillParserTest extends TestBase {

    /**
     * constant values of the test.
     */
    private static final String[] TEST_VALUES = { "     control weather from   (not learned) to     (very good)",
                    "       locate object from   (not learned) to     (very good)", "              summon from          (poor) to  (intermediate)" };
    /**
     * the parse to test.
     */
    @Resource
    private TrainedSkillParser trainedSkillParser;

    /**
     * testing parsing a {@link TrainedSkill} as well as the toString() method.
     */
    @Test
    @Transactional
    public void testParseTrainedSkill() {
        for (String skillString : TEST_VALUES) {
            assertEquals("parse().toString should be an idempotent operation.", skillString, trainedSkillParser.parseTrainedSkill(skillString)
                            .toString());
        }
    }

    /**
     * testing parsing a list of {@link TrainedSkill}s.
     */
    @Test
    @Transactional
    public void testParseTrainedSkills() {
        StringBuilder skillsString = new StringBuilder();
        for (String skillString : TEST_VALUES) {
            skillsString.append(skillString);
            skillsString.append('\n');
        }
        Set<TrainedSkill> trainedSkills = trainedSkillParser.parseTrainedSkills(skillsString.toString());
        Iterator<TrainedSkill> iterator = trainedSkills.iterator();
        int i = 0;
        for (; i < TEST_VALUES.length; i++) {
            assertEquals("The values should be conserved.", TEST_VALUES[i], iterator.next().toString());
        }
    }
}
