Setze Namen für Buttons in StartMenu und passe Tests entsprechend an
parent
cd94bc7db0
commit
1244cb333d
|
@ -14,4 +14,25 @@
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
<dependencies>
|
||||||
|
<!-- AssertJ Swing Test-Framework -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-swing</artifactId>
|
||||||
|
<version>3.17.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.13.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<version>5.8.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
|
|
|
@ -13,21 +13,28 @@ public class StartMenu extends JPanel {
|
||||||
JButton continueButton = createButton("Spiel fortsetzen", 200, 30);
|
JButton continueButton = createButton("Spiel fortsetzen", 200, 30);
|
||||||
JButton selectBoardButton = createButton("Spielfeld aussuchen", 200, 30);
|
JButton selectBoardButton = createButton("Spielfeld aussuchen", 200, 30);
|
||||||
JButton randomBoardButton = createButton("Zufälliges Spielfeld", 200, 30);
|
JButton randomBoardButton = createButton("Zufälliges Spielfeld", 200, 30);
|
||||||
JButton highscoreButton = createButton("Highscore anzeigen", 200, 30);
|
JButton highscorelistButton = createButton("Highscoreliste anzeigen", 200, 30);
|
||||||
JButton exitButton = createButton("Spiel beenden", 200, 30);
|
JButton exitButton = createButton("Spiel beenden", 200, 30);
|
||||||
|
|
||||||
|
// Namen für AssertJ-Swing setzen
|
||||||
|
continueButton.setName("continueButton");
|
||||||
|
selectBoardButton.setName("selectBoardButton");
|
||||||
|
randomBoardButton.setName("randomBoardButton");
|
||||||
|
highscorelistButton.setName("highscorelistButton");
|
||||||
|
exitButton.setName("exitButton");
|
||||||
|
|
||||||
// ActionListener hinzufügen
|
// ActionListener hinzufügen
|
||||||
continueButton.addActionListener(e -> showMessage("Spiel fortsetzen wird implementiert."));
|
continueButton.addActionListener(e -> showMessage("Spiel fortsetzen wird implementiert."));
|
||||||
selectBoardButton.addActionListener(e -> showMessage("Spielfeld auswählen wird implementiert."));
|
selectBoardButton.addActionListener(e -> showMessage("Spielfeld auswählen wird implementiert."));
|
||||||
randomBoardButton.addActionListener(e -> showMessage("Zufälliges Spielfeld wird gestartet."));
|
randomBoardButton.addActionListener(e -> showMessage("Zufälliges Spielfeld wird gestartet."));
|
||||||
highscoreButton.addActionListener(e -> showMessage("Highscore-Liste wird angezeigt."));
|
highscorelistButton.addActionListener(e -> showMessage("Highscore-Liste wird angezeigt."));
|
||||||
exitButton.addActionListener(e -> System.exit(0));
|
exitButton.addActionListener(e -> System.exit(0));
|
||||||
|
|
||||||
// Buttons zum Panel hinzufügen
|
// Buttons zum Panel hinzufügen
|
||||||
this.add(continueButton);
|
this.add(continueButton);
|
||||||
this.add(selectBoardButton);
|
this.add(selectBoardButton);
|
||||||
this.add(randomBoardButton);
|
this.add(randomBoardButton);
|
||||||
this.add(highscoreButton);
|
this.add(highscorelistButton);
|
||||||
this.add(exitButton);
|
this.add(exitButton);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package GUI;
|
||||||
|
|
||||||
|
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 javax.swing.*;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
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
|
||||||
|
public void testButtonsExist() {
|
||||||
|
// Buttons über ihre Namen finden und testen
|
||||||
|
assertThat(window.button("continueButton")).isNotNull();
|
||||||
|
assertThat(window.button("selectBoardButton")).isNotNull();
|
||||||
|
assertThat(window.button("randomBoardButton")).isNotNull();
|
||||||
|
assertThat(window.button("highscorelistButton")).isNotNull();
|
||||||
|
assertThat(window.button("exitButton")).isNotNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testButtonActions() {
|
||||||
|
window.button("continueButton").click();
|
||||||
|
window.button("selectBoardButton").click();
|
||||||
|
window.button("randomBoardButton").click();
|
||||||
|
window.button("highscorelistButton").click();
|
||||||
|
window.button("exitButton").click();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue