-
Notifications
You must be signed in to change notification settings - Fork 25
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
Closed
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c00f98a
feat: added lesson15 unit test homework by Yemi
jimoye244 b6c43af
Merge branch 'code-differently:main' into feature/lesson16
jimoye244 4604aff
feat: updated lesson15 unit test HW to handle exception case by Yemi
jimoye244 06b3063
feat: updated lesson15 unit test HW to handle exception case by Yemi
jimoye244 1d73f5c
fix: moved unit test file to right folder by Yemi
jimoye244 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
69 changes: 69 additions & 0 deletions
69
lesson_15/tdd/tdd_app/src/test/java/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,69 @@ | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
|
||
| 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 testgetEmployee() { | ||
| // Arrange | ||
| Employee employee = new Employee(2, "Washington", "Finance", 29.23); | ||
|
|
||
| // Act | ||
| Employee returnedEmployee = cut.getEmployee(employee.getId()); | ||
|
|
||
| // Assert | ||
| assertNull(returnedEmployee); | ||
| } | ||
|
|
||
| @Test | ||
| public void testRemoveEmployee() { | ||
| // Arrange | ||
| Employee employee = new Employee(3, "Belvedere", "Finance", 100.1); | ||
|
|
||
| // Act | ||
| cut.removeEmployee(employee.getId()); | ||
|
|
||
| // Assert | ||
| int removedId = 3; | ||
| assertNull(cut.getEmployee(removedId)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testUpdateEmployee() { | ||
| // Arrange | ||
| Employee employee = new Employee(5, "John", "Safety", 50); | ||
|
|
||
| // Act | ||
| cut.updateEmployee(employee); | ||
|
|
||
| // Assert | ||
| int expectedId = 5; | ||
| assertEquals(expectedId, employee.getId()); | ||
| } | ||
| } | ||
79 changes: 79 additions & 0 deletions
79
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,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 = cut.getSalary(); | ||
| 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); | ||
| } | ||
| } |
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.
Better name would be
testGetEmployee_doesntExist.