diff --git a/component/pom.xml b/component/pom.xml
index e71b1cc59716..f75b981aa666 100644
--- a/component/pom.xml
+++ b/component/pom.xml
@@ -1,65 +1,15 @@
-
-
-
The implementation has decoupled graphic, physics and input components from - * the player and NPC objects. As a result, it avoids the creation of monolithic java classes. - * - *
The below example in this App class demonstrates the use of the component interfaces - * for separate objects (player & NPC) and updating of these components as per the - * implementations in GameObject class and the component classes. - */ -@Slf4j -public final class App { - /** - * Program entry point. - * - * @param args args command line args. - */ - public static void main(String[] args) { - final var player = GameObject.createPlayer(); - final var npc = GameObject.createNpc(); - - - LOGGER.info("Player Update:"); - player.update(KeyEvent.KEY_LOCATION_LEFT); - LOGGER.info("NPC Update:"); - npc.demoUpdate(); - } -} diff --git a/component/src/main/java/com/iluwatar/component/FirstTask.java b/component/src/main/java/com/iluwatar/component/FirstTask.java new file mode 100644 index 000000000000..24d561232207 --- /dev/null +++ b/component/src/main/java/com/iluwatar/component/FirstTask.java @@ -0,0 +1,36 @@ +package com.iluwatar.component; +public class FirstTask implements Task { + private String title; + + public FirstTask(String title) { + this.title = title; + } + + @Override + public String getTitle() { + return title; + } + + @Override + public void setTitle(String title) { + this.title = title; + } + + @Override + public void addTask(Task task) { + // Not applicable for FirstTask, as it's a leaf node. + } + + @Override + public void removeTask(Task task) { + // Not applicable for FirstTask, as it's a leaf node. + } + + @Override + public void display() { + System.out.println("FirstTask: " + title); + } +} + + + diff --git a/component/src/main/java/com/iluwatar/component/GameObject.java b/component/src/main/java/com/iluwatar/component/GameObject.java index c67970d0625f..8b137891791f 100644 --- a/component/src/main/java/com/iluwatar/component/GameObject.java +++ b/component/src/main/java/com/iluwatar/component/GameObject.java @@ -1,118 +1 @@ -/* - * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). - * - * The MIT License - * Copyright © 2014-2022 Ilkka Seppälä - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package com.iluwatar.component; -import com.iluwatar.component.component.graphiccomponent.GraphicComponent; -import com.iluwatar.component.component.graphiccomponent.ObjectGraphicComponent; -import com.iluwatar.component.component.inputcomponent.DemoInputComponent; -import com.iluwatar.component.component.inputcomponent.InputComponent; -import com.iluwatar.component.component.inputcomponent.PlayerInputComponent; -import com.iluwatar.component.component.physiccomponent.ObjectPhysicComponent; -import com.iluwatar.component.component.physiccomponent.PhysicComponent; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -/** - * The GameObject class has three component class instances that allow - * the creation of different game objects based on the game design requirements. - */ -@Getter -@RequiredArgsConstructor -public class GameObject { - private final InputComponent inputComponent; - private final PhysicComponent physicComponent; - private final GraphicComponent graphicComponent; - - private final String name; - private int velocity = 0; - private int coordinate = 0; - - /** - * Creates a player game object. - * - * @return player object - */ - public static GameObject createPlayer() { - return new GameObject(new PlayerInputComponent(), - new ObjectPhysicComponent(), - new ObjectGraphicComponent(), - "player"); - } - - - /** - * Creates a NPC game object. - * - * @return npc object - */ - public static GameObject createNpc() { - return new GameObject( - new DemoInputComponent(), - new ObjectPhysicComponent(), - new ObjectGraphicComponent(), - "npc"); - } - - /** - * Updates the three components of the NPC object used in the demo in App.java - * note that this is simply a duplicate of update() without the key event for - * demonstration purposes. - * - *
This method is usually used in games if the player becomes inactive.
- */
- public void demoUpdate() {
- inputComponent.update(this, 0);
- physicComponent.update(this);
- graphicComponent.update(this);
- }
-
- /**
- * Updates the three components for objects based on key events.
- *
- * @param e key event from the player.
- */
- public void update(int e) {
- inputComponent.update(this, e);
- physicComponent.update(this);
- graphicComponent.update(this);
- }
-
- /**
- * Update the velocity based on the acceleration of the GameObject.
- *
- * @param acceleration the acceleration of the GameObject
- */
- public void updateVelocity(int acceleration) {
- this.velocity += acceleration;
- }
-
-
- /**
- * Set the c based on the current velocity.
- */
- public void updateCoordinate() {
- this.coordinate += this.velocity;
- }
-}
diff --git a/component/src/main/java/com/iluwatar/component/Task.java b/component/src/main/java/com/iluwatar/component/Task.java
new file mode 100644
index 000000000000..cc4fd3e7c0b1
--- /dev/null
+++ b/component/src/main/java/com/iluwatar/component/Task.java
@@ -0,0 +1,10 @@
+package com.iluwatar.component;
+
+public interface Task {
+ String getTitle();
+ void setTitle(String title);
+ void addTask(Task task);
+ void removeTask(Task task);
+ void display();
+}
+
diff --git a/component/src/main/java/com/iluwatar/component/TaskFactory.java b/component/src/main/java/com/iluwatar/component/TaskFactory.java
new file mode 100644
index 000000000000..6db35669fdc1
--- /dev/null
+++ b/component/src/main/java/com/iluwatar/component/TaskFactory.java
@@ -0,0 +1,14 @@
+package com.iluwatar.component;
+
+public class TaskFactory {
+
+ // Creates and returns a simple task
+ public static Task createFirstTask(String title) {
+ return new FirstTask(title);
+ }
+
+ // Creates and returns a task list
+ public static TaskList createTaskList(String title) {
+ return new TaskList(title);
+ }
+}
diff --git a/component/src/main/java/com/iluwatar/component/TaskList.java b/component/src/main/java/com/iluwatar/component/TaskList.java
new file mode 100644
index 000000000000..bd97e31dc5b2
--- /dev/null
+++ b/component/src/main/java/com/iluwatar/component/TaskList.java
@@ -0,0 +1,46 @@
+package com.iluwatar.component;
+import java.util.ArrayList;
+import java.util.List;
+
+public class TaskList implements Task {
+ private String title;
+ private final List Essentially, the demo mode is utilised during a game if the user become inactive.
- * Please see: http://gameprogrammingpatterns.com/component.html
- */
-@Slf4j
-public class DemoInputComponent implements InputComponent {
- private static final int WALK_ACCELERATION = 2;
-
- /**
- * Redundant method in the demo mode.
- *
- * @param gameObject the gameObject instance
- * @param e key event instance
- */
- @Override
- public void update(GameObject gameObject, int e) {
- gameObject.updateVelocity(WALK_ACCELERATION);
- LOGGER.info(gameObject.getName() + " has moved right.");
- }
-}
diff --git a/component/src/main/java/com/iluwatar/component/component/inputcomponent/InputComponent.java b/component/src/main/java/com/iluwatar/component/component/inputcomponent/InputComponent.java
index 3ab30c148cdc..8b137891791f 100644
--- a/component/src/main/java/com/iluwatar/component/component/inputcomponent/InputComponent.java
+++ b/component/src/main/java/com/iluwatar/component/component/inputcomponent/InputComponent.java
@@ -1,34 +1 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.component.component.inputcomponent;
-import com.iluwatar.component.GameObject;
-
-/**
- * Generic InputComponent interface.
- */
-public interface InputComponent {
- void update(GameObject gameObject, int e);
-}
diff --git a/component/src/main/java/com/iluwatar/component/component/inputcomponent/PlayerInputComponent.java b/component/src/main/java/com/iluwatar/component/component/inputcomponent/PlayerInputComponent.java
index eb9e9d800059..e69de29bb2d1 100644
--- a/component/src/main/java/com/iluwatar/component/component/inputcomponent/PlayerInputComponent.java
+++ b/component/src/main/java/com/iluwatar/component/component/inputcomponent/PlayerInputComponent.java
@@ -1,62 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.component.component.inputcomponent;
-
-import com.iluwatar.component.GameObject;
-import java.awt.event.KeyEvent;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * PlayerInputComponent is used to handle user key event inputs,
- * and thus it implements the InputComponent interface.
- */
-@Slf4j
-public class PlayerInputComponent implements InputComponent {
- private static final int WALK_ACCELERATION = 1;
-
- /**
- * The update method to change the velocity based on the input key event.
- *
- * @param gameObject the gameObject instance
- * @param e key event instance
- */
- @Override
- public void update(GameObject gameObject, int e) {
- switch (e) {
- case KeyEvent.KEY_LOCATION_LEFT -> {
- gameObject.updateVelocity(-WALK_ACCELERATION);
- LOGGER.info(gameObject.getName() + " has moved left.");
- }
- case KeyEvent.KEY_LOCATION_RIGHT -> {
- gameObject.updateVelocity(WALK_ACCELERATION);
- LOGGER.info(gameObject.getName() + " has moved right.");
- }
- default -> {
- LOGGER.info(gameObject.getName() + "'s velocity is unchanged due to the invalid input");
- gameObject.updateVelocity(0);
- } // incorrect input
- }
- }
-}
diff --git a/component/src/main/java/com/iluwatar/component/component/physiccomponent/ObjectPhysicComponent.java b/component/src/main/java/com/iluwatar/component/component/physiccomponent/ObjectPhysicComponent.java
index b8d880138534..e69de29bb2d1 100644
--- a/component/src/main/java/com/iluwatar/component/component/physiccomponent/ObjectPhysicComponent.java
+++ b/component/src/main/java/com/iluwatar/component/component/physiccomponent/ObjectPhysicComponent.java
@@ -1,46 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.component.component.physiccomponent;
-
-import com.iluwatar.component.GameObject;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * Take this component class to update the x coordinate for the Game Object instance.
- */
-@Slf4j
-public class ObjectPhysicComponent implements PhysicComponent {
-
- /**
- * The method update the horizontal (X-axis) coordinate based on the velocity of gameObject.
- *
- * @param gameObject the gameObject instance
- */
- @Override
- public void update(GameObject gameObject) {
- gameObject.updateCoordinate();
- LOGGER.info(gameObject.getName() + "'s coordinate has been changed.");
- }
-}
diff --git a/component/src/main/java/com/iluwatar/component/component/physiccomponent/PhysicComponent.java b/component/src/main/java/com/iluwatar/component/component/physiccomponent/PhysicComponent.java
index 25e2dfd40b8b..e69de29bb2d1 100644
--- a/component/src/main/java/com/iluwatar/component/component/physiccomponent/PhysicComponent.java
+++ b/component/src/main/java/com/iluwatar/component/component/physiccomponent/PhysicComponent.java
@@ -1,34 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.component.component.physiccomponent;
-
-import com.iluwatar.component.GameObject;
-
-/**
- * Generic PhysicComponent interface.
- */
-public interface PhysicComponent {
- void update(GameObject gameObject);
-}
diff --git a/component/src/test/java/com/iluwatar/component/AppTest.java b/component/src/test/java/com/iluwatar/component/AppTest.java
deleted file mode 100644
index 6fa191804c84..000000000000
--- a/component/src/test/java/com/iluwatar/component/AppTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.component;
-
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-
-/**
- * Tests App class : src/main/java/com/iluwatar/component/App.java
- * General execution test of the application.
- */
-class AppTest {
-
- @Test
- void shouldExecuteComponentWithoutException() {
- assertDoesNotThrow(() -> App.main(new String[]{}));
- }
-}
diff --git a/component/src/test/java/com/iluwatar/component/GameObjectTest.java b/component/src/test/java/com/iluwatar/component/GameObjectTest.java
index 66b6c6a5523a..8b137891791f 100644
--- a/component/src/test/java/com/iluwatar/component/GameObjectTest.java
+++ b/component/src/test/java/com/iluwatar/component/GameObjectTest.java
@@ -1,95 +1 @@
-/*
- * This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt).
- *
- * The MIT License
- * Copyright © 2014-2022 Ilkka Seppälä
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- */
-package com.iluwatar.component;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import java.awt.event.KeyEvent;
-import lombok.extern.slf4j.Slf4j;
-
-/**
- * Tests GameObject class.
- * src/main/java/com/iluwatar/component/GameObject.java
- */
-@Slf4j
-class GameObjectTest {
- GameObject playerTest;
- GameObject npcTest;
- @BeforeEach
- public void initEach() {
- //creates player & npc objects for testing
- //note that velocity and coordinates are initialised to 0 in GameObject.java
- playerTest = GameObject.createPlayer();
- npcTest = GameObject.createNpc();
- }
-
- /**
- * Tests the create methods - createPlayer() and createNPC().
- */
- @Test
- void objectTest(){
- LOGGER.info("objectTest:");
- assertEquals("player",playerTest.getName());
- assertEquals("npc",npcTest.getName());
- }
-
- /**
- * Tests the input component with varying key event inputs.
- * Targets the player game object.
- */
- @Test
- void eventInputTest(){
- LOGGER.info("eventInputTest:");
- playerTest.update(KeyEvent.KEY_LOCATION_LEFT);
- assertEquals(-1, playerTest.getVelocity());
- assertEquals(-1, playerTest.getCoordinate());
-
- playerTest.update(KeyEvent.KEY_LOCATION_RIGHT);
- playerTest.update(KeyEvent.KEY_LOCATION_RIGHT);
- assertEquals(1, playerTest.getVelocity());
- assertEquals(0, playerTest.getCoordinate());
-
- LOGGER.info(Integer.toString(playerTest.getCoordinate()));
- LOGGER.info(Integer.toString(playerTest.getVelocity()));
-
- GameObject p2 = GameObject.createPlayer();
- p2.update(KeyEvent.KEY_LOCATION_LEFT);
- //in the case of an unknown, object stats are set to default
- p2.update(KeyEvent.KEY_LOCATION_UNKNOWN);
- assertEquals(-1, p2.getVelocity());
- }
-
- /**
- * Tests the demo component interface.
- */
- @Test
- void npcDemoTest(){
- LOGGER.info("npcDemoTest:");
- npcTest.demoUpdate();
- assertEquals(2, npcTest.getVelocity());
- assertEquals(2, npcTest.getCoordinate());
- }
-}
diff --git a/component/src/test/java/com/iluwatar/component/TaskListTest.java b/component/src/test/java/com/iluwatar/component/TaskListTest.java
new file mode 100644
index 000000000000..31d225c69873
--- /dev/null
+++ b/component/src/test/java/com/iluwatar/component/TaskListTest.java
@@ -0,0 +1,66 @@
+package com.iluwatar.component;
+import org.junit.jupiter.api.Test;
+import static org.junit.jupiter.api.Assertions.*;
+
+
+public class TaskListTest
+{
+
+ @Test
+ public void testCreateFirstTask()
+ {
+ // Test creating the first task.
+ Task task = new FirstTask("Study for the exam");
+ assertNotNull(task, "Task should not be exit");
+ assertEquals("Study for the exam", task.getTitle(), "Task title should match");
+ }
+
+ @Test
+ public void testSetTaskTitle()
+ {
+ // Test updating the title for the implemented task
+ Task task = new FirstTask("Old Title");
+ task.setTitle("New Title");
+ assertEquals("New Title", task.getTitle(), "Task title should update correctly");
+ }
+
+ @Test
+ public void testAddTaskToTaskList()
+ {
+ // Test adding tasks to a task list
+ TaskList taskList = new TaskList("My Task List");
+ Task task = new FirstTask("Complete homework");
+ taskList.addTask(task);
+
+ assertEquals(1, taskList.getTasks().size(), "Task list should contain one task");
+ assertEquals("Complete homework", taskList.getTasks().get(0).getTitle(), "Task title should match");
+ }
+
+ @Test
+ public void testRemoveTaskFromTaskList()
+ {
+
+ TaskList taskList = new TaskList("My Task List");
+ Task task = new FirstTask("Complete homework");
+ taskList.addTask(task);
+ taskList.removeTask(task);
+
+ assertEquals(0, taskList.getTasks().size(), "Task list should be empty after removing the task");
+ }
+
+ @Test
+ public void testDisplayTaskList()
+ {
+ // Test displaying the task list and tasks
+ TaskList taskList = new TaskList("My Task List");
+ Task task1 = new FirstTask("Complete Task");
+ Task task2 = new FirstTask("Study for the quiz");
+
+ taskList.addTask(task1);
+ taskList.addTask(task2);
+
+ // Test that the tasks are displayed (this doesn't assert, just for practice)
+ System.out.println("Testing display:");
+ taskList.display();
+ }
+}