Skip to content

feat: adds lesson15 unit test homework by Yemi #481

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

public String getDetails() {
return "Employee ID: "
+ this.getId()
+ ", Name: "
+ this.getName()
+ ", Department: "
+ this.getDepartment()
+ ", Salary: "
+ this.getSalary();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.codedifferently.lesson15.Employee;
import com.codedifferently.lesson15.EmployeeManager;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class EmployeeManagerTest {
private EmployeeManager cut;

@BeforeEach
public void setUp() {
cut = new EmployeeManager();
Employee employee1 = new Employee(10, "Jojo", "Sales", 22.12);
cut.addEmployee(employee1);
}

@Test
public void testAddEmployee() {
// Arrange
Employee employee = new Employee(2, "Washington", "Finance", 29.23);

// Act
cut.addEmployee(employee);

// Assert
int expectedId = 2;
assertEquals(expectedId, cut.getEmployeeCount());
}

@Test
public void testUpdateEmployee() {
// Arrange
Employee employee = new Employee(5, "John", "Safety", 50);
cut.addEmployee(employee);

// Act
cut.updateEmployee(employee);

// Assert
int expectedId = 5;
assertEquals(expectedId, employee.getId());
}

@Test
public void testRemoveEmployee() {
// Arrange
Employee employee = new Employee(2, "Belvedere", "Finance", 100.1);
cut.addEmployee(employee);
// Act
cut.removeEmployee(employee.getId());

// Assert
int removedId = 2;
assertThatThrownBy(() -> cut.removeEmployee(removedId))
.isInstanceOf(IllegalArgumentException.class)
.hasMessage("Employee does not in collection with id " + removedId);
}

@Test
public void testGetEmployee() {
// Arrange
Employee employee = new Employee(2, "Washington", "Finance", 29.23);
// Act
cut.addEmployee(employee);

int employeeId = employee.getId();
Employee returnedEmployee = cut.getEmployee(employeeId);
// Assert
assertEquals(employee, returnedEmployee);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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 Employee cut;

@BeforeEach
public void setUp() {
cut = new Employee(1, "Wilmington", "HR", 200.00);
}

@Test
public void testGetName() {
// Arrange
cut.setName("Wilmington");

// Act
String expectedName = cut.getName();

// Assert
String actualName = "Wilmington";
assertEquals(expectedName, actualName, "The name should be 'Wilmington'");
}

@Test
public void testGetId() {
// Arrange
cut.setId(1);

// Act
int expectedId = cut.getId();

// Assert
int actualId = 1;
assertEquals(expectedId, actualId, "The id should be '1'");
}

@Test
public void testGetDepartment() {
// Arrange
cut.setDepartment("HR");

// Act
String expectedDept = cut.getDepartment();

// Assert
String actualDept = "HR";
assertEquals(expectedDept, actualDept, "The Department should be 'HR'");
}

@Test
public void testGetSalary() {
// Arrange
cut.setSalary(200.00);

// Act
double expectedSalary = cut.getSalary();

// Assert
double actualSalary = 200.00;
assertEquals(expectedSalary, actualSalary, "The Salary should be '200.00'");
}

@Test
public void testGetDetails() {
// Arrange
String expected = "Employee ID: 1, Name: Wilmington, Department: HR, Salary: 200.0";

// Act
String actual = cut.getDetails();

// Assert
assertEquals(expected, actual);
}
}
Loading