Skip to content

Feat: Adds for Lesson15.java Files for Nile Jackson #497

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 14 commits into from
Closed
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,24 @@ public double getSalary() {
public void setSalary(double salary) {
this.salary = salary;
}

public boolean isEqualTo(int otherId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Only needed to implement the getDetails method.

return this.id == otherId;
}

public String getDetails() {
return "id: "
+ this.getId()
+ " name: "
+ this.getName()
+ " department: "
+ this.getDepartment()
+ " salary: "
+ this.getSalary();
}

public void put(Employee employee) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'put'");
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be no changes to this file.

Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,37 @@

public class EmployeeManager {

private final Map<Integer, Employee> employees;
private Map<Integer, Employee> employees = new HashMap<>();

public EmployeeManager() {
employees = new HashMap<>();
public void addEmployee(Employee employee) {
employees.put(employee.getId(), employee);
}

public void addEmployee(Employee employee) {
public void removeEmployee(int id) {
employees.remove(id);
}

public void updateEmployee(Employee employee) {
employees.put(employee.getId(), employee);
}

public Employee getEmployee(int id) {
assertEmployeeInCollection(id);
return employees.get(id);
}

public void updateEmployee(Employee employee) {
assertEmployeeInCollection(employee.getId());
employees.put(employee.getId(), employee);
public int getEmployeeCount() {
return employees.size();
}

public void removeEmployee(int id) {
assertEmployeeInCollection(id);
employees.remove(id);
public Map<Integer, Employee> getEmployees() {
return employees;
}

private void assertEmployeeInCollection(int id) {
if (this.employees.containsKey(id)) {
return;
}
throw new IllegalArgumentException("Employee does not in collection with id " + id);
public void setEmployees(Map<Integer, Employee> employees) {
this.employees = employees;
}

public int getEmployeeCount() {
return employees.size();
public EmployeeManager() {
employees = new HashMap<>();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

File should be named EmployeeTest.java.

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

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

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

class EmployeeTest {

Employee employee;

// Set up
@BeforeEach
void setUp() {
employee = new Employee(7, "Nile", "SWE", 65000.00);
}

@Test
public void testGetId() {
int actualId = employee.getId();
int expectedId = 7;
assertEquals(expectedId, actualId);
}

@Test
public void testSetID() {
int expectedSetId = 0;
employee.setId(expectedSetId);
assertEquals(expectedSetId, employee.getId());
}

@Test
public void testGetName() {
String expectedName = "Nile";
String actualName = employee.getName();
assertEquals(expectedName, actualName);
}

@Test
public void testSetName() {
String expectedSetName = "Nile";
employee.setName(expectedSetName);
assertEquals(expectedSetName, employee.getName());
}

@Test
public void testGetDepartment() {
String expectedDepartment = "SWE";
String actualDepartment = employee.getDepartment();
assertEquals(expectedDepartment, actualDepartment);
}

@Test
public void testSetDepartment() {
String expectedSetDepartment = "Tech";
employee.setDepartment(expectedSetDepartment);
assertEquals(expectedSetDepartment, employee.getDepartment());
}

@Test
public void testGetSalary() {
double expectedSalary = 65000.00;
double actualSalary = employee.getSalary();
assertEquals(expectedSalary, actualSalary);
}

@Test
public void testSetSalary() {
double expectedSetSalary = 100000.00;
employee.setSalary(expectedSetSalary);
assertEquals(expectedSetSalary, employee.getSalary());
}

@Test
public void testGetDetails() {
String actualDetails = employee.getDetails();
String expectedDetails = "id: 7 name: Nile department: SWE salary: 65000.0";
assertEquals(expectedDetails, actualDetails);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.codedifferently.lesson15;

import static org.assertj.core.api.Assertions.assertThat;
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;
private Employee employee1;
private Employee employee2;

@BeforeEach
public void setup() {
employees = new HashMap<>();
employee1 = new Employee(1, "Nile", "SWE", 65000.00);
employee2 = new Employee(2, "Chino", "Marketing", 70000.00);

employeeManager = new EmployeeManager();
employeeManager.setEmployees(employees);
employeeManager.addEmployee(employee1);
employeeManager.addEmployee(employee2);
}

@Test
public void testEmployeeManagement() {}

@Test
public void addEmployee() {
assertThat(employees).hasSize(2);
}

@Test
public void getEmployee() {
Employee retrievedEmployee = employeeManager.getEmployee(2);
assertThat(retrievedEmployee.getName()).isEqualTo("Chino");
}

@Test
public void updateEmployee() {
employee1.setSalary(70000.00);
employeeManager.updateEmployee(employee1);

Employee updatedEmployee = employeeManager.getEmployee(1);
assertThat(updatedEmployee.getSalary()).isEqualTo(70000.00);
}

@Test
public void getEmployeeCount() {
int count = employeeManager.getEmployeeCount();
assertEquals(2, count);
}

@Test
public void getEmployees() {
Map<Integer, Employee> employeeMap = employeeManager.getEmployees();
assertThat(employeeMap.size()).isEqualTo(2);
}

@Test
public void setEmployees() {
Map<Integer, Employee> newEmployees = new HashMap<>();
newEmployees.put(3, new Employee(3, "Charlie", "HR", 75000.00));
employeeManager.setEmployees(newEmployees);

assertThat(employeeManager.getEmployees().size()).isEqualTo(1);
}

@Test
public void testGetDetails() {
String actualDetails = employee1.getDetails();
String expectedDetails = "id: 1 name: Nile department: SWE salary: 65000.0";
assertEquals(expectedDetails, actualDetails);
}
}
Loading