Skip to content

feat: Lesson_15 code coverage 82% - Xavier Cruz #483

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
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 @@ -45,4 +45,15 @@ public double getSalary() {
public void setSalary(double salary) {
this.salary = salary;
}

public String getDetails() {
return "ID: "
+ getId()
+ ", Name: "
+ getName()
+ ", Department: "
+ getDepartment()
+ ", Salary: "
+ getSalary();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Employee tests should be in EmployeeTest.java file, and EmployeeManager tests belong in EmployeeManagerTest.java.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codedifferently.lesson15;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

Expand All @@ -16,4 +17,65 @@ public void testGetGreeting() {
// Act
Lesson15.main(null);
}

@Test
public void employeeManagerAddEmployee() {
Employee employee = new Employee(0, null, null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);

assertEquals(employee, manager.getEmployee(0));
}

@Test
public void employeeManagerRemoveEmployee() {
Employee employee = new Employee(0, null, null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);

manager.removeEmployee(0);

assertEquals(0, manager.getEmployeeCount());
}

@Test
public void employeeManagerUpdateEmployee() {
Employee employee = new Employee(0, null, null, 0);
Employee employee2 = new Employee(0, "test", "dept", 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);

manager.updateEmployee(employee2);

assertEquals(
"ID: 0, Name: test, Department: dept, Salary: 0.0", manager.getEmployee(0).getDetails());
}

@Test
public void getEmployeeDepartment() {
Employee employee = new Employee(0, null, "fryCook", 0);

assertEquals("fryCook", employee.getDepartment());
}

@Test
public void getEmployeeSalary() {
Employee employee = new Employee(0, null, "fryCook", 999_999);

assertEquals(999_999, employee.getSalary());
}

@Test
public void getEmployeeName() {
Employee employee = new Employee(0, "James Bartholomew the III", "fryCook", 999_999);
assertEquals("James Bartholomew the III", employee.getName());
}

@Test
public void getEmployeeDetails() {
Employee employee = new Employee(0, "James Bartholomew the III", "fryCook", 999_999);
assertEquals(
"ID: 0, Name: James Bartholomew the III, Department: fryCook, Salary: 999999.0",
employee.getDetails());
}
}
Loading