-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#3) added testing for SceneManager, SimpleManager, Scene
- Loading branch information
1 parent
bf5a9f6
commit 07e8457
Showing
14 changed files
with
356 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...test/java/unittest/mock/MockBehavior.java → .../mock/systems/behaviors/MockBehavior.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/test/java/unittest/mock/systems/control/MockEmptyScene.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package unittest.mock.systems.control; | ||
|
||
import io.github.lucasstarsz.fastj.graphics.Display; | ||
|
||
import io.github.lucasstarsz.fastj.systems.control.Scene; | ||
|
||
import java.util.UUID; | ||
|
||
public class MockEmptyScene extends Scene { | ||
|
||
public MockEmptyScene() { | ||
super(UUID.randomUUID().toString()); | ||
} | ||
|
||
@Override | ||
public void load(Display display) { | ||
} | ||
|
||
@Override | ||
public void unload(Display display) { | ||
} | ||
|
||
@Override | ||
public void update(Display display) { | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/java/unittest/mock/systems/control/MockEmptySimpleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package unittest.mock.systems.control; | ||
|
||
import io.github.lucasstarsz.fastj.graphics.Display; | ||
|
||
import io.github.lucasstarsz.fastj.systems.control.SimpleManager; | ||
|
||
public class MockEmptySimpleManager extends SimpleManager { | ||
@Override | ||
public void init(Display display) { | ||
} | ||
|
||
@Override | ||
public void update(Display display) { | ||
} | ||
} |
8 changes: 4 additions & 4 deletions
8
src/test/java/unittest/mock/MockScene.java → ...systems/control/MockNameSettingScene.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
src/test/java/unittest/mock/MockManager.java → ...ms/control/MockRunnableSimpleManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/test/java/unittest/mock/systems/control/MockSceneManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package unittest.mock.systems.control; | ||
|
||
import io.github.lucasstarsz.fastj.graphics.Display; | ||
|
||
import io.github.lucasstarsz.fastj.systems.control.SceneManager; | ||
|
||
public class MockSceneManager extends SceneManager { | ||
@Override | ||
public void init(Display display) { | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/unittest/mock/systems/control/MockUpdatableScene.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package unittest.mock.systems.control; | ||
|
||
import io.github.lucasstarsz.fastj.graphics.Display; | ||
|
||
import io.github.lucasstarsz.fastj.systems.control.Scene; | ||
|
||
import java.util.UUID; | ||
|
||
public abstract class MockUpdatableScene extends Scene { | ||
|
||
public MockUpdatableScene() { | ||
super(UUID.randomUUID().toString()); | ||
} | ||
|
||
@Override | ||
public void load(Display display) { | ||
|
||
} | ||
|
||
@Override | ||
public void unload(Display display) { | ||
|
||
} | ||
|
||
@Override | ||
public abstract void update(Display display); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/java/unittest/mock/systems/tags/MockTaggableEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package unittest.mock.systems.tags; | ||
|
||
import io.github.lucasstarsz.fastj.graphics.Drawable; | ||
|
||
import io.github.lucasstarsz.fastj.systems.control.Scene; | ||
|
||
public class MockTaggableEntity extends Drawable { | ||
@Override | ||
public void destroy(Scene originScene) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/test/java/unittest/testcases/systems/control/SceneManagerTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package unittest.testcases.systems.control; | ||
|
||
import io.github.lucasstarsz.fastj.systems.control.Scene; | ||
import io.github.lucasstarsz.fastj.systems.control.SceneManager; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import unittest.mock.systems.control.MockNameSettingScene; | ||
import unittest.mock.systems.control.MockEmptyScene; | ||
import unittest.mock.systems.control.MockSceneManager; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class SceneManagerTests { | ||
|
||
@Test | ||
void checkSceneManagerCreation() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
assertEquals(0, sceneManager.getScenes().size(), "After creating the manager, it should not contain any scenes."); | ||
assertNull(sceneManager.getCurrentScene(), "After creating the manager, the current scene should not yet have been set."); | ||
assertFalse(sceneManager.isSwitchingScenes(), "After creating the manager, it should not be switching scenes."); | ||
} | ||
|
||
@Test | ||
void checkSceneManagerSceneAdding() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
Scene scene = new MockEmptyScene(); | ||
sceneManager.addScene(scene); | ||
|
||
assertEquals(1, sceneManager.getScenes().size(), "After adding a scene to the manager, it should contain one scene."); | ||
} | ||
|
||
@Test | ||
void trySceneManagerSceneAdding_withNameThatAlreadyExists() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
String sceneName = "having two scenes with the same name should throw an exception"; | ||
Scene nameSettingScene1 = new MockNameSettingScene(sceneName); | ||
Scene nameSettingScene2 = new MockNameSettingScene(sceneName); | ||
|
||
sceneManager.addScene(nameSettingScene1); | ||
|
||
Throwable exception = assertThrows(IllegalStateException.class, () -> sceneManager.addScene(nameSettingScene2)); | ||
|
||
String expectedExceptionMessage = "The scene name \"" + sceneName + "\" is already in use." | ||
+ System.lineSeparator() | ||
+ "Scenes added: [" + sceneName + "]"; | ||
assertEquals(expectedExceptionMessage, exception.getCause().getMessage(), "The exception message should match the expected exception message."); | ||
} | ||
|
||
@Test | ||
void checkSceneManagerSceneGetting_bySceneName() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
Scene scene = new MockEmptyScene(); | ||
sceneManager.addScene(scene); | ||
|
||
assertEquals(scene, sceneManager.getScene(scene.getSceneName()), "After adding a scene to the manager, getting that scene by its name should return the original scene."); | ||
} | ||
|
||
@Test | ||
void trySceneManagerGetScene_withSceneNameThatDoesNotExist() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
String sceneName = "trying to get a scene with a scene name that doesn't exist should throw an exception"; | ||
Throwable exception = assertThrows(IllegalStateException.class, () -> sceneManager.getScene(sceneName)); | ||
|
||
String expectedExceptionMessage = "A scene with the name: \"" + sceneName + "\" hasn't been added!"; | ||
assertEquals(expectedExceptionMessage, exception.getCause().getMessage(), "The exception message should match the expected exception message."); | ||
} | ||
|
||
@Test | ||
void checkSceneManagerSceneRemoving_bySceneObject() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
Scene scene = new MockEmptyScene(); | ||
sceneManager.addScene(scene); | ||
sceneManager.removeScene(scene); | ||
|
||
assertEquals(0, sceneManager.getScenes().size(), "After removing the scene from the manager, it should not contain any scenes."); | ||
} | ||
|
||
@Test | ||
void checkSceneManagerSceneRemoving_bySceneName() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
Scene scene = new MockEmptyScene(); | ||
sceneManager.addScene(scene); | ||
sceneManager.removeScene(scene.getSceneName()); | ||
|
||
assertEquals(0, sceneManager.getScenes().size(), "After removing the scene from the manager, it should not contain any scenes."); | ||
} | ||
|
||
@Test | ||
void trySceneManagerSceneRemoving_bySceneName_withSceneNameThatDoesNotExist() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
String sceneName = "trying to remove a scene with a scene name that doesn't exist should throw an exception"; | ||
Throwable exception = assertThrows(IllegalStateException.class, () -> sceneManager.removeScene(sceneName)); | ||
|
||
String expectedExceptionMessage = "A scene with the name: \"" + sceneName + "\" hasn't been added!"; | ||
assertEquals(expectedExceptionMessage, exception.getCause().getMessage(), "The exception message should match the expected exception message."); | ||
} | ||
|
||
@Test | ||
void checkSceneManagerCurrentSceneSetting_bySceneObject() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
Scene scene = new MockEmptyScene(); | ||
sceneManager.addScene(scene); | ||
sceneManager.setCurrentScene(scene); | ||
|
||
assertEquals(scene, sceneManager.getCurrentScene(), "After setting the manager's current scene, getting the current scene should return the same scene."); | ||
} | ||
|
||
@Test | ||
void checkSceneManagerCurrentSceneSetting_bySceneName() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
Scene scene = new MockEmptyScene(); | ||
sceneManager.addScene(scene); | ||
sceneManager.setCurrentScene(scene.getSceneName()); | ||
|
||
assertEquals(scene, sceneManager.getCurrentScene(), "After setting the manager's current scene, getting the current scene should return the same scene."); | ||
} | ||
|
||
@Test | ||
void trySceneManagerSetCurrentScene_bySceneName_withSceneNameThatDoesNotExist() { | ||
SceneManager sceneManager = new MockSceneManager(); | ||
|
||
String sceneName = "trying to set the current scene with a scene name that doesn't exist should throw an exception"; | ||
Throwable exception = assertThrows(IllegalStateException.class, () -> sceneManager.setCurrentScene(sceneName)); | ||
|
||
String expectedExceptionMessage = "A scene with the name: \"" + sceneName + "\" hasn't been added!"; | ||
assertEquals(expectedExceptionMessage, exception.getCause().getMessage(), "The exception message should match the expected exception message."); | ||
} | ||
} |
Oops, something went wrong.