Score Anzeige GUI Test
parent
1ad76212f6
commit
64218546e4
|
|
@ -0,0 +1,77 @@
|
||||||
|
import GUI.GameUIController;
|
||||||
|
import GUI.HitoriScorePanel;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.TextArea;
|
||||||
|
import org.junit.jupiter.api.*;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.testfx.framework.junit5.ApplicationExtension;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@ExtendWith(ApplicationExtension.class)
|
||||||
|
class HitoriScorePanelTest {
|
||||||
|
private HitoriScorePanel scorePanel;
|
||||||
|
private GameUIController controller;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
controller = mock(GameUIController.class);
|
||||||
|
scorePanel = new HitoriScorePanel(controller);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testInitialization() {
|
||||||
|
assertNotNull(scorePanel);
|
||||||
|
assertTrue(scorePanel.getChildren().size() > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testUpdateHighScores() {
|
||||||
|
String testScores = "Player1: 100\nPlayer2: 200";
|
||||||
|
scorePanel.updateHighScores(testScores);
|
||||||
|
|
||||||
|
TextArea highScoreArea = findTextArea(scorePanel);
|
||||||
|
assertNotNull(highScoreArea);
|
||||||
|
assertEquals(testScores, highScoreArea.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSaveButtonAction() {
|
||||||
|
var saveButton = findButtonByText(scorePanel, "Save Game");
|
||||||
|
assertNotNull(saveButton);
|
||||||
|
|
||||||
|
saveButton.fire();
|
||||||
|
verify(controller, times(1)).saveGame();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDeleteHighScoresButtonAction() {
|
||||||
|
var deleteButton = findButtonByText(scorePanel, "Delete High Scores");
|
||||||
|
assertNotNull(deleteButton);
|
||||||
|
|
||||||
|
deleteButton.fire();
|
||||||
|
verify(controller, times(1)).deleteHighScores();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testHighScoreAreaNotEditable() {
|
||||||
|
TextArea highScoreArea = findTextArea(scorePanel);
|
||||||
|
assertNotNull(highScoreArea);
|
||||||
|
assertFalse(highScoreArea.isEditable());
|
||||||
|
}
|
||||||
|
|
||||||
|
private TextArea findTextArea(HitoriScorePanel panel) {
|
||||||
|
return (TextArea) panel.getChildren().stream()
|
||||||
|
.filter(node -> node instanceof TextArea)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Button findButtonByText(HitoriScorePanel panel, String text) {
|
||||||
|
return (Button) panel.getChildren().stream()
|
||||||
|
.filter(node -> node instanceof Button && ((Button) node).getText().equals(text))
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue