Compare commits
2 Commits
ed886565fb
...
4284c262e2
Author | SHA1 | Date |
---|---|---|
|
4284c262e2 | |
|
2bb0a5bbef |
|
@ -0,0 +1,5 @@
|
||||||
|
package GUI;
|
||||||
|
|
||||||
|
public class BoardLoaderTest {
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package GUI;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.GUI.HighscoreDialog;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class HighscoreDialogTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHighscoreDialogInitialization() {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
JFrame parentFrame = new JFrame();
|
||||||
|
List<String> boardNames = List.of("leicht_8x8.csv", "medium_10x10.csv");
|
||||||
|
HighscoreDialog dialog = new HighscoreDialog(parentFrame, boardNames);
|
||||||
|
|
||||||
|
assertNotNull(dialog, "Der HighscoreDialog sollte erfolgreich erstellt werden.");
|
||||||
|
assertEquals("Highscoreliste", dialog.getTitle(), "Der Titel des Dialogs sollte korrekt sein.");
|
||||||
|
assertEquals(600, dialog.getWidth(), "Die Breite des Dialogs sollte 600 Pixel betragen.");
|
||||||
|
assertEquals(400, dialog.getHeight(), "Die Höhe des Dialogs sollte 400 Pixel betragen.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLoadHighscoresForBoard() {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
JFrame parentFrame = new JFrame();
|
||||||
|
List<String> boardNames = List.of("leicht_8x8.csv", "medium_10x10.csv");
|
||||||
|
HighscoreDialog dialog = new HighscoreDialog(parentFrame, boardNames);
|
||||||
|
|
||||||
|
JComboBox<?> comboBox = (JComboBox<?>) dialog.getContentPane().getComponent(1); // ComboBox ist das 2. Element
|
||||||
|
assertNotNull(comboBox, "Die Spielfeld-Auswahl sollte existieren.");
|
||||||
|
assertEquals(2, comboBox.getItemCount(), "Die ComboBox sollte zwei Einträge enthalten.");
|
||||||
|
|
||||||
|
JTable table = (JTable) ((JScrollPane) dialog.getContentPane().getComponent(2)).getViewport().getView();
|
||||||
|
assertNotNull(table, "Die Tabelle für Highscores sollte existieren.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
package GUI;
|
||||||
|
|
||||||
|
import PR2.HitoriSpiel.GUI.PauseMenu;
|
||||||
|
import PR2.HitoriSpiel.Fassade.GameBoard;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class PauseMenuTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPauseMenuInitialization() {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
JFrame parentFrame = new JFrame();
|
||||||
|
GameBoard gameBoard = new GameBoard(null); // GameBoard-Mock
|
||||||
|
ActionListener resumeAction = e -> System.out.println("Resume Action Triggered");
|
||||||
|
ActionListener mainMenuAction = e -> System.out.println("Main Menu Action Triggered");
|
||||||
|
ActionListener exitAction = e -> System.out.println("Exit Action Triggered");
|
||||||
|
|
||||||
|
PauseMenu pauseMenu = new PauseMenu(parentFrame, gameBoard, resumeAction, mainMenuAction, exitAction);
|
||||||
|
assertNotNull(pauseMenu, "Das PauseMenu sollte erfolgreich erstellt werden.");
|
||||||
|
assertEquals("Pause", pauseMenu.getTitle(), "Der Titel des Dialogs sollte 'Pause' sein.");
|
||||||
|
assertEquals(300, pauseMenu.getWidth(), "Die Breite des Dialogs sollte 300 Pixel betragen.");
|
||||||
|
assertEquals(200, pauseMenu.getHeight(), "Die Höhe des Dialogs sollte 200 Pixel betragen.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testPauseMenuButtonActions() {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
JFrame parentFrame = new JFrame();
|
||||||
|
GameBoard gameBoard = new GameBoard(null); // GameBoard-Mock
|
||||||
|
boolean[] actionTriggered = {false, false, false};
|
||||||
|
|
||||||
|
ActionListener resumeAction = e -> actionTriggered[0] = true;
|
||||||
|
ActionListener mainMenuAction = e -> actionTriggered[1] = true;
|
||||||
|
ActionListener exitAction = e -> actionTriggered[2] = true;
|
||||||
|
|
||||||
|
PauseMenu pauseMenu = new PauseMenu(parentFrame, gameBoard, resumeAction, mainMenuAction, exitAction);
|
||||||
|
|
||||||
|
// Teste Buttons
|
||||||
|
JButton resumeButton = (JButton) pauseMenu.getContentPane().getComponent(0);
|
||||||
|
JButton mainMenuButton = (JButton) pauseMenu.getContentPane().getComponent(1);
|
||||||
|
JButton exitButton = (JButton) pauseMenu.getContentPane().getComponent(2);
|
||||||
|
|
||||||
|
resumeButton.doClick();
|
||||||
|
assertTrue(actionTriggered[0], "Resume-Action sollte ausgelöst werden.");
|
||||||
|
|
||||||
|
mainMenuButton.doClick();
|
||||||
|
assertTrue(actionTriggered[1], "MainMenu-Action sollte ausgelöst werden.");
|
||||||
|
|
||||||
|
exitButton.doClick();
|
||||||
|
assertTrue(actionTriggered[2], "Exit-Action sollte ausgelöst werden.");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,53 +1,46 @@
|
||||||
package GUI;
|
package GUI;
|
||||||
|
|
||||||
import PR2.HitoriSpiel.GUI.StartMenu;
|
import PR2.HitoriSpiel.GUI.StartMenu;
|
||||||
import org.assertj.swing.edt.GuiActionRunner;
|
|
||||||
import org.assertj.swing.fixture.FrameFixture;
|
|
||||||
import org.junit.jupiter.api.AfterEach;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
public class StartMenuTest {
|
public class StartMenuTest {
|
||||||
|
|
||||||
private FrameFixture window;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
public void setUp() {
|
|
||||||
JFrame frame = GuiActionRunner.execute(() -> {
|
|
||||||
JFrame testFrame = new JFrame();
|
|
||||||
testFrame.add(new StartMenu(testFrame));
|
|
||||||
testFrame.pack();
|
|
||||||
testFrame.setVisible(true);
|
|
||||||
return testFrame;
|
|
||||||
});
|
|
||||||
window = new FrameFixture(frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterEach
|
|
||||||
public void tearDown() {
|
|
||||||
window.cleanUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testButtonsExist() {
|
public void testStartMenuInitialization() {
|
||||||
// Buttons über ihre Namen finden und testen
|
SwingUtilities.invokeLater(() -> {
|
||||||
assertThat(window.button("Spiel fortsetzen")).isNotNull();
|
JFrame parentFrame = new JFrame();
|
||||||
assertThat(window.button("Spielfeld aussuchen")).isNotNull();
|
StartMenu startMenu = new StartMenu(parentFrame);
|
||||||
assertThat(window.button("Zufälliges Spielfeld")).isNotNull();
|
|
||||||
assertThat(window.button("Highscoreliste anschauen")).isNotNull();
|
assertNotNull(startMenu, "Das StartMenu sollte erfolgreich erstellt werden.");
|
||||||
assertThat(window.button("Spiel beenden")).isNotNull();
|
assertEquals(5, startMenu.getComponentCount(), "Das StartMenu sollte fünf Buttons enthalten.");
|
||||||
|
|
||||||
|
// Überprüfe Buttons
|
||||||
|
JButton continueButton = (JButton) startMenu.getComponent(1);
|
||||||
|
assertEquals("Spiel fortsetzen", continueButton.getText(), "Der Text des ersten Buttons sollte korrekt sein.");
|
||||||
|
|
||||||
|
JButton selectBoardButton = (JButton) startMenu.getComponent(2);
|
||||||
|
assertEquals("Spielfeld aussuchen", selectBoardButton.getText(), "Der Text des zweiten Buttons sollte korrekt sein.");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testButtonActions() {
|
public void testButtonActions() {
|
||||||
window.button("Spiel fortsetzen").click();
|
SwingUtilities.invokeLater(() -> {
|
||||||
window.button("Spielfeld aussuchen").click();
|
JFrame parentFrame = new JFrame();
|
||||||
window.button("Zufälliges Spielfeld").click();
|
StartMenu startMenu = new StartMenu(parentFrame);
|
||||||
window.button("Highscoreliste anschauen").click();
|
|
||||||
window.button("Spiel beenden").click();
|
// Simuliere Button-Klicks
|
||||||
|
JButton continueButton = (JButton) startMenu.getComponent(1);
|
||||||
|
continueButton.doClick();
|
||||||
|
|
||||||
|
JButton exitButton = (JButton) startMenu.getComponent(4);
|
||||||
|
exitButton.doClick();
|
||||||
|
|
||||||
|
// Die tatsächliche Logik muss separat getestet werden (z. B. via Mocking).
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
- [x] Verwendung von Maven
|
- [x] Verwendung von Maven
|
||||||
- [x] Verwendung von Git
|
- [x] Verwendung von Git
|
||||||
- [x] Verwendung von Feature-Branches
|
- [x] Verwendung von Feature-Branches
|
||||||
- [ ] Erstellung Unit-Tests mit JUnit
|
- [x] Erstellung Unit-Tests mit JUnit
|
||||||
|
|
||||||
## Die Aufgabenstellung:
|
## Die Aufgabenstellung:
|
||||||
- [x] GUI: GUI, in der beliebige Spielfelder angezeigt und bespielt werden können.
|
- [x] GUI: GUI, in der beliebige Spielfelder angezeigt und bespielt werden können.
|
||||||
|
|
Loading…
Reference in New Issue