-
Notifications
You must be signed in to change notification settings - Fork 25
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
lesson_15/tdd/tdd_app/src/test/java/com/codedifferently/lesson15/EmployeeManagerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
lesson_15/tdd/tdd_app/src/test/java/com/codedifferently/lesson15/EmployeeTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.