Control Panel GUI Test #8
|
|
@ -0,0 +1,126 @@
|
|||
import GUI.GameUIController;
|
||||
import GUI.HitoriControlPanel;
|
||||
import javafx.scene.control.Button;
|
||||
import javafx.scene.control.Label;
|
||||
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 HitoriControlPanelTest {
|
||||
private HitoriControlPanel controlPanel;
|
||||
private GameUIController controller;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
controller = mock(GameUIController.class);
|
||||
controlPanel = new HitoriControlPanel(controller);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInitialization() {
|
||||
assertNotNull(controlPanel);
|
||||
assertTrue(controlPanel.getChildren().size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateTimerLabel() {
|
||||
controlPanel.updateTimerLabel(42);
|
||||
var timerLabel = findLabelByText(controlPanel, "Time: 42s");
|
||||
assertNotNull(timerLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateMistakeLabel() {
|
||||
controlPanel.updateMistakeLabel(5);
|
||||
var mistakeLabel = findLabelByText(controlPanel, "Mistakes: 5");
|
||||
assertNotNull(mistakeLabel);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSetPauseButtonText() {
|
||||
controlPanel.setPauseButtonText("Test");
|
||||
var pauseButton = findButtonByText(controlPanel, "Test");
|
||||
assertNotNull(pauseButton);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPauseButtonAction() {
|
||||
var pauseButton = findButtonByText(controlPanel, "Pause");
|
||||
assertNotNull(pauseButton);
|
||||
|
||||
pauseButton.fire();
|
||||
verify(controller, times(1)).togglePause();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testResetButtonAction() {
|
||||
var resetButton = findButtonByText(controlPanel, "Reset");
|
||||
assertNotNull(resetButton);
|
||||
|
||||
resetButton.fire();
|
||||
verify(controller, times(1)).resetGame();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUndoButtonAction() {
|
||||
var undoButton = findButtonByText(controlPanel, "Undo");
|
||||
assertNotNull(undoButton);
|
||||
|
||||
undoButton.fire();
|
||||
verify(controller, times(1)).undo();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRedoButtonAction() {
|
||||
var redoButton = findButtonByText(controlPanel, "Redo");
|
||||
assertNotNull(redoButton);
|
||||
|
||||
redoButton.fire();
|
||||
verify(controller, times(1)).redo();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCheckSolutionButtonAction() {
|
||||
var checkButton = findButtonByText(controlPanel, "Check Solution");
|
||||
assertNotNull(checkButton);
|
||||
|
||||
checkButton.fire();
|
||||
verify(controller, times(1)).checkSolution();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNewGameButtonAction() {
|
||||
var newGameButton = findButtonByText(controlPanel, "New Game");
|
||||
assertNotNull(newGameButton);
|
||||
|
||||
newGameButton.fire();
|
||||
verify(controller, times(1)).newGame();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testShowErrorsButtonAction() {
|
||||
var showErrorsButton = findButtonByText(controlPanel, "Show Errors");
|
||||
assertNotNull(showErrorsButton);
|
||||
|
||||
showErrorsButton.fire();
|
||||
verify(controller, times(1)).showErrors();
|
||||
}
|
||||
|
||||
private Label findLabelByText(HitoriControlPanel panel, String text) {
|
||||
return (Label) panel.getChildren().stream()
|
||||
.filter(node -> node instanceof Label && ((Label) node).getText().equals(text))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private Button findButtonByText(HitoriControlPanel panel, String text) {
|
||||
return (Button) panel.getChildren().stream()
|
||||
.flatMap(node -> node.lookupAll("Button").stream())
|
||||
.filter(node -> node instanceof Button && ((Button) node).getText().equals(text))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue