Skip to content

feat: EmployeeManager/Java test files.AngelicaC #493

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 3 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 + " " + name + " " + department + " " + salary + ".";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.codedifferently.lesson15;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class EmployeeManagertest {
private EmployeeManager employeeManager;
private Map<Integer, Employee> employees;
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't make sense to me. How does this help you test the EmployeeManager functionality?

Employee newEmployee;
Employee tomCat;

@BeforeEach
void set_up() {
employees = new HashMap<Integer, Employee>();
newEmployee = new Employee(5, "Mike", "Human Resources", 900000.80);
employeeManager = new EmployeeManager();
}

@Test
void addEmployee() {

employees.put(newEmployee.getId(), newEmployee);
employeeManager.addEmployee(newEmployee);
assertEquals(employees.get(5), employeeManager.getEmployee(5));
}

@Test
void updateEmployee() {

tomCat = new Employee(5, "mike", "Human Resources", 900000.80);
employees.put(newEmployee.getId(), newEmployee);
employeeManager.addEmployee(newEmployee);

employees.put(tomCat.getId(), tomCat);
employeeManager.updateEmployee(tomCat);
assertEquals(employees.get(tomCat.getId()), employeeManager.getEmployee(newEmployee.getId()));
}

@Test
void RemoveEmployee() {
employeeManager.addEmployee(newEmployee);
employeeManager.removeEmployee(newEmployee.getId());
assertEquals(0, employeeManager.getEmployeeCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.codedifferently.lesson15;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class EmployeeTest {
// private class Employee employee;
Employee testEmployee;

@BeforeEach
void setUp() {
testEmployee = new Employee(3, "angie", "Software Engineer", 100000.99);
}

@Test
void getId_successful() {

Employee employee = new Employee(3, null, "", 0);
int actualId = employee.getId();
assertEquals(3, actualId);
}

@Test
void setName() {
testEmployee.setName("angie");
assertEquals("angie", testEmployee.getName());
}

@Test
void getName_successful() {
Employee testemployee = new Employee(0, "angie", "", 0);

String actualName = testemployee.getName();
assertEquals("angie", actualName);
}

@Test
void getDepartment_successful() {
Employee employee = new Employee(0, null, "test", 0);

String actualDepartment = employee.getDepartment();

assertEquals("test", actualDepartment);
}

@Test
void getSalary_successful() {
Employee employee = new Employee(0, null, "", 100000.99);

Double actualSalary = employee.getSalary();

assertEquals(100000.99, actualSalary);
}

@Test
public void testGetDetails() {
assertEquals("3 angie Software Engineer 100000.99.", testEmployee.getDetails());
}
}
Loading