-
Notifications
You must be signed in to change notification settings - Fork 25
Feat: Added Lesson 15 Employee and EmployeeManager Tests #487
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
40 commits
Select commit
Hold shift + click to select a range
887b8f0
Merge pull request #1 from code-differently/main
A1-4U2T1NN 05ad627
Merge branch 'code-differently:main' into main
A1-4U2T1NN 5715b6a
Merge branch 'code-differently:main' into main
A1-4U2T1NN 6c909b0
Merge branch 'code-differently:main' into main
A1-4U2T1NN 4c1a3f2
Merge branch 'code-differently:main' into main
A1-4U2T1NN de19403
Merge branch 'code-differently:main' into main
A1-4U2T1NN 56aa83d
Merge branch 'code-differently:main' into main
A1-4U2T1NN 8529105
Merge branch 'code-differently:main' into main
A1-4U2T1NN 4f76813
Merge branch 'code-differently:main' into main
A1-4U2T1NN 48bf962
Merge branch 'code-differently:main' into main
A1-4U2T1NN 1da88b9
Merge branch 'code-differently:main' into main
A1-4U2T1NN 3068765
Merge branch 'code-differently:main' into main
A1-4U2T1NN 712efd6
Merge branch 'code-differently:main' into main
A1-4U2T1NN 5db7413
Merge branch 'code-differently:main' into main
A1-4U2T1NN 5096f8e
Merge branch 'code-differently:main' into main
A1-4U2T1NN 09341aa
Merge branch 'code-differently:main' into main
A1-4U2T1NN a8f634e
Merge branch 'code-differently:main' into main
A1-4U2T1NN b643a4c
feat: created chigazograham.json file
cae2152
Merge branch 'code-differently:main' into main
A1-4U2T1NN 68ccb5f
fix: deleted lesson_09 content from main;
7d4f86f
Merge branch 'code-differently:main' into main
A1-4U2T1NN 473eb98
Merge branch 'code-differently:main' into main
A1-4U2T1NN 1d19106
Merge branch 'code-differently:main' into main
A1-4U2T1NN bba5af5
Merge branch 'code-differently:main' into main
A1-4U2T1NN a51c852
Merge branch 'code-differently:main' into main
A1-4U2T1NN 8a39fcc
Merge branch 'code-differently:main' into main
A1-4U2T1NN ac98745
Merge branch 'code-differently:main' into main
A1-4U2T1NN eade00f
Merge branch 'code-differently:main' into main
A1-4U2T1NN bf252ad
Merge branch 'code-differently:main' into main
A1-4U2T1NN 955b86f
Merge branch 'code-differently:main' into main
A1-4U2T1NN b6f63bd
Merge branch 'code-differently:main' into main
A1-4U2T1NN 22db65b
Merge branch 'code-differently:main' into main
A1-4U2T1NN d5eff9e
Merge branch 'code-differently:main' into main
A1-4U2T1NN 28ebc46
feat: added test framework for EmployeeTest and EmployeeManagerTest
845074e
Merge branch 'code-differently:main' into lesson_15
A1-4U2T1NN 9b45e84
feat: added Arrange, Act, and Assert methods for all 'textGet...' fun…
863a8da
feat: added Arrange, Act, and Assert methods for testSetDepartment an…
2442d62
feat: added getDetails method to Employee.java; created corresponding…
c1c218b
fix: Ran './gradlew :tdd_app:spotlessApply' to correct formatting;
3cfbfff
fix: removed duplicate EmployeeManagerTest;
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
75 changes: 75 additions & 0 deletions
75
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,75 @@ | ||
package com.codedifferently.lesson15; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class EmployeeManagerTest { | ||
|
||
EmployeeManager employeeManager; | ||
List<Employee> employees; | ||
|
||
// Set up | ||
@BeforeEach | ||
void setUp() { | ||
employeeManager = new EmployeeManager(); | ||
Employee employee = new Employee(0, "Nitsua", "Sales", 65000.00); | ||
employeeManager.addEmployee(employee); | ||
employees = new ArrayList(); | ||
employees.add(employee); | ||
} | ||
|
||
@Test | ||
public void testAddEmployee() { | ||
// Arrange | ||
Employee employee1 = new Employee(1, "Penny", "Sales", 65000.00); | ||
// Act & Assert | ||
employeeManager.addEmployee(employee1); | ||
} | ||
|
||
@Test | ||
public void testGetEmployee() { | ||
// Arrange | ||
Employee employee = new Employee(0, "Nitsua", "Sales", 65000.00); | ||
Employee expectedEmployee = employeeManager.getEmployee(employee.getId()); | ||
// Act | ||
Employee actualEmployee = employeeManager.getEmployee(0); | ||
// Assert | ||
assertEquals(expectedEmployee, actualEmployee); | ||
} | ||
|
||
@Test | ||
public void testUpdateEmployee() { | ||
// Arrange | ||
Employee expectedEmployeeUpdate = new Employee(0, "Nitsua", "Tech", 100000.00); | ||
// Act | ||
employeeManager.updateEmployee(expectedEmployeeUpdate); | ||
// Act | ||
assertEquals(expectedEmployeeUpdate, employeeManager.getEmployee(0)); | ||
} | ||
|
||
@Test | ||
public void testRemoveEmployee() { | ||
// Arange | ||
Employee employee = new Employee(0, "Nitsua", "Sales", 65000.00); | ||
employeeManager.addEmployee(employee); | ||
// Act | ||
employeeManager.removeEmployee(0); | ||
// Assert | ||
assertThatThrownBy(() -> employeeManager.removeEmployee(0)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("Employee does not in collection with id " + employee.getId()); | ||
} | ||
|
||
@Test | ||
public void testGetEmployeeCount() { | ||
// Act | ||
int actualEmployeeCount = employeeManager.getEmployeeCount(); | ||
// Assert(recieved help from Vicente on employees array) | ||
assertEquals(employees.size(), actualEmployeeCount); | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
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,116 @@ | ||
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; | ||
|
||
// Set up | ||
@BeforeEach | ||
void setUp() { | ||
employee = new Employee(19, "Chigazo", "Finance", 50000.00); | ||
} | ||
|
||
@Test | ||
// Method being tested | ||
public void testGetId() { | ||
// Execersise | ||
int actualId = employee.getId(); | ||
|
||
int expectedId = 19; | ||
// Assert(Checking the value) | ||
assertEquals(expectedId, actualId); | ||
} | ||
|
||
@Test | ||
public void testSetID() { | ||
// Arrange | ||
int expectedSetId = 91; | ||
// Act | ||
employee.setId(expectedSetId); | ||
// Assert | ||
assertEquals(expectedSetId, employee.getId()); | ||
} | ||
|
||
@Test | ||
public void testGetName() { | ||
// Arrange | ||
String expectedName = "Chigazo"; | ||
// Act | ||
String actualName = employee.getName(); | ||
// Assert | ||
assertEquals(expectedName, actualName); | ||
} | ||
|
||
@Test | ||
public void testSetName() { | ||
// Arrange | ||
String expectedSetName = "Austin"; | ||
// Act | ||
employee.setName(expectedSetName); | ||
// Assert | ||
assertEquals(expectedSetName, employee.getName()); | ||
} | ||
|
||
@Test | ||
public void testGetDepartment() { | ||
// Arrange | ||
String actualDepartment = "Finance"; | ||
// Act | ||
String expectedDepartment = employee.getDepartment(); | ||
// Assert | ||
assertEquals(expectedDepartment, actualDepartment); | ||
} | ||
|
||
@Test | ||
public void testSetDepartment() { | ||
// Arrange | ||
String expectedSetDepartment = "Tech"; | ||
// Act | ||
employee.setDepartment(expectedSetDepartment); | ||
// Assert | ||
assertEquals(expectedSetDepartment, employee.getDepartment()); | ||
} | ||
|
||
@Test | ||
public void testGetSalary() { | ||
// Arrange | ||
double actualSalary = 50000.00; | ||
// Act | ||
double expectedSalary = employee.getSalary(); | ||
// Assert | ||
assertEquals(expectedSalary, actualSalary); | ||
} | ||
|
||
@Test | ||
public void testSetSalary() { | ||
// Arrange | ||
double expectedSetSalary = 100000.00; | ||
// Act | ||
employee.setSalary(expectedSetSalary); | ||
// Assert | ||
assertEquals(expectedSetSalary, employee.getSalary()); | ||
} | ||
|
||
@Test | ||
public void testGetDetails() { | ||
// Arrange | ||
String actualDetails = | ||
"id: " | ||
+ employee.getId() | ||
+ "name: " | ||
+ employee.getName() | ||
+ "department: " | ||
+ employee.getDepartment() | ||
+ "salary: " | ||
+ employee.getSalary(); | ||
// Act | ||
String expectedDetails = employee.getDetails(); | ||
// Assert | ||
assertEquals(expectedDetails, actualDetails); | ||
} | ||
} |
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.
Need an actual assertion.