From 40871a5d8b892daf4c40b4ed0d2cd2381230478d Mon Sep 17 00:00:00 2001 From: Ken Kousen Date: Wed, 8 Nov 2023 21:30:56 -0700 Subject: [PATCH] Update CompanyEmployee methods and tests In CompanyEmployee.java, added a new method company() to return the Company name, making the class more robust. Modified the doWork() method to make the output more general. In SortGolfers.java, updated the comment lines to give a clearer understanding of the operation. A new unit test for the company() method was created in CompanyEmployeeTest.java for better coverage. --- src/main/java/interfaces/CompanyEmployee.java | 7 +++++-- src/main/java/sorting/SortGolfers.java | 4 ++-- src/test/java/interfaces/CompanyEmployeeTest.java | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/interfaces/CompanyEmployee.java b/src/main/java/interfaces/CompanyEmployee.java index 660d947..e9bd88d 100644 --- a/src/main/java/interfaces/CompanyEmployee.java +++ b/src/main/java/interfaces/CompanyEmployee.java @@ -12,9 +12,12 @@ public String getName() { return Employee.super.getName() + " works for " + Company.super.getName(); } - @Override + public String company() { + return Company.super.getName(); + } + public void doWork() { - System.out.println("Preparing TPS reports for six different bosses..."); + System.out.println("Work, work..."); } } diff --git a/src/main/java/sorting/SortGolfers.java b/src/main/java/sorting/SortGolfers.java index 66977bc..c1cadda 100644 --- a/src/main/java/sorting/SortGolfers.java +++ b/src/main/java/sorting/SortGolfers.java @@ -21,8 +21,8 @@ public void oldSchoolSort() { // default sort is by score, using streams public void defaultSort() { - golfers.stream() - .sorted() + golfers.stream() // Stream + .sorted() // Stream (natural sort) .forEach(System.out::println); } diff --git a/src/test/java/interfaces/CompanyEmployeeTest.java b/src/test/java/interfaces/CompanyEmployeeTest.java index 35e7539..34414dc 100644 --- a/src/test/java/interfaces/CompanyEmployeeTest.java +++ b/src/test/java/interfaces/CompanyEmployeeTest.java @@ -16,4 +16,10 @@ public void getName() { CompanyEmployee emp = new CompanyEmployee("Peter", "Gibbons"); assertEquals("Peter Gibbons works for Initech", emp.getName()); } + + @Test + void getCompany() { + CompanyEmployee emp = new CompanyEmployee("Peter", "Gibbons"); + assertEquals("Initech", emp.company()); + } } \ No newline at end of file