Skip to content

fix: updated Kimberlee's Lesson 15 TDD: Unit test building by removing getSalary method and fixing Lesson15Test file #536

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 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
61e99da
feat:added test files
haldanek Oct 29, 2024
915b285
fix: fixed lesson15test file
haldanek Oct 29, 2024
3b4a5e5
chore: added second test
haldanek Oct 30, 2024
91c8815
chore: edit test 2
haldanek Oct 30, 2024
bfc1c22
chore: adds test 3
haldanek Oct 30, 2024
3e0ee14
fix: fixed test files
haldanek Oct 30, 2024
5bda902
fix: file edit
haldanek Oct 30, 2024
7847f94
chore: updated employeemanagertest
haldanek Oct 30, 2024
b56345f
chore: edit files
haldanek Oct 30, 2024
08346a3
Merge branch 'code-differently:main' into Lesson_15
haldanek Oct 30, 2024
328c058
chore: tried to fix tests/ removeEmployee and
haldanek Oct 31, 2024
36e2963
Merge remote-tracking branch 'refs/remotes/origin/Lesson_15' into Les…
haldanek Oct 31, 2024
f1d9734
feat: adds Employee.java test and getDetails Method
haldanek Oct 31, 2024
c776df3
Merge branch 'code-differently:main' into Lesson_15
haldanek Nov 1, 2024
3e23e19
Merge branch 'code-differently:main' into Lesson_15
haldanek Nov 1, 2024
2ca7730
Merge branch 'code-differently:main' into Lesson_15
haldanek Nov 1, 2024
63c7cd3
fix: fixed the Lesson15Test.java file
haldanek Nov 2, 2024
2e0e6a9
Merge remote-tracking branch 'refs/remotes/origin/Lesson_15' into Les…
haldanek Nov 2, 2024
8073d85
fix: removed getSalary method
haldanek Nov 2, 2024
4a93ee2
chore: fixed one of two failing tests
haldanek Nov 2, 2024
e391e36
Merge branch 'code-differently:main' into Lesson_15
haldanek Nov 4, 2024
0c3eb22
Merge branch 'code-differently:main' into Lesson_15
haldanek Nov 5, 2024
a2ce1af
Merge branch 'code-differently:main' into Lesson_15
haldanek Nov 14, 2024
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 Employee getDetails(Employee employee) {
return employee;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void assertEmployeeInCollection(int id) {
if (this.employees.containsKey(id)) {
return;
}
throw new IllegalArgumentException("Employee does not in collection with id " + id);
throw new IllegalArgumentException("Employee does not exist in collection with Id " + id);
}

public int getEmployeeCount() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.codedifferently.lesson15;

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

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

class EmployeeManagerTest {

private EmployeeManager employeeManager;
private Employee employee;

@BeforeEach
void setUp() {
employeeManager = new EmployeeManager();
employee = new Employee(1, "Edgar Allen Poe", "Publications", 0.0);
employeeManager.addEmployee(employee);
}

@Test
void testAddEmployee() {
// Arrange
Employee newEmployee = new Employee(2, "Sheet Ghost", "Administration", 0.0);
// Act
employeeManager.addEmployee(newEmployee);
// Assert
assertThat(employeeManager.getEmployee(2)).isEqualTo(newEmployee);
}

@Test
void testGetEmployee() {
// Act
Employee actualEmployee = employeeManager.getEmployee(1);
// Assert
assertThat(actualEmployee).isEqualTo(employee);
}

@Test
void testUpdateEmployee() {
// Arrange
Employee updatedEmployee = new Employee(1, "Frankenstein", "Development", 0.0);
// Act
employeeManager.updateEmployee(updatedEmployee);
Employee actualEmployee = employeeManager.getEmployee(1);
// Assert
assertThat(actualEmployee).isEqualTo(updatedEmployee);
}

@Test
void testRemoveEmployee() {
// Arrange
employeeManager.addEmployee(new Employee(1, "Frankenstein", "Development", 0.0));
// Act
employeeManager.removeEmployee(1);
Employee removedEmployee = employeeManager.getEmployee(1);
// Assert
assertEquals(0, employeeManager.getEmployeeCount(), "Employee count should be 0");
assertNull(removedEmployee, "Employee should be removed from directory.");
}

@Test
void testAssertEmployeeInCollection() {
// Arrange & Act & Assert
assertThatThrownBy(() -> employeeManager.getEmployee(52))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Employee does not exist in collection with Id 52");
}

@Test
void testGetEmployeeCount() {
// Arrange
Employee addNew1 = new Employee(2, "Dracula", "Medical", 0.0);
Employee addNew2 = new Employee(3, "Blade", "Security", 0.0);
// Act
employeeManager.addEmployee(addNew1);
employeeManager.addEmployee(addNew2);
// Assert
assertEquals(3, employeeManager.getEmployeeCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.codedifferently.lesson15;

import static org.assertj.core.api.Assertions.*;

import org.junit.jupiter.api.Test;

public class EmployeeTest {
private Employee employee;

@Test
void testGetDetails() {
// Arrange
employee = new Employee(1, "Jet Li", "Specialist", 110.00);
// Act
Employee actualDetails = employee.getDetails(employee);
// Assert
assertThat(actualDetails).isEqualTo(employee);
}
}
Loading