package com.alexrnl.subtitlecorrector.correctionstrategy;

import static com.alexrnl.subtitlecorrector.common.TranslationKeys.KEYS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.Locale;

import org.junit.Before;
import org.junit.Test;

import com.alexrnl.subtitlecorrector.common.Subtitle;

/**
 * Test suite for the {@link FixPunctuation} class.
 * @author Alex
 */
public class FixPunctuationTest {
	/** The punctuation fixer strategy */
	private FixPunctuation		fixPunctuation;
	/** Reference to the locale parameter of the strategy */
	private Parameter<Locale>	locale;
	
	/**
	 * Set up test attributes.
	 * @throws URISyntaxException
	 *         if there is an issue when parsing the path.
	 * @throws IOException
	 *         if there is an issue when loading the rules.
	 */
	@Before
	public void setUp () throws IOException, URISyntaxException {
		fixPunctuation = new FixPunctuation(Paths.get(FixPunctuation.class.getResource("/punctuation").toURI()));
		locale = (Parameter<Locale>) fixPunctuation.getParameterByName(KEYS.strategy().fixPunctuation().locale());
		assertNotNull(locale);
	}
	
	/**
	 * Test method for {@link FixPunctuation#getParameters()}.
	 */
	@Test
	public void testGetParameters () {
		assertEquals(1, fixPunctuation.getParameters().size());
	}
	
	/**
	 * Test method for {@link FixPunctuation#getParameterByName(String)}.
	 */
	@Test
	public void testGetParameterByName () {
		final Iterator<Parameter<?>> parametersIterator = fixPunctuation.getParameters().iterator();
		assertEquals(parametersIterator.next(), fixPunctuation.getParameterByName(KEYS.strategy().fixPunctuation().locale()));
		assertNull(fixPunctuation.getParameterByName("ldr"));
	}
	
	/**
	 * Test method for {@link FixPunctuation#toString()}
	 */
	@Test
	public void testToString () {
		assertEquals("subtitlecorrector.strategy.fixpunctuation", fixPunctuation.toString());
	}
	
	/**
	 * Test method for {@link FixPunctuation#getDescription()}
	 */
	@Test
	public void testGetDescription () {
		assertEquals("subtitlecorrector.strategy.fixpunctuation.description", fixPunctuation.getDescription());
	}
	
	/**
	 * Test method for {@link FixPunctuation#correct(Subtitle)}.
	 */
	@Test
	public void testCorrectFrenchRules1 () {
		final Subtitle subtitleToCorrect = new Subtitle(0, 2000, "Bonjour,comment allez vous?");
		locale.setValue(Locale.FRENCH);
		fixPunctuation.correct(subtitleToCorrect);
		assertEquals("Bonjour, comment allez vous ?", subtitleToCorrect.getContent());
	}
	
	/**
	 * Test method for {@link FixPunctuation#correct(Subtitle)}.
	 */
	@Test
	public void testCorrectFrenchRules2 () {
		final Subtitle subtitleToCorrect = new Subtitle(0, 2000, "Bonjour;comment allez vous!");
		locale.setValue(Locale.FRENCH);
		fixPunctuation.correct(subtitleToCorrect);
		assertEquals("Bonjour ; comment allez vous !", subtitleToCorrect.getContent());
	}
	
	/**
	 * Test method for {@link FixPunctuation#correct(Subtitle)}.
	 */
	@Test
	public void testCorrectEnglishRules1 () {
		final Subtitle subtitleToCorrect = new Subtitle(0, 2000, "Bonjour,comment allez vous?Hey:you");
		locale.setValue(Locale.ENGLISH);
		fixPunctuation.correct(subtitleToCorrect);
		assertEquals("Bonjour, comment allez vous? Hey: you", subtitleToCorrect.getContent());
	}
	
	/**
	 * Test method for {@link FixPunctuation#correct(Subtitle)}.
	 */
	@Test
	public void testCorrectEnglishRules2 () {
		final Subtitle subtitleToCorrect = new Subtitle(0, 2000, "Bonjour;comment allez vous!");
		locale.setValue(Locale.ENGLISH);
		fixPunctuation.correct(subtitleToCorrect);
		assertEquals("Bonjour; comment allez vous!", subtitleToCorrect.getContent());
	}
	
	/**
	 * Test method for {@link FixPunctuation#correct(Subtitle)}.
	 */
	@Test
	public void testCorrectNewLine () {
		final Subtitle subtitleToCorrect = new Subtitle(0, 2000, "Bonjour;\ncomment allez vous! Bien");
		locale.setValue(Locale.ENGLISH);
		fixPunctuation.correct(subtitleToCorrect);
		assertEquals("Bonjour;\ncomment allez vous! Bien", subtitleToCorrect.getContent());
	}
	
}

@@ -316,32 +316,87 @@
 yntaxException;%0A
+import java.nio.file.Files;%0Aimport java.nio.file.Path;%0A
 import java.nio.
@@ -1371,32 +1371,473 @@
 ale);%0A%09%7D%0A%09%0A%09/**%0A
+%09 * Check that the strategy cannot be created with a file as a parameter.%0A%09 * @throws IOException%0A%09 *         if there is an issue when loading the rules.%0A%09 */%0A%09@SuppressWarnings(%22unused%22)%0A%09@Test(expected = IllegalArgumentException.class)%0A%09public void createWithFile () throws IOException %7B%0A%09%09final Path tempFile = Files.createTempFile(%22punctuationRule%22, %22txt%22);%0A%09%09tempFile.toFile().deleteOnExit();%0A%09%09new FixPunctuation(tempFile);%0A%09%7D%0A%09%0A%09/**%0A
 %09 * Test method 

Add a test case for the fix punctuation strategy