From c542c34271286e79c77a17246785e284375c6a8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hallvard=20Tr=C3=A6tteberg?= <hal@ntnu.no> Date: Fri, 19 Jun 2020 14:09:54 +0000 Subject: [PATCH] Added test and branch banner --- .gitpod.yml | 2 +- README.md | 6 ++ javafx-app/pom.xml | 101 ++++++++++++++++++++ javafx-app/src/javafxapp/App.fxml | 8 ++ javafx-app/src/javafxapp/App.java | 21 ++++ javafx-app/src/javafxapp/AppController.java | 15 +++ javafx-app/test/javafxapp/AppTest.java | 34 +++++++ 7 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 javafx-app/pom.xml create mode 100644 javafx-app/src/javafxapp/App.fxml create mode 100644 javafx-app/src/javafxapp/App.java create mode 100644 javafx-app/src/javafxapp/AppController.java create mode 100644 javafx-app/test/javafxapp/AppTest.java diff --git a/.gitpod.yml b/.gitpod.yml index 1da4947..9f43e55 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -3,7 +3,7 @@ image: tasks: - init: sdk use java 14.0.1.j9-adpt - # command: cd my-project + command: cd javafxapp ports: # used by virtual desktop and vnc, supports JavaFX diff --git a/README.md b/README.md index ed65065..738ac45 100644 --- a/README.md +++ b/README.md @@ -5,3 +5,9 @@ This repo contains templates for repositories that support gitpod, i.e. with proper .gitignore, .gitpod.docker and .gitpod.yml files There are also branches for projects configured with maven and/or gradle for various purposes + +## javafx branch + +[](https://gitpod.io/#https://gitlab.stud.idi.ntnu.no/it1901/gitpod-templates/tree/javafx) + +Contains example of minimal javafx app (with test) diff --git a/javafx-app/pom.xml b/javafx-app/pom.xml new file mode 100644 index 0000000..07c4986 --- /dev/null +++ b/javafx-app/pom.xml @@ -0,0 +1,101 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>it1901</groupId> + <artifactId>javafx-app</artifactId> + <version>0.0.1-SNAPSHOT</version> + + <dependencies> + <!-- JavaFX --> + <dependency> + <groupId>org.openjfx</groupId> + <artifactId>javafx-fxml</artifactId> + <version>14.0.1</version> + </dependency> + + <!-- Test with JUnit5 --> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <version>5.4.2</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <version>5.4.2</version> + <scope>test</scope> + </dependency> + + <!-- Test with TextFX --> + <dependency> + <groupId>org.testfx</groupId> + <artifactId>testfx-core</artifactId> + <version>4.0.16-alpha</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.testfx</groupId> + <artifactId>testfx-junit5</artifactId> + <version>4.0.16-alpha</version> + <scope>test</scope> + </dependency> + </dependencies> + + <properties> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + </properties> + + <build> + <sourceDirectory>src</sourceDirectory> + <resources> + <resource> + <directory>src</directory> + <includes> + <include>**/*.fxml</include> + <include>**/*.png</include> + </includes> + </resource> + </resources> + <testSourceDirectory>test</testSourceDirectory> + <testResources> + <testResource> + <directory>test</directory> + <includes> + <include>**/*.fxml</include> + <include>**/*.png</include> + </includes> + </testResource> + </testResources> + + <plugins> + <!-- Compiling code --> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <version>3.8.1</version> + <configuration> + <encoding>UTF-8</encoding> + <release>14</release> + </configuration> + </plugin> + + <!-- Running tests --> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <version>2.22.2</version> + </plugin> + + <!-- Running JavaFX code --> + <plugin> + <groupId>org.openjfx</groupId> + <artifactId>javafx-maven-plugin</artifactId> + <version>0.0.4</version> + <configuration> + <mainClass>javafxapp.App</mainClass> + </configuration> + </plugin> + </plugins> + </build> +</project> diff --git a/javafx-app/src/javafxapp/App.fxml b/javafx-app/src/javafxapp/App.fxml new file mode 100644 index 0000000..94cfdfa --- /dev/null +++ b/javafx-app/src/javafxapp/App.fxml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<?import javafx.scene.layout.Pane?> +<?import javafx.scene.control.Button?> + +<Pane xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxapp.AppController"> + <Button fx:id="clickMeButton" text="Click me!" onAction="#handleClickMeButtonAction"/> +</Pane> diff --git a/javafx-app/src/javafxapp/App.java b/javafx-app/src/javafxapp/App.java new file mode 100644 index 0000000..ca72d4a --- /dev/null +++ b/javafx-app/src/javafxapp/App.java @@ -0,0 +1,21 @@ +package javafxapp; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +public class App extends Application { + + @Override + public void start(final Stage primaryStage) throws Exception { + final Parent parent = FXMLLoader.load(getClass().getResource("App.fxml")); + primaryStage.setScene(new Scene(parent)); + primaryStage.show(); + } + + public static void main(final String[] args) { + launch(args); + } +} diff --git a/javafx-app/src/javafxapp/AppController.java b/javafx-app/src/javafxapp/AppController.java new file mode 100644 index 0000000..fc0d9b8 --- /dev/null +++ b/javafx-app/src/javafxapp/AppController.java @@ -0,0 +1,15 @@ +package javafxapp; + +import javafx.fxml.FXML; +import javafx.scene.control.Button; + +public class AppController { + + @FXML + Button clickMeButton; + + @FXML + void handleClickMeButtonAction() { + clickMeButton.setText("Thanks!"); + } +} diff --git a/javafx-app/test/javafxapp/AppTest.java b/javafx-app/test/javafxapp/AppTest.java new file mode 100644 index 0000000..dc4a6ee --- /dev/null +++ b/javafx-app/test/javafxapp/AppTest.java @@ -0,0 +1,34 @@ +package javafxapp; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.testfx.api.FxAssert; +import org.testfx.framework.junit5.ApplicationTest; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; +import javafx.scene.control.Button; + +public class AppTest extends ApplicationTest { + + private Parent parent; + private AppController controller; + + @Override + public void start(final Stage stage) throws Exception { + final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("App.fxml")); + parent = fxmlLoader.load(); + controller = fxmlLoader.getController(); + stage.setScene(new Scene(parent)); + stage.show(); + } + + @Test + public void testController() { + final Button clickMeButton = (Button) parent.lookup("#clickMeButton"); + String oldText = clickMeButton.getText(); + clickOn(clickMeButton); + Assertions.assertFalse(clickMeButton.getText().equals(oldText)); + } +} -- GitLab