package test.api.java;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import api.java.Politician;

public class TestPolitician {

	private static String name;
	private static List<Double> values;
	private static Politician pol;

	private static String otherName;
	private static List<Double> otherValues;
	private static Politician otherPol;

	@Before
	public void setUp() {

		name = "Matthew James";
		values = new ArrayList<Double>(Arrays.asList(1.5d, 2.5d, 3.5d));
		pol = new Politician(name, values);

		otherName = "Matthew James";
		otherValues = new ArrayList<Double>(Arrays.asList(1.5d, 2.5d, 3.5d));
		otherPol = new Politician(otherName, otherValues);
	}

	@After
	public void afterEach() {

		Assert.assertTrue(pol.checkInvariant());
	}

	@Test
	public void testHashCode() {

		Assert.assertEquals(pol.hashCode(), otherPol.hashCode());
	}

	@Test
	public void testPolitician() {

		// test is done using setUp and afterEach methods
	}

	@Test
	public void testGetName() {

		String expected = "Matthew James";

		Assert.assertEquals(expected, pol.getName());
	}

	@Test
	public void testGetValues() {

		// ensures method does not expose original values

		pol.getValues().clear();

		Assert.assertFalse(pol.getValues().isEmpty());
	}

	@Test
	public void testToString() {

		String expected = "Matthew James 1.5 2.5 3.5";

		Assert.assertEquals(expected, pol.toString());
	}

	@Test
	public void testEquals() {

		Assert.assertTrue(pol.equals(otherPol));
	}

	@Test
	public void testEqualsFalseName() {

		otherName = "Other Politician";
		otherPol = new Politician(otherName, otherValues);

		Assert.assertFalse(pol.equals(otherPol));
	}

	@Test
	public void testEqualsFalseValues() {

		otherValues = new ArrayList<Double>(Arrays.asList(10.5d, 1.5d, 5.5d));
		otherPol = new Politician(otherName, otherValues);

		Assert.assertFalse(pol.equals(otherPol));
	}
}
