-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the UI tests for the main menu elements
- Loading branch information
Showing
4 changed files
with
207 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import javax.swing.JFrame; | ||
|
||
import org.assertj.swing.edt.FailOnThreadViolationRepaintManager; | ||
import org.assertj.swing.edt.GuiActionRunner; | ||
import org.assertj.swing.exception.UnexpectedException; | ||
import org.assertj.swing.fixture.FrameFixture; | ||
import org.assertj.swing.fixture.JSpinnerFixture; | ||
import org.junit.BeforeClass; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
|
||
@TestMethodOrder(OrderAnnotation.class) | ||
class MenuPlayerCountAndRoundsUITest { | ||
private FrameFixture window; | ||
private Gui gui; | ||
private JSpinnerFixture spinner; | ||
|
||
|
||
static Stream<Arguments> spinnerNamesWithMinMaxBounds() { | ||
return Stream.of(Arguments.of("RoundSetter","1","100"), | ||
Arguments.of("PlayerCount","4","8")); | ||
} | ||
|
||
@BeforeClass | ||
public static void setUpOnce(){ | ||
FailOnThreadViolationRepaintManager.install(); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp(){ | ||
Gui.getInstance().getFrame().setVisible(false); | ||
|
||
gui = Gui.resetInstance(); | ||
|
||
JFrame frame = GuiActionRunner.execute(() -> { | ||
return gui.getFrame(); | ||
}); | ||
window = new FrameFixture(frame); | ||
|
||
|
||
} | ||
|
||
|
||
@ParameterizedTest(name = "{0}setEnteredValue") | ||
@MethodSource(value = "spinnerNamesWithMinMaxBounds") | ||
@Order(1) | ||
void setEnteredValue(String name,String minVal,String maxVal){ | ||
spinner = window.spinner(name); | ||
assertNotEquals(spinner.text(),maxVal); | ||
String lastVal = spinner.text(); | ||
|
||
spinner.enterTextAndCommit(maxVal); | ||
|
||
assertNotEquals(lastVal,spinner.text()); | ||
} | ||
|
||
|
||
|
||
@ParameterizedTest(name = "{0}increasingWhenPressedTheIncrease") | ||
@MethodSource(value = "spinnerNamesWithMinMaxBounds") | ||
@Order(2) | ||
void increasingWhenPressedTheIncrease(String name,String minVal,String maxVal){ | ||
spinner = window.spinner(name); | ||
spinner.enterTextAndCommit(minVal); | ||
|
||
spinner.increment(); | ||
assertTrue(Integer.parseInt(minVal) < Integer.parseInt(spinner.text())); | ||
} | ||
|
||
|
||
@ParameterizedTest(name = "{0}decreasingWhenPressedTheDecrease") | ||
@MethodSource(value = "spinnerNamesWithMinMaxBounds") | ||
@Order(3) | ||
void decreasingWhenPressedTheDecrease(String name,String minVal,String maxVal){ | ||
spinner = window.spinner(name); | ||
spinner.enterTextAndCommit(maxVal); | ||
|
||
spinner.decrement(); | ||
assertTrue(Integer.parseInt(maxVal) > Integer.parseInt(spinner.text())); | ||
} | ||
|
||
|
||
@ParameterizedTest(name = "{0}minimumValueBoundCheck") | ||
@MethodSource(value = "spinnerNamesWithMinMaxBounds") | ||
void minimumValueBoundCheck(String name,String minVal,String maxVal){ | ||
spinner = window.spinner(name); | ||
spinner.enterTextAndCommit(minVal); | ||
|
||
spinner.decrement(); | ||
assertEquals(minVal, spinner.text()); | ||
spinner.increment(); | ||
assertNotEquals(minVal, spinner.text()); | ||
|
||
String outBoundVal = Integer.toString(Integer.parseInt(minVal) - Integer.parseInt(maxVal)); | ||
assertThrows(UnexpectedException.class, () -> spinner.enterTextAndCommit(outBoundVal)); | ||
} | ||
|
||
@ParameterizedTest(name = "{0}maximumValueBoundCheck") | ||
@MethodSource(value = "spinnerNamesWithMinMaxBounds") | ||
void maximumValueBoundCheck(String name,String minVal,String maxVal){ | ||
spinner = window.spinner(name); | ||
spinner.enterTextAndCommit(maxVal); | ||
|
||
spinner.increment(); | ||
assertEquals(maxVal, spinner.text()); | ||
spinner.decrement(); | ||
assertNotEquals(maxVal, spinner.text()); | ||
|
||
String outBoundVal = Integer.toString(Integer.parseInt(maxVal) + (Integer.parseInt(maxVal) - Integer.parseInt(minVal))); | ||
assertThrows(UnexpectedException.class, () -> spinner.enterTextAndCommit(outBoundVal)); | ||
} | ||
|
||
|
||
@AfterEach | ||
public void tearDown() { | ||
window.cleanUp(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import javax.swing.JFrame; | ||
|
||
import org.assertj.swing.edt.FailOnThreadViolationRepaintManager; | ||
import org.assertj.swing.edt.GuiActionRunner; | ||
import org.assertj.swing.exception.ComponentLookupException; | ||
import org.assertj.swing.fixture.FrameFixture; | ||
import org.assertj.swing.fixture.JPanelFixture; | ||
import org.junit.BeforeClass; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; | ||
import org.junit.jupiter.api.Order; | ||
|
||
|
||
@TestMethodOrder(OrderAnnotation.class) | ||
class MenuPlayerCountUITest { | ||
private FrameFixture window; | ||
private Gui gui; | ||
|
||
@BeforeClass | ||
public static void setUpOnce(){ | ||
FailOnThreadViolationRepaintManager.install(); | ||
} | ||
|
||
@BeforeEach | ||
public void setUp(){ | ||
Gui.getInstance().getFrame().setVisible(false); | ||
|
||
Game.resetInstance(); | ||
gui = Gui.resetInstance(); | ||
|
||
|
||
JFrame frame = GuiActionRunner.execute(() -> { | ||
return gui.getFrame(); | ||
}); | ||
window = new FrameFixture(frame); | ||
} | ||
|
||
|
||
@Test | ||
@Order(1) | ||
void MenuStartButtonClick(){ | ||
|
||
assertThrows(ComponentLookupException.class, () -> window.panel("GamePanel")); | ||
window.button("StartButton").click(); | ||
assertThrows(ComponentLookupException.class, () -> window.panel("MenuPanel")); | ||
assertEquals(JPanelFixture.class, window.panel("GamePanel").getClass()); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
void GameValuesChangingAfterStartButtonClickAtMenu(){ | ||
String playerCount = "8"; | ||
String rounds = "10"; | ||
window.spinner("RoundSetter").enterTextAndCommit("10"); | ||
window.spinner("PlayerCount").enterTextAndCommit("8"); | ||
window.button("StartButton").click(); | ||
assertEquals(Integer.parseInt(rounds), Game.getInstance().getTurns()); | ||
String allPlayersInGame = Integer.toString(Game.getInstance().repairmanGroup.size() + Game.getInstance().saboteurGroup.size()); | ||
assertEquals(playerCount, allPlayersInGame); | ||
} | ||
|
||
|
||
|
||
@AfterEach | ||
public void tearDown() { | ||
window.cleanUp(); | ||
} | ||
|
||
} |