From 5abe93fdd9b86b79939395d2d53ce7bd1f78de8d Mon Sep 17 00:00:00 2001
From: Michael Breu <Michael.Breu@arctis.at>
Date: Mon, 22 Jan 2024 13:53:04 +0100
Subject: [PATCH] Extending PropertiesTester

---
 .../testingUtilities/PropertiesTester.java    | 36 ++++++++++
 .../PropertiesTesterTests.java                | 72 +++++++++++++++++++
 2 files changed, 108 insertions(+)
 create mode 100644 src/test/java/at/ac/uibk/gitsearch/testingUtilities/PropertiesTesterTests.java

diff --git a/src/test/java/at/ac/uibk/gitsearch/testingUtilities/PropertiesTester.java b/src/test/java/at/ac/uibk/gitsearch/testingUtilities/PropertiesTester.java
index a7ffd91cb..312652568 100644
--- a/src/test/java/at/ac/uibk/gitsearch/testingUtilities/PropertiesTester.java
+++ b/src/test/java/at/ac/uibk/gitsearch/testingUtilities/PropertiesTester.java
@@ -24,7 +24,43 @@ import tech.jhipster.service.filter.StringFilter;
 
 /**
  * tests all getters and setters of a bean.
+ * If some setters should not be tested, it can be submitted in an exception
+ * list. It supports getters for
+ * <ul>
+ * <li>String</li>
+ * <li>boolean/Boolean</li>
+ * <li>int/Integer</li>
+ * <li>float/double/Float/Double</li>
+ * <li>byte/Byte</li>
+ * <li>byte[]</li>
+ * <li><T>[]</li>
+ * <li>java.sql.Timestamp</li>
+ * <li>java.util.Date</li>
+ * <li>List<T></li>
+ * <li>enums</li>
+ * <li>tech.jhipster.service.filter.{String|Boolean|Integer|LocalDate|Long}Filter</li>
+ *
+ *
+ * </ul>
+ *
+ * <br>
+ * <p>
+ * <b>Usage:</b>
+ * </p>
+ * <p>
+ *
+ * <pre>
+ *   {@literal @}Test
+ *   void testBean() {
+ *       PropertiesTester pt = new PropertiesTester();
+ *
+ *       pt.testProperties(TestBean.class, /* except * / "setDoubledString");
+ *   }
+ * </pre>
+ * </p>
+ *
  * @author arctis Softwaretechnologie Team
+ * @see PropertiesTesterTests
  *
  */
 @Controller
diff --git a/src/test/java/at/ac/uibk/gitsearch/testingUtilities/PropertiesTesterTests.java b/src/test/java/at/ac/uibk/gitsearch/testingUtilities/PropertiesTesterTests.java
new file mode 100644
index 000000000..a9b4ce539
--- /dev/null
+++ b/src/test/java/at/ac/uibk/gitsearch/testingUtilities/PropertiesTesterTests.java
@@ -0,0 +1,72 @@
+package at.ac.uibk.gitsearch.testingUtilities;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.jupiter.api.Test;
+
+class PropertiesTesterTests {
+
+    public static class TestBean {
+
+        private boolean booleanField;
+        private String stringField;
+        private int intField;
+        private String[] arrayField;
+
+        public boolean isBooleanField() {
+            return booleanField;
+        }
+
+        public void setBooleanField(boolean booleanField) {
+            this.booleanField = booleanField;
+        }
+
+        public String getStringField() {
+            return stringField;
+        }
+
+        public void setStringField(String stringField) {
+            this.stringField = stringField;
+        }
+
+        public int getIntField() {
+            return intField;
+        }
+
+        public void setIntField(int intField) {
+            this.intField = intField;
+        }
+
+        public String getDoubledString() {
+            return stringField;
+        }
+
+        public void setDoubledString(String doubledString) {
+            if (doubledString != null) {
+                this.stringField = doubledString + doubledString;
+            } else {
+                this.stringField = null;
+            }
+        }
+
+        public String[] getArrayField() {
+            return arrayField;
+        }
+
+        public void setArrayField(String[] arrayField) {
+            this.arrayField = arrayField;
+        }
+    }
+
+    @Test
+    void testBean() {
+        PropertiesTester pt = new PropertiesTester();
+
+        pt.testProperties(TestBean.class, /* except */"setDoubledString");
+
+        // extra tests for setDoubledString
+        TestBean tb = new TestBean();
+        tb.setDoubledString("abc");
+        assertEquals("abcabc", tb.getDoubledString());
+    }
+}
-- 
GitLab