Skip to content

Commit 65a12e4

Browse files
committed
test: add unit tests for DiskDriveFullException and LoadGame functionality
1 parent 97e489d commit 65a12e4

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

lesson_16/objects/objects_app/src/test/java/XboxTest/XboxTest.java renamed to lesson_16/objects/objects_app/src/test/xboxtest/XboxTest.java

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

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

712
import com.codedifferently.lesson16.dylans_xbox.LoadGame;
813
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;
1314

1415
public class XboxTest {
1516

@@ -49,7 +50,7 @@ public void testXboxModelEnumValues() {
4950
Xbox.XboxModel[] models = Xbox.XboxModel.values();
5051
assertEquals(6, models.length);
5152
assertEquals(
52-
Xbox.XboxModel.XBOX360, models[0]); // Fixed: Corrected the first model to match the enum
53+
Xbox.XboxModel.XBOX360, models[0]);
5354
assertEquals(Xbox.XboxModel.XBOXSERIESX, models[5]);
5455
}
5556

@@ -58,9 +59,9 @@ public void testDiskDrive() {
5859
Xbox xbox =
5960
new Xbox(
6061
"XBOXONE", 400, "White", true,
61-
false); // Fixed: Set diskDrive to `false` to match the test
62+
false);
6263
assertTrue(
63-
xbox.DiskDrive(), "Disk drive should be empty"); // Fixed: Corrected the assertion syntax
64+
xbox.DiskDrive(), "Disk drive should be empty");
6465
}
6566

6667
@Test
@@ -111,11 +112,8 @@ public void testEjectGame() {
111112
fail("Exception occurred while loading games: " + e.getMessage());
112113
}
113114

114-
// Act: Eject a game
115-
// Act: Eject a game
116115
xbox.ejectGame(1);
117116

118-
// Assert: Verify the game was ejected (if needed, check the state of the Xbox object)
119117
assertTrue(
120118
!xbox.getGames().containsKey(1), "Game with ID 1 should be removed from the games list.");
121119
}
@@ -145,4 +143,18 @@ public void testGetPrice() {
145143
int price = xbox.getPrice();
146144
assertEquals(400, price, "The price should be 400.");
147145
}
146+
147+
@Test
148+
public void testGetColor() {
149+
Xbox xbox = new Xbox("XBOX360", 400, "White", true, false);
150+
String color = xbox.getColor();
151+
assertEquals("White", color, "The color should be White.");
152+
}
153+
154+
@Test
155+
public void testDiskDrive() {
156+
Xbox xbox = new Xbox("XBOX360", 400, "White", true, false);
157+
boolean diskDrive = xbox.DiskDrive();
158+
assertTrue(diskDrive, "The disk drive should be present.");
159+
}
148160
}

0 commit comments

Comments
 (0)