Skip to content
Snippets Groups Projects
Commit c542c342 authored by Hallvard Trætteberg's avatar Hallvard Trætteberg
Browse files

Added test and branch banner

parent b6f52195
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https://gitlab.stud.idi.ntnu.no/it1901/gitpod-templates/tree/javafx)
Contains example of minimal javafx app (with test)
<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>
<?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>
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);
}
}
package javafxapp;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
public class AppController {
@FXML
Button clickMeButton;
@FXML
void handleClickMeButtonAction() {
clickMeButton.setText("Thanks!");
}
}
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));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment