/*
 * Copyright (c) 2013, Bell Canada All rights reserved.
 * Bell Canada PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.planimod.core.comparators;

import static com.planimod.core.TimeUtils.date;
import static org.junit.Assert.assertTrue;

import java.util.Comparator;

import org.junit.Test;

import com.planimod.core.Employee;
import com.planimod.core.EmployeePreference;
import com.planimod.core.Section;

public class EmployeePreferenceComparatorsTest {

	Comparator<EmployeePreference> seniority = EmployeePreferenceComparators.bySeniority();

	@Test
	public void testBySeniority_WithoutPreferences() {

		Employee emp1 = new Employee();
		emp1.setHireDate(date("1998-10-07"));
		EmployeePreference pref1 = new EmployeePreference();
		pref1.setEmployee(emp1);

		Employee emp2 = new Employee();
		emp2.setHireDate(date("1977-07-07"));
		EmployeePreference pref2 = new EmployeePreference();
		pref2.setEmployee(emp2);

		assertTrue(seniority.compare(pref1, pref2) > 0);

	}

	@Test
	public void testBySeniority_WithPreferences() {

		Section section = new Section();

		Employee emp1 = new Employee();
		emp1.setHireDate(date("1998-10-07"));
		EmployeePreference pref1 = new EmployeePreference();
		pref1.setEmployee(emp1);
		pref1.setPreferredSection(section);

		Employee emp2 = new Employee();
		emp2.setHireDate(date("1977-07-07"));
		EmployeePreference pref2 = new EmployeePreference();
		pref2.setEmployee(emp2);
		pref2.setPreferredSection(section);

		assertTrue(seniority.compare(pref1, pref2) > 0);

	}

	@Test
	public void testBySeniority_WithAndWithoutPreferences() {

		Section section = new Section();

		Employee emp1 = new Employee();
		emp1.setHireDate(date("1998-10-07"));
		EmployeePreference pref1 = new EmployeePreference();
		pref1.setEmployee(emp1);
		pref1.setPreferredSection(section);

		Employee emp2 = new Employee();
		emp2.setHireDate(date("1977-07-07"));
		EmployeePreference pref2 = new EmployeePreference();
		pref2.setEmployee(emp2);

		assertTrue(seniority.compare(pref1, pref2) < 0);

	}

	@Test
	public void testBySeniority_WithNullHiredate() {

		Section section = new Section();

		Employee emp1 = new Employee();
		emp1.setHireDate(date("1998-10-07"));
		EmployeePreference pref1 = new EmployeePreference();
		pref1.setEmployee(emp1);
		pref1.setPreferredSection(section);

		Employee emp2 = new Employee();
		emp2.setHireDate(null);
		EmployeePreference pref2 = new EmployeePreference();
		pref2.setEmployee(emp2);

		assertTrue(seniority.compare(pref1, pref2) < 0);

	}

	@Test
	public void testBySeniority_WithNull() {

		Section section = new Section();

		Employee emp1 = new Employee();
		emp1.setHireDate(date("1998-10-07"));
		EmployeePreference pref1 = new EmployeePreference();
		pref1.setEmployee(emp1);
		pref1.setPreferredSection(section);

		assertTrue(seniority.compare(pref1, null) < 0);

	}

	@Test
	public void testBySeniority_WithNullEmployee() {

		Employee emp1 = new Employee();
		emp1.setHireDate(date("1998-10-07"));
		EmployeePreference pref1 = new EmployeePreference();
		pref1.setEmployee(emp1);

		EmployeePreference pref2 = new EmployeePreference();
		pref2.setEmployee(null);

		assertTrue(seniority.compare(pref1, pref2) < 0);

	}
}
