Проверяем основные положения задания: работа конструктора, изменение заработной платы, перегрузку 3 операций.
public class EmployeeTest {
@Test
public void TestConstructor()
{
Employee testEmployee = createTestEmployee();
String name = "Иван Иванович Иванов";
Date hireDate = new Date(2010, 03, 20);
double salary = 20000;
Assert.assertEquals(testEmployee.getName(), name);
Assert.assertEquals(testEmployee.getHireDate().toLocaleString(), hireDate.toLocaleString());
Assert.assertEquals(testEmployee.getSalary(), salary);
}
@Test
public void TestRaiseSalary()
{
double salary = 20000;
Employee testEmployee = new Employee("", null, salary);
double percent = 10;
testEmployee.raiseSalary(10);
Assert.assertEquals(testEmployee.getSalary(), salary * (1 + percent/100));
}
@Test
public void TestToString()
{
Employee testEmployee = createTestEmployee();
Assert.assertEquals(testEmployee.toString(), testEmployee.getName());
}
@Test
public void TestEquals()
{
Employee testEmployee1 = createTestEmployee();
Employee testEmployee2 = createTestEmployee();
Assert.assertTrue(testEmployee1.equals(testEmployee2));
}
@Test
public void TestHashCode()
{
Employee testEmployee = createTestEmployee();
Assert.assertEquals(testEmployee.hashCode(), (testEmployee.getName() + testEmployee.getHireDate().toString()).hashCode());
}
private Employee createTestEmployee() {
String name = "Иван Иванович Иванов";
Date hireDate = new Date(2010, 03, 20);
double salary = 20000;
return new Employee(name, hireDate, salary);
}
}
* This source code was highlighted with Source Code Highlighter.
Комментариев нет:
Отправить комментарий