Skip to content

feat: adds Kimberlee's Lesson 15 TDD: Unit test building #500

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

public boolean containsKey(Object id2) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'containsKey'");
}

public Employee getDetails(Employee employee) {
return employee;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
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() {
// 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 1");
}

@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);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
package com.codedifferently.lesson15;

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

import org.junit.jupiter.api.Test;

class Lesson15Test {

@Test
public void testLesson15() {
assertThat(new Lesson15()).isNotNull();
}

@Test
public void testGetGreeting() {
// Act
Lesson15.main(null);
}
}
Loading