Skip to content

Commit

Permalink
Merge pull request #55 from mcgivrer/feature/add-configuration-tests
Browse files Browse the repository at this point in the history
feat(configTests): Add Configuration tests
  • Loading branch information
mcgivrer authored Oct 10, 2021
2 parents 2e52092 + 2b01ad3 commit a99e9da
Show file tree
Hide file tree
Showing 12 changed files with 115 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

public class Configuration {

private ResourceBundle defaultConfig;
public ResourceBundle defaultConfig;

public String title = "fromClassToGame";

public int defaultScreen;
public int width = 320;
public int height = 200;
public double scale = 1.0;
Expand All @@ -33,10 +34,12 @@ public Configuration(String configurationPath) {
public void readValuesFromFile() {

this.debugLevel = Integer.parseInt(defaultConfig.getString("game.setup.debugLevel"));
this.defaultScreen = Integer.parseInt(defaultConfig.getString("game.setup.screen"));
this.width = Integer.parseInt(defaultConfig.getString("game.setup.width"));
this.height = Integer.parseInt(defaultConfig.getString("game.setup.height"));
this.scale = Double.parseDouble(defaultConfig.getString("game.setup.scale"));
this.FPS = Double.parseDouble(defaultConfig.getString("game.setup.fps"));

this.title = defaultConfig.getString("game.setup.title");
this.scenes = defaultConfig.getString("game.setup.scenes");
this.defaultScene = defaultConfig.getString("game.setup.scene.default");
Expand Down Expand Up @@ -69,6 +72,9 @@ public Configuration parseArgs(String[] argv) throws UnknownArgumentException {
case "scene":
this.defaultScene = values[1];
break;
case "screen":
this.defaultScreen = Integer.parseInt(values[1]);
break;
default:
throw new UnknownArgumentException(String.format("The argument %s is unknown", arg));
}
Expand Down
56 changes: 56 additions & 0 deletions src/test/java/features/ConfigurationStepdefs.java
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);
});

}
}
1 change: 1 addition & 0 deletions src/test/resources/camera-1-scene.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ game.setup.width=320
game.setup.height=200
game.setup.scale=1.0
game.setup.fps=30
game.setup.screen=-1
game.setup.scenes=testCamera:fr.snapgames.fromclasstogame.test.scenes.TestCameraScene
game.setup.scene.default=testCamera
game.setup.world.gravity=0.981
15 changes: 15 additions & 0 deletions src/test/resources/config-test.properties
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
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"
1 change: 1 addition & 0 deletions src/test/resources/no-scene.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ game.setup.width=320
game.setup.height=200
game.setup.scale=1.0
game.setup.fps=30
game.setup.screen=-1
game.setup.scenes=
game.setup.scene.default=
game.setup.world.gravity=0.981
1 change: 1 addition & 0 deletions src/test/resources/test-game-args.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ game.setup.width=320
game.setup.height=200
game.setup.scale=1.0
game.setup.fps=30
game.setup.screen=-1
game.setup.scenes=test:fr.snapgames.fromclasstogame.test.scenes.TestScene
game.setup.scene.default=test
game.setup.world.gravity=0.981
1 change: 1 addition & 0 deletions src/test/resources/test-pe.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ game.setup.width=320
game.setup.height=200
game.setup.scale=1.0
game.setup.fps=30
game.setup.screen=-1
game.setup.scenes=test:fr.snapgames.fromclasstogame.test.scenes.TestScene
game.setup.scene.default=test
game.setup.world.gravity=0.981
1 change: 1 addition & 0 deletions src/test/resources/test-render.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ game.setup.width=320
game.setup.height=200
game.setup.scale=1.0
game.setup.fps=30
game.setup.screen=-1
game.setup.scenes=testrender:fr.snapgames.fromclasstogame.test.scenes.TestRenderScene
game.setup.scene.default=testrender
game.setup.world.gravity=0.981
1 change: 1 addition & 0 deletions src/test/resources/test-scene.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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=test3
game.setup.world.gravity=0.981
1 change: 1 addition & 0 deletions src/test/resources/test-sm.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ game.setup.width=320
game.setup.height=200
game.setup.scale=1.0
game.setup.fps=30
game.setup.screen=-1
game.setup.scenes=
game.setup.scene.default=
game.setup.world.gravity=0.981
13 changes: 13 additions & 0 deletions src/test/resources/win-test.properties
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

0 comments on commit a99e9da

Please sign in to comment.