-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55 from mcgivrer/feature/add-configuration-tests
feat(configTests): Add Configuration tests
- Loading branch information
Showing
12 changed files
with
115 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package features; | ||
|
||
import fr.snapgames.fromclasstogame.core.config.Configuration; | ||
import io.cucumber.java8.En; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
|
||
public class ConfigurationStepdefs implements En { | ||
private Configuration config; | ||
|
||
public ConfigurationStepdefs() { | ||
Given("the Configuration object is initialized with {string}", (String configFilename) -> { | ||
config = new Configuration(configFilename); | ||
}); | ||
Then("the properties are loaded", () -> { | ||
assertNotNull("properties have not been loaded", config.defaultConfig); | ||
}); | ||
And("the default title is {string}", (String title) -> { | ||
assertEquals("the title has not been set to the correct value ", title, config.title); | ||
}); | ||
And("the default game width is {int}", (Integer width) -> { | ||
assertEquals("the default width has not been set to " + width, width, config.width, 0.1); | ||
}); | ||
And("the default game height is {int}", (Integer height) -> { | ||
assertEquals("the default height has not been set to " + height, height, config.height, 0.1); | ||
}); | ||
And("the default game scale is {int}", (Integer scale) -> { | ||
assertEquals("the default scale has not been set to " + scale, scale, config.scale, 0.1); | ||
}); | ||
And("the default screen is {int}", (Integer screenId) -> { | ||
assertEquals("the default scale has not been set to " + screenId, screenId, config.defaultScreen, 0.1); | ||
}); | ||
And("the default world gravity is {double}", (Double gravity) -> { | ||
assertEquals("the default scale has not been set to " + gravity, gravity, config.gravity, 0.1); | ||
}); | ||
And("the scene {string} is {string}", (String name, String className) -> { | ||
String[] scenes = config.scenes.split(","); | ||
Map<String, String> mapScenes = new HashMap<>(); | ||
Arrays.asList(scenes).forEach(s -> { | ||
String[] values = s.split(":"); | ||
mapScenes.put(values[0], values[1]); | ||
}); | ||
|
||
assertTrue("the scene " + name + " has not been set to " + className, mapScenes.containsKey(name) && mapScenes.get(name).equals(className)); | ||
}); | ||
And("the default scene is {string}", (String defaultSceneName) -> { | ||
assertEquals("the default Scene has not been set correctly to " + defaultSceneName, defaultSceneName, config.defaultScene); | ||
}); | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# From a Class To game | ||
# (c) Frédéric Delorme - 2021-08-02 | ||
# No Scene Test configuration file | ||
game.setup.debugLevel=2 | ||
game.setup.title=config-test | ||
game.setup.width=320 | ||
game.setup.height=200 | ||
game.setup.scale=1.0 | ||
game.setup.fps=30 | ||
game.setup.screen=-1 | ||
game.setup.scenes=test1:fr.snapgames.fromclasstogame.test.scenes.TestScene,\ | ||
test2:fr.snapgames.fromclasstogame.test.scenes.TestScene,\ | ||
test3:fr.snapgames.fromclasstogame.test.scenes.TestScene | ||
game.setup.scene.default=test1 | ||
game.setup.world.gravity=0.981 |
17 changes: 17 additions & 0 deletions
17
src/test/resources/features/Configuration_is_loaded_from_file.feature
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,17 @@ | ||
Feature: The configuration is loaded from a properties file | ||
|
||
All the default configuration values are loaded from a java properties file | ||
|
||
Scenario: Load a set of default values | ||
Given the Configuration object is initialized with "config-test" | ||
Then the properties are loaded | ||
And the default title is "config-test" | ||
And the default game width is 320 | ||
And the default game height is 200 | ||
And the default game scale is 1 | ||
And the default screen is -1 | ||
And the default world gravity is 0.981 | ||
And the scene "test1" is "fr.snapgames.fromclasstogame.test.scenes.TestScene" | ||
And the scene "test2" is "fr.snapgames.fromclasstogame.test.scenes.TestScene" | ||
And the scene "test3" is "fr.snapgames.fromclasstogame.test.scenes.TestScene" | ||
And the default scene is "test1" |
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
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
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
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,13 @@ | ||
# From a Class To game | ||
# (c) Frédéric Delorme - 2021-08-02 | ||
# No Scene Test configuration file | ||
game.setup.debugLevel=2 | ||
game.setup.title=window-title-test | ||
game.setup.width=320 | ||
game.setup.height=200 | ||
game.setup.scale=1.0 | ||
game.setup.fps=30 | ||
game.setup.screen=-1 | ||
game.setup.scenes=test1:fr.snapgames.fromclasstogame.test.scenes.TestScene,test2:fr.snapgames.fromclasstogame.test.scenes.TestScene,test3:fr.snapgames.fromclasstogame.test.scenes.TestScene | ||
game.setup.scene.default=test1 | ||
game.setup.world.gravity=0.981 |