Skip to content

Feat: Adds Shawn Dunsmore Jr Lesson 15 Implementing Tests. #505

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

public String getDetails() {
return "ID: " + id + ", Name: " + name + ", Department: " + department + ", Salary: " + salary;
}
}
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,74 @@ public void testGetGreeting() {
// Act
Lesson15.main(null);
}

@Test
public void testEmployeeId_Exists() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The Employee related tests should be in a file named EmployeeTest.java to match the class they are testing. Similarly, EmployeeManager tests belong in an EmployeeManagerTest.java file.

Employee employee = new Employee(0, null, null, 0);
assertEquals(0, employee.getId());
}

@Test
public void testEmployeeName_Exists() {
Employee employee = new Employee(0, "dave", null, 0);
assertEquals("dave", employee.getName());
}

@Test
public void testEmployeeDepartment_Exists() {
Employee employee = new Employee(0, "dave", "IT", 0);
assertEquals("IT", employee.getDepartment());
}

@Test
public void testEmployeeSalary_Exists() {
Employee employee = new Employee(0, "dave", "IT", 10000);
assertEquals(10000, employee.getSalary());
}

@Test
public void testGetEmployee() {
Employee employee = new Employee(10, null, null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);
assertEquals(employee, manager.getEmployee(10));
}

@Test
public void testGetEmployeeCount() {
Employee employee = new Employee(10, null, null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);
assertEquals(1, manager.getEmployeeCount());
}

@Test
public void testGetEmployeeUpate() {
Employee employee2 = new Employee(10, "BillyBobJenkins", null, 0);
Employee employee = new Employee(10, "Dave", null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);
manager.updateEmployee(employee2);

assertEquals(employee2, manager.getEmployee(10));
}

@Test
public void testGetEmployeeRemove() {
Employee employee2 = new Employee(10, "BillyBobJenkins", null, 0);
Employee employee = new Employee(11, "Dave", null, 0);
EmployeeManager manager = new EmployeeManager();
manager.addEmployee(employee);
manager.addEmployee(employee2);
manager.removeEmployee(10);

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

@Test
public void testGetDetails() {
Employee employee2 = new Employee(10, "BillyBobJenkins", "IT", 10);
assertEquals(
"ID: 10, Name: BillyBobJenkins, Department: IT, Salary: 10.0", employee2.getDetails());
}
}
Loading