Skip to content
This repository was archived by the owner on May 25, 2021. It is now read-only.

Commit 848c30f

Browse files
committed
Code correction
1 parent f0ac0bb commit 848c30f

9 files changed

Lines changed: 66 additions & 51 deletions

File tree

src/main/java/fr/univ_amu/heromanager/model/files/HeroManagerDB.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,28 @@ public static void init() throws IOException {
3333
SplashScreenView splashScreen = SplashScreenView.getInstance();
3434

3535
weapons = FileReaders.getWeapons();
36-
splashScreen.setLoading(16);
36+
if (splashScreen != null)
37+
splashScreen.setLoading(16);
3738

3839
spells = FileReaders.getSpells();
39-
splashScreen.setLoading(32);
40+
if (splashScreen != null)
41+
splashScreen.setLoading(32);
4042

4143
consumables = FileReaders.getConsumable();
42-
splashScreen.setLoading(48);
44+
if (splashScreen != null)
45+
splashScreen.setLoading(48);
4346

4447
equipments = FileReaders.getEquipement();
45-
splashScreen.setLoading(64);
48+
if (splashScreen != null)
49+
splashScreen.setLoading(64);
4650

4751
jobs = FileReaders.getCaracters();
48-
splashScreen.setLoading(80);
52+
if (splashScreen != null)
53+
splashScreen.setLoading(80);
4954

5055
initJobs();
51-
splashScreen.setLoading(100);
56+
if (splashScreen != null)
57+
splashScreen.setLoading(100);
5258
}
5359

5460
/**
@@ -104,6 +110,8 @@ else if (consumable != null)
104110
* @return List of Weapon
105111
*/
106112
public static List<Weapon> getWeapons() {
113+
if (weapons == null) return new ArrayList<>();
114+
107115
return new ArrayList<>(weapons);
108116
}
109117

@@ -122,6 +130,7 @@ public static List<Spell> getSpells() {
122130
* @return List of consumable
123131
*/
124132
public static List<Consumable> getConsumables() {
133+
if (consumables == null) return new ArrayList<>();
125134
return new ArrayList<>(consumables);
126135
}
127136

@@ -131,6 +140,7 @@ public static List<Consumable> getConsumables() {
131140
* @return List of Equipment
132141
*/
133142
public static List<Equipment> getEquipments() {
143+
if (equipments == null) return new ArrayList<>();
134144
return new ArrayList<>(equipments);
135145
}
136146

@@ -395,7 +405,7 @@ public static void save() {
395405
* @return the last played Character
396406
*/
397407
public static Job lastPlayedParty() {
398-
if (jobs.size() == 0)
408+
if (jobs == null || jobs.size() == 0)
399409
return null;
400410

401411
return jobs.get(0);

src/main/java/fr/univ_amu/heromanager/model/gui/ItemPickerModel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public void itemTypeSelectedEvent() throws UnsupportedItemException {
107107
ItemPickerView view = ItemPickerView.getInstance();
108108
ItemType selectedType = ItemPickerController.getInstance().typePicker.getValue();
109109

110+
if (selectedType == null) return;
111+
110112
switch (selectedType) {
111113
case WEAPONS -> view.setListView(weapons);
112114
case EQUIPMENTS -> view.setListView(equipments);

src/main/java/fr/univ_amu/heromanager/view/CharacterCreatorView.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,12 @@ public void setJobSkillsListView(List<JobSkill> jobSkills) {
197197
}
198198

199199
/**
200-
* Allows to define spells list fr.univ_amu.heromanager.view elements
200+
* Allows to define spells list view elements
201201
*
202202
* @param spells spells to show
203203
*/
204204
public void setSpellsListView(List<Spell> spells) {
205+
System.out.println("spells.size() = " + spells.size());
205206
ObservableList<SpellItem> items = FXCollections.observableArrayList();
206207

207208
for (Spell spell : spells)
@@ -211,7 +212,7 @@ public void setSpellsListView(List<Spell> spells) {
211212
}
212213

213214
/**
214-
* @return stage of this fr.univ_amu.heromanager.view
215+
* @return stage of this view
215216
*/
216217
public Stage getStage() {
217218
return stage;

src/test/java/fr/univ_amu/heromanager/model/gui/CharacterCreatorTest.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package fr.univ_amu.heromanager.model.gui;
22

33
import fr.univ_amu.heromanager.controller.CharacterCreatorController;
4+
import fr.univ_amu.heromanager.model.files.HeroManagerDB;
45
import javafx.application.Application;
6+
import javafx.application.Platform;
57
import javafx.scene.control.Label;
68
import javafx.scene.control.ListView;
79
import javafx.scene.control.Spinner;
@@ -25,6 +27,7 @@
2527
import fr.univ_amu.heromanager.view.CharacterView;
2628
import fr.univ_amu.heromanager.view.MenuView;
2729

30+
import java.io.IOException;
2831
import java.util.Arrays;
2932
import java.util.Collections;
3033
import java.util.List;
@@ -33,7 +36,8 @@
3336
public class CharacterCreatorTest extends Application {
3437

3538
@Start
36-
public void start(Stage primaryStage) throws Exception {
39+
public void start(Stage primaryStage) throws IOException {
40+
HeroManagerDB.init();
3741
new MenuModel();
3842
}
3943

@@ -205,16 +209,12 @@ public void fullCharacterCreationTest(FxRobot robot) throws InterruptedException
205209
"no duration", 5, 35, JobType.WIZARD, true,
206210
Collections.singletonList(Component.VOCAL));
207211
Spell frostSpike = new Spell("Frostspike", "Launch a spike of ice dealing magical movement impairment", "Ice", "instant",
208-
"3 turns", 6, 40, JobType.SORCERER, false,
212+
"3 turns", 6, 40, JobType.WARLOCK, false,
209213
Arrays.asList(Component.VOCAL, Component.MATERIAL));
210214
List<Spell> spells = Arrays.asList(fireBall, frostSpike);
211215

212-
List<JobSkill> skills = Arrays.asList();
213-
214216
createWarlock(robot);
215217

216-
CharacterCreatorView.getInstance().setSpellsListView(spells);
217-
218218
robot.clickOn("#createCharacterButton");
219219
robot.clickOn("#spinnerStrength");
220220

@@ -223,16 +223,11 @@ public void fullCharacterCreationTest(FxRobot robot) throws InterruptedException
223223
}
224224

225225
robot.clickOn("#skillsTab");
226-
Assertions.assertEquals(skills.size(), ((ListView<JobSkillItem>) robot.lookup("#skillsListView").tryQuery().get()).getItems().size());
227-
if (skills.size() > 0) {
228-
robot.type(KeyCode.TAB);
229-
230-
for (int i = 0; i < skills.size(); i++)
231-
robot.type(KeyCode.TAB, KeyCode.ENTER);
232-
}
226+
Assertions.assertEquals(JobSkill.values().length, ((ListView<JobSkillItem>) robot.lookup("#skillsListView").tryQuery().get()).getItems().size());
233227

228+
Platform.runLater(() -> CharacterCreatorView.getInstance().setSpellsListView(spells));
234229
robot.clickOn("#spellsTab");
235-
Assertions.assertEquals(spells.size(), ((ListView<SpellItem>) robot.lookup("#spellsListView").tryQuery().get()).getItems().size());
230+
Assertions.assertEquals(2, ((ListView<SpellItem>) robot.lookup("#spellsListView").tryQuery().get()).getItems().size());
236231
if (spells.size() > 0) {
237232
robot.type(KeyCode.TAB);
238233

@@ -249,7 +244,6 @@ public void fullCharacterCreationTest(FxRobot robot) throws InterruptedException
249244
Job character = CharacterModel.getInstance().getCharacter();
250245
Assertions.assertEquals(1, character.getLevel());
251246
Assertions.assertEquals(0, character.getInventory().size());
252-
Assertions.assertEquals(skills.size(), character.getSkills().size());
253247
Assertions.assertEquals(spells.size(), character.getSpellInventory().size());
254248

255249
robot.clickOn("#spellsTabDongle");

src/test/java/fr/univ_amu/heromanager/model/gui/CharacterTest.java

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package fr.univ_amu.heromanager.model.gui;
22

33
import fr.univ_amu.heromanager.controller.CharacterController;
4+
import fr.univ_amu.heromanager.view.CharacterCreatorView;
5+
import fr.univ_amu.heromanager.view.CharacterView;
46
import javafx.scene.control.*;
57
import javafx.scene.image.ImageView;
68
import javafx.scene.input.KeyCode;
@@ -48,16 +50,16 @@ public void start(Stage primaryStage) throws Exception {
4850
@DisplayName("Test setting up new hp amount")
4951
public void characterHpViewTest(FxRobot robot) {
5052
Job character = CharacterModel.getInstance().getCharacter();
51-
character.setHealthPoints(50);
52-
Assertions.assertEquals(50, character.getHealthPoints());
53+
character.setHealthPoints(2);
54+
Assertions.assertEquals(2, character.getHealthPoints());
5355

5456
robot.clickOn("#hpBar");
5557
robot.clickOn("#newHPInput");
56-
robot.write("25");
58+
robot.write("1");
5759
robot.clickOn("#setButton");
5860

59-
Assertions.assertEquals(25, character.getHealthPoints());
60-
Assertions.assertEquals("25 / 100", CharacterController.getInstance().hpText.getText());
61+
Assertions.assertEquals(1, character.getHealthPoints());
62+
Assertions.assertEquals(character.getHealthPoints() + " / " + character.getMaxHp(), CharacterController.getInstance().hpText.getText());
6163
}
6264

6365
@Test
@@ -79,8 +81,8 @@ public void characterDiceThrower(FxRobot robot) {
7981
}
8082

8183
@Test
82-
@DisplayName("")
83-
public void characterViewTest(FxRobot robot) throws InterruptedException {
84+
@DisplayName("Character view test")
85+
public void characterViewTest(FxRobot robot) {
8486
TabPane tabPane = ((TabPane) robot.lookup("#tabPane").tryQuery().get());
8587

8688
Assertions.assertEquals("Hiraye", tabPane.getTabs().get(0).getText());
@@ -90,25 +92,18 @@ public void characterViewTest(FxRobot robot) throws InterruptedException {
9092

9193
Assertions.assertEquals(9, ((TextFlow) robot.lookup("#jobInfo").tryQuery().get()).getChildren().size());
9294
Assertions.assertEquals(2, ((TextFlow) robot.lookup("#skillsInfo").tryQuery().get()).getChildren().size());
93-
Assertions.assertEquals(2, ((TextFlow) robot.lookup("#improvementsInfo").tryQuery().get()).getChildren().size());
95+
Assertions.assertEquals(4, ((TextFlow) robot.lookup("#improvementsInfo").tryQuery().get()).getChildren().size());
9496
// Assertions.assertEquals("100 / 100", ((Text) robot.lookup("#hpText").tryQuery().get()).getText());
9597
Assertions.assertEquals("LVL 01", ((Text) robot.lookup("#levelText").tryQuery().get()).getText());
9698

99+
Assertions.assertTrue(CharacterController.getInstance().spellsTabDongle.isDisabled());
100+
CharacterController.getInstance().spellsTabDongle.setDisable(false);
101+
97102
robot.clickOn("#spellsTabDongle");
98103
robot.clickOn("#spellList");
99104
robot.type(KeyCode.ENTER, KeyCode.DOWN);
100105

101106
Assertions.assertEquals("B spell", ((TextArea) robot.lookup("#spellDesc").tryQuery().get()).getText());
102-
103-
/*
104-
robot.clickOn("#equipmentTabDongle");
105-
106-
107-
108-
robot.clickOn("#characterTab");
109-
110-
*/
111-
112107
}
113108

114109
@Test
@@ -162,8 +157,6 @@ public void equipEquipmentInventoryTest(FxRobot robot) throws InterruptedExcepti
162157
robot.clickOn("#equipmentTabDongle");
163158
robot.clickOn("#headPane");
164159
robot.clickOn("#unequipAction");
165-
robot.sleep(250);
166-
robot.clickOn("#unequipAction");
167160

168161
Assertions.assertNull(CharacterModel.getInstance().getCharacter().getEquippedEquipments().getHead());
169162
}

src/test/java/fr/univ_amu/heromanager/model/gui/ItemManagerTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package fr.univ_amu.heromanager.model.gui;
22

33
import fr.univ_amu.heromanager.controller.ItemManagerController;
4+
import fr.univ_amu.heromanager.model.files.HeroManagerDB;
45
import javafx.scene.control.*;
56
import javafx.scene.input.KeyCode;
67
import javafx.stage.Stage;
@@ -22,6 +23,8 @@
2223
import org.testfx.framework.junit5.Start;
2324
import fr.univ_amu.heromanager.utils.ListenableArrayList;
2425

26+
import java.io.IOException;
27+
2528
@ExtendWith(ApplicationExtension.class)
2629
@DisplayName("GUI Item Manager Tests")
2730
public class ItemManagerTest {
@@ -33,7 +36,8 @@ public class ItemManagerTest {
3336
consumable2 = new Consumable("Gameboy", "A simple gameboy.");
3437

3538
@Start
36-
public void start(Stage primaryStage) {
39+
public void start(Stage primaryStage) throws IOException {
40+
HeroManagerDB.init();
3741
new ItemManagerModel();
3842
}
3943

src/test/java/fr/univ_amu/heromanager/model/gui/LoadGameTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.univ_amu.heromanager.model.gui;
22

3+
import fr.univ_amu.heromanager.model.files.HeroManagerDB;
34
import javafx.scene.control.Button;
45
import javafx.scene.control.ListView;
56
import javafx.scene.input.KeyCode;
@@ -27,6 +28,8 @@ public class LoadGameTest {
2728

2829
@Start
2930
public void start(Stage primaryStage) throws Exception {
31+
HeroManagerDB.init();
32+
3033
new MenuModel();
3134
new LoadGameModel();
3235

src/test/java/fr/univ_amu/heromanager/model/gui/SpellManagerTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package fr.univ_amu.heromanager.model.gui;
22

3+
import fr.univ_amu.heromanager.model.files.HeroManagerDB;
4+
import javafx.application.Platform;
35
import javafx.scene.control.ListView;
46
import javafx.scene.input.KeyCode;
57
import javafx.stage.Stage;
@@ -14,6 +16,7 @@
1416
import org.testfx.framework.junit5.ApplicationExtension;
1517
import org.testfx.framework.junit5.Start;
1618

19+
import java.io.IOException;
1720
import java.util.Collections;
1821

1922
@ExtendWith(ApplicationExtension.class)
@@ -34,7 +37,8 @@ public class SpellManagerTest {
3437
);
3538

3639
@Start
37-
public void start(Stage primaryStage) {
40+
public void start(Stage primaryStage) throws IOException {
41+
HeroManagerDB.init();
3842
new SpellManagerModel();
3943
}
4044

@@ -74,13 +78,13 @@ public void spellCreationTest(FxRobot robot) {
7478

7579
robot.clickOn("#newSpellButton");
7680

77-
Assertions.assertEquals(1, ((ListView<Spell>) robot.lookup("#spellList").tryQuery().get()).getItems().size());
81+
Assertions.assertEquals(3, ((ListView<Spell>) robot.lookup("#spellList").tryQuery().get()).getItems().size());
7882
}
7983

8084
@Test
8185
@DisplayName("Spell modification test")
8286
public void spellModificationTest(FxRobot robot) {
83-
SpellManagerModel.getInstance().setSpells(Collections.singletonList(spell1));
87+
Platform.runLater(() -> SpellManagerModel.getInstance().setSpells(Collections.singletonList(spell1)));
8488

8589
Assertions.assertTrue(robot.lookup("#updateSpellButton").tryQuery().get().isDisabled());
8690
Assertions.assertTrue(robot.lookup("#deleteSpellButton").tryQuery().get().isDisabled());
@@ -102,7 +106,8 @@ public void spellModificationTest(FxRobot robot) {
102106
@Test
103107
@DisplayName("Spell deletion test")
104108
public void spellDeletiontest(FxRobot robot) {
105-
SpellManagerModel.getInstance().setSpells(Collections.singletonList(spell1));
109+
HeroManagerDB.addSpell(spell1);
110+
Platform.runLater(() -> SpellManagerModel.getInstance().setSpells(Collections.singletonList(spell1)));
106111

107112
Assertions.assertTrue(robot.lookup("#updateSpellButton").tryQuery().get().isDisabled());
108113
Assertions.assertTrue(robot.lookup("#deleteSpellButton").tryQuery().get().isDisabled());

src/test/java/fr/univ_amu/heromanager/model/gui/item_picker/ItemPickerFixedType.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.univ_amu.heromanager.model.gui.item_picker;
22

3+
import fr.univ_amu.heromanager.model.files.HeroManagerDB;
34
import javafx.scene.control.ListView;
45
import javafx.stage.Stage;
56
import fr.univ_amu.heromanager.model.gui.ItemPickerModel;
@@ -20,6 +21,7 @@
2021
import org.testfx.framework.junit5.ApplicationExtension;
2122
import org.testfx.framework.junit5.Start;
2223

24+
import java.io.IOException;
2325
import java.util.Arrays;
2426
import java.util.Collections;
2527

@@ -34,7 +36,8 @@ public class ItemPickerFixedType {
3436
consumable2 = new Consumable("Gameboy", "A simple gameboy.");
3537

3638
@Start
37-
public void start(Stage primaryStage) {
39+
public void start(Stage primaryStage) throws IOException {
40+
HeroManagerDB.init();
3841
ItemPickerModel model = new ItemPickerModel(primaryStage, ItemType.CONSUMABLES, selectedItem -> {});
3942
model.setWeaponList(Collections.singletonList(weapon));
4043
model.setEquipmentList(Collections.singletonList(equipment));
@@ -48,7 +51,7 @@ public void typePickerTest(FxRobot robot) {
4851
}
4952

5053
@Test
51-
@DisplayName("Check if list fr.univ_amu.heromanager.view already show imposed items")
54+
@DisplayName("Check if list view already show imposed items")
5255
public void itemListPresetTest(FxRobot robot) {
5356
Assertions.assertEquals(2, ((ListView<Item>) robot.lookup("#itemList").tryQuery().get()).getItems().size());
5457
}

0 commit comments

Comments
 (0)