Skip to content

feat: practiced unit testing Lesson 15 Hw by Hummad Tanweer #496

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

public String getDetails() {
return "ID:" + id + "Name: " + name + "Department: " + department + "salary: " + salary;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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 EmployeeManagerTest {

EmployeeManager employeeManager;

Employee employee;

@BeforeEach
public void setUp() {
employeeManager = new EmployeeManager();
employee = new Employee(2, "Hummad", "Finance", 2000);
}

@Test
public void testAddEmployee() {

employeeManager.addEmployee(employee);
Employee employee1 = new Employee(3, "Hummad", "Finance", 2000);
employeeManager.addEmployee(employee1);

assertEquals(2, employeeManager.getEmployeeCount());
}

@Test
public void testGetEmployee() {

employeeManager.addEmployee(employee);

assertEquals(employee, employeeManager.getEmployee(employee.getId()));
}

@Test
public void testGetEmployeeCount() {

employee = new Employee(2, "Hummad", "Finance", 2000);
Employee employee1 = new Employee(3, "Hummad", "Finance", 2000);

employeeManager.addEmployee(employee1);

employeeManager.addEmployee(employee);

assertEquals(2, employeeManager.getEmployeeCount());
}

@Test
public void testRemoveEmployee() {

employeeManager.addEmployee(employee);

employeeManager.removeEmployee(employee.getId());

assertEquals(0, employeeManager.getEmployeeCount());
}

@Test
public void testUpdateEmployee() {

employee = new Employee(2, "Hummad", "Finance", 2000);

employeeManager.addEmployee(employee);

employeeManager.updateEmployee(employee);

assertEquals(employeeManager.getEmployee(employee.getId()), employee);
Copy link
Contributor

Choose a reason for hiding this comment

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

Arguments reversed, the expected argument goes first.

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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 {

Employee employee;

@BeforeEach
void setUp() {
employee = new Employee(2, "Hummad", "Finance", 2000);
}

@Test
public void testGetId() {

int actualId = 2;
int expectedId = employee.getId();
assertEquals(expectedId, actualId);
}

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

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

@Test
public void testSetId() {

employee.setId(10);
assertEquals(employee.getId(), 10);
}

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

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

@Test
public void testGetDepartment() {

assertEquals(employee.getDepartment(), "Finance");
}

@Test
public void testSetDepartment() {

employee.setDepartment("Finance");
assertEquals(employee.getDepartment(), "Finance");
}

@Test
public void testGetDetails() {

// String expectedDetails = "2 Hummad Finance 2000";
Copy link
Contributor

Choose a reason for hiding this comment

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

Cannot commit commented out code.

assertEquals("ID:2Name: HummadDepartment: Financesalary: 2000.0", employee.getDetails());
}
}
Loading