Skip to content

Commit

Permalink
Update CompanyEmployee methods and tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kousen committed Nov 9, 2023
1 parent a49c6a7 commit 40871a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/main/java/interfaces/CompanyEmployee.java
Original file line number Diff line number Diff line change
Expand Up @@ -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...");
}

}
4 changes: 2 additions & 2 deletions src/main/java/sorting/SortGolfers.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public void oldSchoolSort() {

// default sort is by score, using streams
public void defaultSort() {
golfers.stream()
.sorted()
golfers.stream() // Stream<Golfer>
.sorted() // Stream<Golfer> (natural sort)
.forEach(System.out::println);
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/interfaces/CompanyEmployeeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 40871a5

Please sign in to comment.