From 5dfb39712d62767c74f81ad2c12f73a4ad2e1dc6 Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Sat, 21 Aug 2021 17:18:36 +0200 Subject: [PATCH 1/2] first commit (#11118) --- maven-modules/maven-surefire-plugin/pom.xml | 17 +++++++++++ .../runasingletest/TheFirstUnitTest.java | 14 +++++++++ .../runasingletest/TheSecondUnitTest.java | 30 +++++++++++++++++++ maven-modules/pom.xml | 3 +- 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 maven-modules/maven-surefire-plugin/pom.xml create mode 100644 maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheFirstUnitTest.java create mode 100644 maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheSecondUnitTest.java diff --git a/maven-modules/maven-surefire-plugin/pom.xml b/maven-modules/maven-surefire-plugin/pom.xml new file mode 100644 index 0000000000..903adf3c11 --- /dev/null +++ b/maven-modules/maven-surefire-plugin/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + maven-surefire-plugin + 0.0.1-SNAPSHOT + maven-surefire-plugin + jar + + com.baeldung + maven-modules + 0.0.1-SNAPSHOT + + + + diff --git a/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheFirstUnitTest.java b/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheFirstUnitTest.java new file mode 100644 index 0000000000..1e7fce885e --- /dev/null +++ b/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheFirstUnitTest.java @@ -0,0 +1,14 @@ +package com.baeldung.runasingletest; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class TheFirstUnitTest { + private static final Logger logger = LoggerFactory.getLogger(TheFirstUnitTest.class); + + @Test + void whenTestCase_thenPass() { + logger.info("Running a dummyTest"); + } +} diff --git a/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheSecondUnitTest.java b/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheSecondUnitTest.java new file mode 100644 index 0000000000..fd05751599 --- /dev/null +++ b/maven-modules/maven-surefire-plugin/src/test/java/com/baeldung/runasingletest/TheSecondUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.runasingletest; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class TheSecondUnitTest { + + private static final Logger logger = LoggerFactory.getLogger(TheSecondUnitTest.class); + + @Test + void whenTestCase1_thenPrintTest1_1() { + logger.info("Running When Case1: test1_1"); + } + + @Test + void whenTestCase1_thenPrintTest1_2() { + logger.info("Running When Case1: test1_2"); + } + + @Test + void whenTestCase1_thenPrintTest1_3() { + logger.info("Running When Case1: test1_3"); + } + + @Test + void whenTestCase2_thenPrintTest2_1() { + logger.info("Running When Case2: test2_1"); + } +} diff --git a/maven-modules/pom.xml b/maven-modules/pom.xml index 5b4b567ae6..a0c45234d2 100644 --- a/maven-modules/pom.xml +++ b/maven-modules/pom.xml @@ -35,6 +35,7 @@ maven-builder-plugin host-maven-repo-example plugin-management + maven-surefire-plugin - \ No newline at end of file + From cf452d7add33fba456c75f5d496a1364690518c1 Mon Sep 17 00:00:00 2001 From: Anton Kudruk Date: Sat, 21 Aug 2021 19:09:19 +0300 Subject: [PATCH 2/2] Added JavaFX demo app for ListView CellFactory (#11133) * Added JavaFX demo app for ListView CellFactory * Moved to the common project --- .../baeldung/listview/ExampleController.java | 38 +++++++++++++++++++ .../main/java/com/baeldung/listview/Main.java | 28 ++++++++++++++ .../java/com/baeldung/listview/Person.java | 25 ++++++++++++ .../cellfactory/CheckboxCellFactory.java | 29 ++++++++++++++ .../cellfactory/PersonCellFactory.java | 23 +++++++++++ javafx/src/main/resources/example.fxml | 14 +++++++ 6 files changed, 157 insertions(+) create mode 100644 javafx/src/main/java/com/baeldung/listview/ExampleController.java create mode 100644 javafx/src/main/java/com/baeldung/listview/Main.java create mode 100644 javafx/src/main/java/com/baeldung/listview/Person.java create mode 100644 javafx/src/main/java/com/baeldung/listview/cellfactory/CheckboxCellFactory.java create mode 100644 javafx/src/main/java/com/baeldung/listview/cellfactory/PersonCellFactory.java create mode 100644 javafx/src/main/resources/example.fxml diff --git a/javafx/src/main/java/com/baeldung/listview/ExampleController.java b/javafx/src/main/java/com/baeldung/listview/ExampleController.java new file mode 100644 index 0000000000..c02fa68d2e --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/ExampleController.java @@ -0,0 +1,38 @@ +package com.baeldung.listview; + +import com.baeldung.listview.cellfactory.CheckboxCellFactory; +import com.baeldung.listview.cellfactory.PersonCellFactory; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.ListView; + +import java.net.URL; +import java.util.ResourceBundle; + +public class ExampleController implements Initializable { + @FXML + private ListView listView; + + @Override + public void initialize(URL location, ResourceBundle resources) { + ObservableList wordsList = FXCollections.observableArrayList(); + wordsList.add(new Person("Isaac", "Newton")); + wordsList.add(new Person("Albert", "Einstein")); + wordsList.add(new Person("Ludwig", "Boltzmann")); + listView.setItems(wordsList); + } + + public void defaultButtonClick() { + listView.setCellFactory(null); + } + + public void cellFactoryButtonClick() { + listView.setCellFactory(new PersonCellFactory()); + } + + public void checkboxCellFactoryButtonClick() { + listView.setCellFactory(new CheckboxCellFactory()); + } +} diff --git a/javafx/src/main/java/com/baeldung/listview/Main.java b/javafx/src/main/java/com/baeldung/listview/Main.java new file mode 100644 index 0000000000..a067971758 --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/Main.java @@ -0,0 +1,28 @@ +package com.baeldung.javafx.listview; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.net.URL; + +public class Main extends Application { + + public static void main(String args[]) { + launch(args); + } + + @Override + public void start(Stage primaryStage) throws Exception { + FXMLLoader loader = new FXMLLoader(); + URL xmlUrl = getClass().getResource("/example.fxml"); + loader.setLocation(xmlUrl); + Parent root = loader.load(); + + primaryStage.setTitle("List View Demo"); + primaryStage.setScene(new Scene(root)); + primaryStage.show(); + } +} diff --git a/javafx/src/main/java/com/baeldung/listview/Person.java b/javafx/src/main/java/com/baeldung/listview/Person.java new file mode 100644 index 0000000000..cdc0ab2dc8 --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/Person.java @@ -0,0 +1,25 @@ +package com.baeldung.listview; + +public class Person { + + private final String firstName; + private final String lastName; + + public Person(String firstName, String lastName) { + this.firstName = firstName; + this.lastName = lastName; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + @Override + public String toString() { + return firstName + " " + lastName; + } +} diff --git a/javafx/src/main/java/com/baeldung/listview/cellfactory/CheckboxCellFactory.java b/javafx/src/main/java/com/baeldung/listview/cellfactory/CheckboxCellFactory.java new file mode 100644 index 0000000000..522afcb76e --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/cellfactory/CheckboxCellFactory.java @@ -0,0 +1,29 @@ +package com.baeldung.listview.cellfactory; + +import com.baeldung.listview.Person; +import javafx.scene.control.CheckBox; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.util.Callback; + +public class CheckboxCellFactory implements Callback, ListCell> { + @Override + public ListCell call(ListView param) { + return new ListCell(){ + @Override + public void updateItem(Person person, boolean empty) { + super.updateItem(person, empty); + if (empty) { + setText(null); + setGraphic(null); + } else if (person != null) { + setText(null); + setGraphic(new CheckBox(person.getFirstName() + " " + person.getLastName())); + } else { + setText("null"); + setGraphic(null); + } + } + }; + } +} diff --git a/javafx/src/main/java/com/baeldung/listview/cellfactory/PersonCellFactory.java b/javafx/src/main/java/com/baeldung/listview/cellfactory/PersonCellFactory.java new file mode 100644 index 0000000000..57866b9ead --- /dev/null +++ b/javafx/src/main/java/com/baeldung/listview/cellfactory/PersonCellFactory.java @@ -0,0 +1,23 @@ +package com.baeldung.listview.cellfactory; + +import com.baeldung.listview.Person; +import javafx.scene.control.ListCell; +import javafx.scene.control.ListView; +import javafx.util.Callback; + +public class PersonCellFactory implements Callback, ListCell> { + @Override + public ListCell call(ListView param) { + return new ListCell(){ + @Override + public void updateItem(Person person, boolean empty) { + super.updateItem(person, empty); + if (empty || person == null) { + setText(null); + } else { + setText(person.getFirstName() + " " + person.getLastName()); + } + } + }; + } +} diff --git a/javafx/src/main/resources/example.fxml b/javafx/src/main/resources/example.fxml new file mode 100644 index 0000000000..c68df076d0 --- /dev/null +++ b/javafx/src/main/resources/example.fxml @@ -0,0 +1,14 @@ + + + + + + + + + +