Skip to content

Feat : Yafiah Lesson-15 Unit Test Employee & EmployeeManager #499

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 1 commit 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 "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,48 @@
package test.java.com.codedifferently.lesson15;

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

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

class EmployeeManagerTest {
private EmployeeManager employeeManager;
private Employee employee;

@BeforeEach
public void setUp() {
employeeManager = new EmployeeManager();
employee = new Employee(1, "Yafiah", "Engineering", 75000.0);
employeeManager.addEmployee(employee);
}

@Test
public void testAddEmployee() {
assertEquals(1, employeeManager.getEmployeeCount());
}

@Test
public void testGetEmployee() {
assertEquals(employee, employeeManager.getEmployee(1));
}

@Test
public void testUpdateEmployee() {
Employee updatedEmployee = new Employee(1, "Yafiah", "Engineering", 80000.0);
employeeManager.updateEmployee(updatedEmployee);
assertEquals(80000.0, employeeManager.getEmployee(1).getSalary());
}

@Test
public void testRemoveEmployee() {
employeeManager.removeEmployee(1);
assertEquals(0, employeeManager.getEmployeeCount());
}

@Test
public void testGetEmployeeCount() {
assertEquals(1, employeeManager.getEmployeeCount());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.codedifferently.lesson15;

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

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

public class EmployeeTest {
private Employee employee;

@BeforeEach
public void setUp() {
employee = new Employee(1, "Yafiah", "Engineering", 75000.0);
}

@Test
public void testGetId() {
assertEquals(1, employee.getId());
}

@Test
public void testGetName() {
assertEquals("Yafiah", employee.getName());
}

@Test
public void testGetDepartment() {
assertEquals("Engineering", employee.getDepartment());
}

@Test
public void testGetSalary() {
assertEquals(75000.0, employee.getSalary());
}

@Test
public void testSetId() {
employee.setId(2);
assertEquals(2, employee.getId());
}

@Test
public void testSetName() {
employee.setName("Nash");
assertEquals("Nash", employee.getName());
}

@Test
public void testSetDepartment() {
employee.setDepartment("Marketing");
assertEquals("Marketing", employee.getDepartment());
}

@Test
public void testSetSalary() {
employee.setSalary(80000.0);
assertEquals(80000.0, employee.getSalary());
}

@Test
public void testGetDetails() {
String expectedDetails = "ID: 1, Name: Yafiah, Department: Engineering, Salary: $75000.0";
assertEquals(expectedDetails, employee.getDetails());
}
}
Loading