From 823d0572dc2b08a5a6c1b027a2360639b99cf105 Mon Sep 17 00:00:00 2001 From: Joel <60149879+Joel-Dandin@users.noreply.github.com> Date: Sun, 30 Jun 2024 09:17:40 +0530 Subject: [PATCH] fix: Issue 2975 Refactored Visitor (#3001) --- .../visitor/CommanderVisitorTest.java | 6 +-- .../iluwatar/visitor/SergeantVisitorTest.java | 6 +-- .../iluwatar/visitor/SoldierVisitorTest.java | 6 +-- .../com/iluwatar/visitor/VisitorTest.java | 37 +++++++++---------- 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/visitor/src/test/java/com/iluwatar/visitor/CommanderVisitorTest.java b/visitor/src/test/java/com/iluwatar/visitor/CommanderVisitorTest.java index 2fcf7497f574..b3ff8da5b05b 100644 --- a/visitor/src/test/java/com/iluwatar/visitor/CommanderVisitorTest.java +++ b/visitor/src/test/java/com/iluwatar/visitor/CommanderVisitorTest.java @@ -38,9 +38,9 @@ class CommanderVisitorTest extends VisitorTest { public CommanderVisitorTest() { super( new CommanderVisitor(), - Optional.of("Good to see you commander"), - Optional.empty(), - Optional.empty() + ("Good to see you commander"), + null, + null ); } diff --git a/visitor/src/test/java/com/iluwatar/visitor/SergeantVisitorTest.java b/visitor/src/test/java/com/iluwatar/visitor/SergeantVisitorTest.java index b2b9b7f572bc..b35473e39302 100644 --- a/visitor/src/test/java/com/iluwatar/visitor/SergeantVisitorTest.java +++ b/visitor/src/test/java/com/iluwatar/visitor/SergeantVisitorTest.java @@ -38,9 +38,9 @@ class SergeantVisitorTest extends VisitorTest { public SergeantVisitorTest() { super( new SergeantVisitor(), - Optional.empty(), - Optional.of("Hello sergeant"), - Optional.empty() + null, + ("Hello sergeant"), + null ); } diff --git a/visitor/src/test/java/com/iluwatar/visitor/SoldierVisitorTest.java b/visitor/src/test/java/com/iluwatar/visitor/SoldierVisitorTest.java index 98d5bf3ea7bd..11efb124c7e8 100644 --- a/visitor/src/test/java/com/iluwatar/visitor/SoldierVisitorTest.java +++ b/visitor/src/test/java/com/iluwatar/visitor/SoldierVisitorTest.java @@ -38,9 +38,9 @@ class SoldierVisitorTest extends VisitorTest { public SoldierVisitorTest() { super( new SoldierVisitor(), - Optional.empty(), - Optional.empty(), - Optional.of("Greetings soldier") + null, + null, + ("Greetings soldier") ); } diff --git a/visitor/src/test/java/com/iluwatar/visitor/VisitorTest.java b/visitor/src/test/java/com/iluwatar/visitor/VisitorTest.java index 6127a2e98e13..b3dacb2912d3 100644 --- a/visitor/src/test/java/com/iluwatar/visitor/VisitorTest.java +++ b/visitor/src/test/java/com/iluwatar/visitor/VisitorTest.java @@ -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; @@ -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 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 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 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 commanderResponse, - final Optional sergeantResponse, - final Optional soldierResponse + final String commanderResponse, + final String sergeantResponse, + final String soldierResponse ) { this.visitor = visitor; this.commanderResponse = commanderResponse; @@ -98,8 +97,8 @@ 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()); } } @@ -107,8 +106,8 @@ void testVisitCommander() { @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()); } } @@ -116,8 +115,8 @@ void testVisitSergeant() { @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()); } }