Skip to content

feat:Adds Dasia's Lesson_15 Test for Employee and EmployeeManager #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class Employee {
private String name;
private String department;
private double salary;
Employee employee;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, didn't need this.


public Employee(int id, String name, String department, double salary) {
this.id = id;
Expand Down Expand Up @@ -45,4 +46,8 @@ public double getSalary() {
public void setSalary(double salary) {
this.salary = salary;
}

public String getDetails() {
return "id " + id + " name " + name + " department " + department + " salary " + salary;
}
}
41 changes: 41 additions & 0 deletions lesson_15/tdd/tdd_app/src/test/java/EmployeeManagerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.codedifferently.lesson15.Employee;
import com.codedifferently.lesson15.EmployeeManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class EmployeeManagerTest {

private EmployeeManager employeeManager;
Employee employee;
Employee employeeNew;

@BeforeEach
void beforeTest() {
employee = new Employee(4, "Dasia", "HR", 100000);
employeeManager = new EmployeeManager();
}

@Test
void addEmployee() {
employeeManager.addEmployee(employee);
assertThat(employeeManager.getEmployee(employee.getId())).isEqualTo(employee);
}

@Test
void removeEmployee() {
employeeManager.addEmployee(employee);
employeeManager.removeEmployee(employee.getId());
assertEquals(0, employeeManager.getEmployeeCount());
}

@Test
void testUpdateEmployee_replacesOutdatedInformation() {
employeeManager.addEmployee(employee);
employeeNew = new Employee(4, "Bri", "Makerting", 300000);
employeeManager.updateEmployee(employeeNew);
assertEquals(employeeNew, employeeManager.getEmployee(employee.getId()));
}
}
65 changes: 65 additions & 0 deletions lesson_15/tdd/tdd_app/src/test/java/EmployeeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.codedifferently.lesson15.Employee;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class EmployeeTest {

Employee employee;

@BeforeEach
void beforeTest_makesEmployeeBeforeEachTest() {
employee = new Employee(4, "Dasia", "Human Resources", 100000);
}

@Test
void testgetId() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Camel-case for method names everywhere.

assertEquals(4, employee.getId());
}

@Test
void testsetId_getsEmployeesNewId() {
employee.setId(10);
assertEquals(10, employee.getId());
}

@Test
void testgetName() {
assertEquals("Dasia", employee.getName());
}

@Test
void testsetName_getsEmployeesNewName() {
employee.setName("Destiny");
assertEquals("Destiny", employee.getName());
}

@Test
void testgetDapartment() {
assertEquals("Human Resources", employee.getDepartment());
}

@Test
void testsetDepartment_getsEmployeesNewDepartment() {
employee.setDepartment("Human Resources");
assertEquals("Human Resources", employee.getDepartment());
}

@Test
void testgetSalary() {
assertEquals(100000, employee.getSalary());
}

@Test
void testsetSalary_getsEmployeesNewSalary() {
employee.setSalary(100000);
assertEquals(100000, employee.getSalary());
}

@Test
public void testGetDetails_getEmployeesUniqueInformation() {
assertEquals(
"id 4 name Dasia department Human Resources salary 100000.0", employee.getDetails());
}
}
Loading