Skip to content

Commit 97e489d

Browse files
committed
feat: add games.csv file into a data folder and update Test Files to be able to find filepath.
1 parent 4549442 commit 97e489d

File tree

5 files changed

+46
-47
lines changed

5 files changed

+46
-47
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Lesson16.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ public static void main(String[] args) {
1212
var application = new SpringApplication(Lesson16.class);
1313
application.run(args);
1414
}
15-
1615
}

lesson_16/objects/objects_app/src/test/java/XboxTest/DiskdrivefullTest.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.fail;
5-
import org.junit.jupiter.api.Test;
65

76
import com.codedifferently.lesson16.dylans_xbox.DiskDriveFullException;
87
import com.codedifferently.lesson16.dylans_xbox.Xbox;
8+
import org.junit.jupiter.api.Test;
99

1010
public class DiskdrivefullTest {
11-
@Test
12-
public void testDiskDriveFullException() throws Exception {
13-
// Create an instance of Xbox with diskDriveFull set to true
14-
Xbox xbox = new Xbox("XBOXSERIESX", 600, "Black", true, true);
15-
16-
try {
17-
xbox.inputGame(1, "Call of Duty");
18-
fail("Expected DiskDriveFullException to be thrown.");
19-
} catch (DiskDriveFullException e) {
20-
assertEquals("Disk drive is full. Cannot insert game.", e.getMessage());
21-
}
11+
@Test
12+
public void testDiskDriveFullException() throws Exception {
13+
// Create an instance of Xbox with diskDriveFull set to true
14+
Xbox xbox = new Xbox("XBOXSERIESX", 600, "Black", true, true);
15+
16+
try {
17+
xbox.inputGame(1, "Call of Duty");
18+
fail("Expected DiskDriveFullException to be thrown.");
19+
} catch (DiskDriveFullException e) {
20+
assertEquals("Disk drive is full. Cannot insert game.", e.getMessage());
2221
}
22+
}
2323
}
Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
package XboxTest;
22

3-
import java.util.HashMap;
4-
53
import static org.junit.jupiter.api.Assertions.assertEquals;
64
import static org.junit.jupiter.api.Assertions.assertTrue;
75
import static org.junit.jupiter.api.Assertions.fail;
8-
import org.junit.jupiter.api.Test;
96

107
import com.codedifferently.lesson16.dylans_xbox.LoadGame;
118
import com.codedifferently.lesson16.dylans_xbox.Xbox;
9+
import java.util.HashMap;
10+
import org.junit.jupiter.api.Test;
1211

1312
public class LoadgameTest {
14-
@Test
15-
public void testLoadGame() {
16-
// Create an instance of Xbox
17-
Xbox xbox = new Xbox("XBOXSERIESX", 600, "Black", true, false);
18-
19-
// Create an instance of LoadGame
20-
LoadGame loader = new LoadGame("src/main/java/com/codedifferently/lesson16/dylans_xbox/games.csv");
21-
22-
// Load games from the file
23-
try {
24-
loader.loadGamesFromFile(xbox);
25-
} catch (Exception e) {
26-
e.printStackTrace();
27-
fail("Exception occurred while loading games: " + e.getMessage());
28-
}
29-
30-
// Check if the game was loaded correctly
31-
HashMap<Integer, String> games = xbox.getGames();
32-
assertTrue(games.containsKey(1)); // Check that the first game is loaded (ID 1)
33-
assertEquals("Call of Duty", games.get(1)); // Ensure the first game matches the CSV
13+
@Test
14+
public void testLoadGame() {
15+
// Create an instance of Xbox
16+
Xbox xbox = new Xbox("XBOXSERIESX", 600, "Black", true, false);
17+
18+
// Create an instance of LoadGame
19+
LoadGame loader =
20+
new LoadGame("src/main/java/com/codedifferently/lesson16/dylans_xbox/data/games.csv");
21+
22+
// Load games from the file
23+
try {
24+
loader.loadGamesFromFile(xbox);
25+
} catch (Exception e) {
26+
e.printStackTrace();
27+
fail("Exception occurred while loading games: " + e.getMessage());
3428
}
29+
30+
// Check if the game was loaded correctly
31+
HashMap<Integer, String> games = xbox.getGames();
32+
assertTrue(games.containsKey(1)); // Check that the first game is loaded (ID 1)
33+
assertEquals("Call of Duty", games.get(1)); // Ensure the first game matches the CSV
34+
}
3535
}

lesson_16/objects/objects_app/src/test/java/XboxTest/XboxTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
package XboxTest;
22

3-
import java.io.ByteArrayOutputStream; // Ensure LoadGame is imported
4-
import java.io.PrintStream;
5-
import java.util.HashMap;
6-
73
import static org.junit.jupiter.api.Assertions.assertEquals;
84
import static org.junit.jupiter.api.Assertions.assertTrue;
9-
import static org.junit.jupiter.api.Assertions.fail;
10-
import org.junit.jupiter.api.Test;
5+
import static org.junit.jupiter.api.Assertions.fail; // Ensure LoadGame is imported
116

127
import com.codedifferently.lesson16.dylans_xbox.LoadGame;
138
import com.codedifferently.lesson16.dylans_xbox.Xbox;
9+
import java.io.ByteArrayOutputStream;
10+
import java.io.PrintStream;
11+
import java.util.HashMap;
12+
import org.junit.jupiter.api.Test;
1413

1514
public class XboxTest {
1615

1716
@Test
1817
public void testAddGame() {
1918
LoadGame loader =
2019
new LoadGame(
21-
"src/main/java/com/codedifferently/lesson16/dylans_xbox/games.csv"); // Ensure LoadGame
20+
"src/main/java/com/codedifferently/lesson16/dylans_xbox/data/games.csv"); // Ensure
21+
// LoadGame
2222

2323
Xbox xbox = new Xbox("XBOXSERIESX", 600, "Black", true, false); // Create an instance of Xbox
2424
try {
@@ -67,7 +67,7 @@ public void testDiskDrive() {
6767
public void testPrintAllGames() {
6868
Xbox xbox = new Xbox("XBOXSERIESX", 600, "Black", true, false);
6969
LoadGame loader =
70-
new LoadGame("src/main/java/com/codedifferently/lesson16/dylans_xbox/games.csv");
70+
new LoadGame("src/main/java/com/codedifferently/lesson16/dylans_xbox/data/games.csv");
7171
try {
7272
loader.loadGamesFromFile(xbox);
7373
} catch (Exception e) {
@@ -103,7 +103,7 @@ public void testPrintAllGames() {
103103
public void testEjectGame() {
104104
Xbox xbox = new Xbox("XBOXSERIESX", 600, "Black", true, false);
105105
LoadGame loader =
106-
new LoadGame("src/main/java/com/codedifferently/lesson16/dylans_xbox/games.csv");
106+
new LoadGame("src/main/java/com/codedifferently/lesson16/dylans_xbox/data/games.csv");
107107
try {
108108
loader.loadGamesFromFile(xbox);
109109
} catch (Exception e) {
@@ -125,7 +125,7 @@ public void testGetGames() {
125125

126126
Xbox xbox = new Xbox("XBOXSERIESX", 600, "Black", true, false);
127127
LoadGame loader =
128-
new LoadGame("src/main/java/com/codedifferently/lesson16/dylans_xbox/games.csv");
128+
new LoadGame("src/main/java/com/codedifferently/lesson16/dylans_xbox/data/games.csv");
129129

130130
try {
131131
loader.loadGamesFromFile(xbox);
@@ -139,7 +139,7 @@ public void testGetGames() {
139139
assertEquals(10, games.size(), "There should be 10 games loaded.");
140140
}
141141

142-
@Test
142+
@Test
143143
public void testGetPrice() {
144144
Xbox xbox = new Xbox("XBOX360", 400, "White", true, false);
145145
int price = xbox.getPrice();

0 commit comments

Comments
 (0)