Skip to content

Commit

Permalink
fix: Issue 2975 Refactored Visitor (iluwatar#3001)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel-Dandin authored Jun 30, 2024
1 parent fab64a2 commit 823d057
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class CommanderVisitorTest extends VisitorTest<CommanderVisitor> {
public CommanderVisitorTest() {
super(
new CommanderVisitor(),
Optional.of("Good to see you commander"),
Optional.empty(),
Optional.empty()
("Good to see you commander"),
null,
null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class SergeantVisitorTest extends VisitorTest<SergeantVisitor> {
public SergeantVisitorTest() {
super(
new SergeantVisitor(),
Optional.empty(),
Optional.of("Hello sergeant"),
Optional.empty()
null,
("Hello sergeant"),
null
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class SoldierVisitorTest extends VisitorTest<SoldierVisitor> {
public SoldierVisitorTest() {
super(
new SoldierVisitor(),
Optional.empty(),
Optional.empty(),
Optional.of("Greetings soldier")
null,
null,
("Greetings soldier")
);
}

Expand Down
37 changes: 18 additions & 19 deletions visitor/src/test/java/com/iluwatar/visitor/VisitorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import ch.qos.logback.core.AppenderBase;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -62,32 +61,32 @@ void tearDown() {
private final V visitor;

/**
* The optional expected response when being visited by a commander.
* The expected response when being visited by a commander.
*/
private final Optional<String> commanderResponse;
private final String commanderResponse;

/**
* The optional expected response when being visited by a sergeant.
* The expected response when being visited by a sergeant.
*/
private final Optional<String> sergeantResponse;
private final String sergeantResponse;

/**
* The optional expected response when being visited by a soldier.
* The expected response when being visited by a soldier.
*/
private final Optional<String> soldierResponse;
private final String soldierResponse;

/**
* Create a new test instance for the given visitor.
*
* @param commanderResponse The optional expected response when being visited by a commander
* @param sergeantResponse The optional expected response when being visited by a sergeant
* @param soldierResponse The optional expected response when being visited by a soldier
* @param commanderResponse The expected response when being visited by a commander
* @param sergeantResponse The expected response when being visited by a sergeant
* @param soldierResponse The expected response when being visited by a soldier
*/
public VisitorTest(
final V visitor,
final Optional<String> commanderResponse,
final Optional<String> sergeantResponse,
final Optional<String> soldierResponse
final String commanderResponse,
final String sergeantResponse,
final String soldierResponse
) {
this.visitor = visitor;
this.commanderResponse = commanderResponse;
Expand All @@ -98,26 +97,26 @@ public VisitorTest(
@Test
void testVisitCommander() {
this.visitor.visit(new Commander());
if (this.commanderResponse.isPresent()) {
assertEquals(this.commanderResponse.get(), appender.getLastMessage());
if (this.commanderResponse != null) {
assertEquals(this.commanderResponse, appender.getLastMessage());
assertEquals(1, appender.getLogSize());
}
}

@Test
void testVisitSergeant() {
this.visitor.visit(new Sergeant());
if (this.sergeantResponse.isPresent()) {
assertEquals(this.sergeantResponse.get(), appender.getLastMessage());
if (this.sergeantResponse != null) {
assertEquals(this.sergeantResponse, appender.getLastMessage());
assertEquals(1, appender.getLogSize());
}
}

@Test
void testVisitSoldier() {
this.visitor.visit(new Soldier());
if (this.soldierResponse.isPresent()) {
assertEquals(this.soldierResponse.get(), appender.getLastMessage());
if (this.soldierResponse != null) {
assertEquals(this.soldierResponse, appender.getLastMessage());
assertEquals(1, appender.getLogSize());
}
}
Expand Down

0 comments on commit 823d057

Please sign in to comment.