package com.alexrnl.subtitlecorrector.io;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.MockitoAnnotations.initMocks;

import java.util.Arrays;
import java.util.HashSet;

import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;

/**
 * Test suite for the {@link SubtitleFormat} class.
 * @author Alex
 */
public class SubtitleFormatTest {
	/** The SubRip format */
	private SubtitleFormat	subrip;
	/** The ASS format */
	private SubtitleFormat	ass;
	/** The mocked subtitle reader */
	@Mock
	private SubtitleReader	reader;
	/** The mocked subtitle writer */
	@Mock
	private SubtitleWriter	writer;
	
	/**
	 * Set up test attributes.
	 */
	@Before
	public void setUp () {
		initMocks(this);
		subrip = new SubtitleFormat("subrip", Arrays.asList("srt"), reader, null);
		ass = new SubtitleFormat("ass", null, writer, "ass", "ass2");
	}
	
	/**
	 * Test method for {@link SubtitleFormat#getName()}.
	 */
	@Test
	public void testGetName () {
		assertEquals("subrip", subrip.getName());
		assertEquals("ass", ass.getName());
	}
	
	/**
	 * Test method for {@link SubtitleFormat#getExtensions()}.
	 */
	@Test
	public void testGetExtensions () {
		assertEquals(new HashSet<>(Arrays.asList("srt")), subrip.getExtensions());
		assertEquals(new HashSet<>(Arrays.asList("ass", "ass2")), ass.getExtensions());
	}
	
	/**
	 * Test method for {@link SubtitleFormat#getReader()}.
	 */
	@Test
	public void testGetReader () {
		assertEquals(reader, subrip.getReader());
		assertNull(ass.getReader());
	}
	
	/**
	 * Test method for {@link SubtitleFormat#getWriter()}.
	 */
	@Test
	public void testGetWriter () {
		assertNull(subrip.getWriter());
		assertEquals(writer, ass.getWriter());
	}
	
	/**
	 * Test method for {@link SubtitleFormat#hashCode()}.
	 */
	@Test
	public void testHashCode () {
		assertNotEquals(subrip.hashCode(), ass.hashCode());
		assertEquals(subrip.hashCode(), subrip.hashCode());
		assertEquals(ass.hashCode(), ass.hashCode());
	}

	/**
	 * Test method for {@link SubtitleFormat#equals(Object)}.
	 */
	@Test
	public void testEqualsObject () {
		assertNotEquals(subrip, null);
		assertNotEquals(subrip, ass);
		assertEquals(subrip, new SubtitleFormat("subrip", null, null));
		assertNotEquals(subrip, new SubtitleFormat("Subrip", null, null));
		assertEquals(ass, new SubtitleFormat("ass", null, null));
		assertNotEquals(ass, new SubtitleFormat(".ass", null, null));
	}
	
	/**
	 * Test method for {@link SubtitleFormat#toString()}.
	 */
	@Test
	public void testToString () {
		assertEquals("subrip [srt]", subrip.toString());
		assertEquals("ass [ass, ass2]", ass.toString());
	}
}

@@ -842,28 +842,28 @@
 itleFormat(%22
-subr
+SubR
 ip%22, Arrays.
@@ -912,35 +912,48 @@
 SubtitleFormat(%22
-ass
+SubStation Alpha
 %22, null, writer,
@@ -961,20 +961,19 @@
 %22ass%22, %22
-a
 ss
-2
+a
 %22);%0A%09%7D%0A%09
@@ -1090,20 +1090,20 @@
 Equals(%22
-subr
+SubR
 ip%22, sub
@@ -1134,19 +1134,32 @@
 Equals(%22
-ass
+SubStation Alpha
 %22, ass.g
@@ -1415,20 +1415,19 @@
 %22ass%22, %22
-a
 ss
-2
+a
 %22)), ass
@@ -2302,20 +2302,20 @@
 Format(%22
-subr
+SubR
 ip%22, nul
@@ -2434,19 +2434,32 @@
 Format(%22
-ass
+SubStation Alpha
 %22, null,
@@ -2655,20 +2655,20 @@
 Equals(%22
-subr
+SubR
 ip %5Bsrt%5D
@@ -2710,22 +2710,34 @@
 ls(%22
-ass
+SubStation Alpha
  %5Bass, 
-a
 ss
-2
+a
 %5D%22, 

Fix subtitle format names in test