-
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.
- Loading branch information
Showing
1 changed file
with
107 additions
and
0 deletions.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
src/test/java/edu/ntnu/idi/idatt2003/g40/mappe/view/ViewElementTest.java
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,107 @@ | ||
| package edu.ntnu.idi.idatt2003.g40.mappe.view; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import edu.ntnu.idi.idatt2003.g40.mappe.service.event.EventManager; | ||
| import javafx.scene.control.Button; | ||
| import javafx.scene.layout.Pane; | ||
| import javafx.scene.layout.VBox; | ||
| import javafx.stage.Stage; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.testfx.framework.junit5.ApplicationTest; | ||
|
|
||
| class ViewElementTest extends ApplicationTest { | ||
|
|
||
| /** | ||
| * View element instance used for testing. | ||
| * */ | ||
| private ViewElementTest.GenericViewElement testViewElement; | ||
|
|
||
| /** | ||
| * Root of generic view instance. | ||
| * */ | ||
| private Pane rootPane; | ||
|
|
||
| @Override | ||
| public void start(final Stage stage) { | ||
| rootPane = new Pane(); | ||
| testViewElement = new ViewElementTest.GenericViewElement(rootPane); | ||
| } | ||
|
|
||
| @Test | ||
| void constructorSetsValuesAsExpected() { | ||
| assertEquals(rootPane, testViewElement.getRootPane()); | ||
| } | ||
|
|
||
| @Test | ||
| void constructorThrowsExceptionWhenIllegalArguments() { | ||
| assertDoesNotThrow( | ||
| () -> new ViewElementTest.GenericViewElement(new VBox()) | ||
| ); | ||
|
|
||
| assertThrows(IllegalArgumentException.class, | ||
| () -> new ViewElementTest.GenericViewElement(null) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void setOnActionThrowsExceptionOnIllegalArguments() { | ||
| assertThrows(IllegalArgumentException.class, | ||
| () -> testViewElement.setOnAction( | ||
| GenericViewActions.UNUSED_TEST_ACTION, | ||
| () -> testViewElement.setButtonPressed() | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| private enum GenericViewActions { | ||
| /** | ||
| * Action used for testing purposes. | ||
| * */ | ||
| TEST_ACTION, | ||
|
|
||
| /** | ||
| * Unused test action to check exception throwing. | ||
| * */ | ||
| UNUSED_TEST_ACTION | ||
| } | ||
|
|
||
| /** | ||
| * Test class meant for simulating a view element instance. | ||
| * | ||
| * @see ViewElement | ||
| * */ | ||
| private static class GenericViewElement extends ViewElement<Pane, ViewElementTest.GenericViewActions> { | ||
| private boolean buttonPressed = false; | ||
| private Button interactableButton; | ||
|
|
||
| protected GenericViewElement(final Pane rootPane) { | ||
| super(rootPane, ViewElementTest.GenericViewActions.class); | ||
| } | ||
|
|
||
| @Override | ||
| protected void initLayout() { | ||
| interactableButton = new Button("Click me!"); | ||
| registerButton(ViewElementTest.GenericViewActions.TEST_ACTION, interactableButton); | ||
| } | ||
|
|
||
| public Button getInteractableButton() { | ||
| return interactableButton; | ||
| } | ||
|
|
||
| public boolean getButtonPressed() { | ||
| return buttonPressed; | ||
| } | ||
|
|
||
| public void setButtonPressed() { | ||
| buttonPressed = true; | ||
| } | ||
|
|
||
| @Override | ||
| protected void initStyling() { | ||
| // Empty | ||
| } | ||
| } | ||
| } |