From c78560ac3afd9264eb2601df08078b9ae8aabf31 Mon Sep 17 00:00:00 2001
From: verboomp
Date: Tue, 3 Feb 2026 12:27:56 +0100
Subject: [PATCH] cleanup and unit tests
---
.../core/utils/ImageUtil.java | 6 +++---
.../core/utils/PdfUtils.java | 11 +++++------
.../rest/vo/PictureValue.java | 9 ++++++---
.../core/utils/ImageUtilTest.java | 4 ++--
.../rest/CustomerPictureResourceTest.java | 19 -------------------
5 files changed, 16 insertions(+), 33 deletions(-)
diff --git a/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/core/utils/ImageUtil.java b/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/core/utils/ImageUtil.java
index ff3a782..b1b607d 100644
--- a/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/core/utils/ImageUtil.java
+++ b/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/core/utils/ImageUtil.java
@@ -31,10 +31,10 @@ public class ImageUtil {
private static final Log LOG = LogFactory.getLog(ImageUtil.class);
private static final int NORMAL_MAX_WIDTH = 1200;
- private static final float NORMAL_QUALITY = 0.75f;
+ private static final float NORMAL_QUALITY = 0.75F;
private static final int THUMBNAIL_MAX_WIDTH = 200;
- private static final float THUMBNAIL_QUALITY = 0.6f;
+ private static final float THUMBNAIL_QUALITY = 0.6F;
/**
* size 1 is original
@@ -68,7 +68,6 @@ public class ImageUtil {
}
int originalWidth = image.getWidth();
- int originalHeight = image.getHeight();
if (originalWidth <= maxWidth) {
return original;
@@ -76,6 +75,7 @@ public class ImageUtil {
double scale = (double) maxWidth / originalWidth;
int targetWidth = maxWidth;
+ int originalHeight = image.getHeight();
int targetHeight = (int) (originalHeight * scale);
BufferedImage resized = new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
diff --git a/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/core/utils/PdfUtils.java b/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/core/utils/PdfUtils.java
index 50888f9..f4def7b 100644
--- a/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/core/utils/PdfUtils.java
+++ b/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/core/utils/PdfUtils.java
@@ -33,7 +33,7 @@ import marketing.heyday.hartmann.fotodocumentation.core.model.Picture;
*
* created: 2 Feb 2026
*/
-@SuppressWarnings({"java:S818", "squid:S818", "squid:S109"})
+@SuppressWarnings({ "java:S818", "squid:S818", "squid:S109" })
public class PdfUtils {
private static final Log LOG = LogFactory.getLog(PdfUtils.class);
@@ -42,10 +42,9 @@ public class PdfUtils {
private static final Color COLOR_CUSTOMER_NAME = new Color(0x00, 0x45, 0xFF);
private static final Color COLOR_DATE = new Color(0x00, 0x16, 0x89);
-
+
private static final Color COLOR_TEXT_GRAY = new Color(0x2F, 0x2F, 0x2F);
-
-
+
private static final Color COLOR_GREEN = new Color(76, 175, 80);
private static final Color COLOR_YELLOW = new Color(255, 193, 7);
private static final Color COLOR_RED = new Color(244, 67, 54);
@@ -114,7 +113,7 @@ public class PdfUtils {
float rightY = imageY - 32F;
// Date (no label, bold, size 44)
- String dateStr = picture.getPictureDate() != null ? DATE_FORMAT.format(picture.getPictureDate()) + " UHR": "";
+ String dateStr = picture.getPictureDate() != null ? (DATE_FORMAT.format(picture.getPictureDate()) + " UHR") : "";
cs.setFont(fontBold, 32);
cs.setNonStrokingColor(COLOR_DATE);
cs.beginText();
@@ -202,7 +201,7 @@ public class PdfUtils {
float currentY = y;
for (String word : words) {
- String testLine = line.isEmpty() ? word : line + " " + word;
+ String testLine = line.isEmpty() ? word : (line + " " + word);
float textWidth = font.getStringWidth(testLine) / 1000F * 10F;
if (textWidth > maxWidth && !line.isEmpty()) {
cs.beginText();
diff --git a/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/rest/vo/PictureValue.java b/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/rest/vo/PictureValue.java
index e81463d..b8f02c1 100644
--- a/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/rest/vo/PictureValue.java
+++ b/hartmann-foto-documentation-app/src/main/java/marketing/heyday/hartmann/fotodocumentation/rest/vo/PictureValue.java
@@ -22,9 +22,12 @@ public record PictureValue(Long id, String comment, String category, Date pictur
if (picture == null) {
return null;
}
- String imageUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=1";
- String normalSizeUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=2";
- String thumbnailSizeUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=3";
+
+ String sizeUrl = baseUrl + "picture/image/" + picture.getPictureId() + "?size=";
+
+ String imageUrl = sizeUrl + "1";
+ String normalSizeUrl = sizeUrl + "2";
+ String thumbnailSizeUrl = sizeUrl + "3";
return new PictureValue(picture.getPictureId(), picture.getComment(), picture.getCategory(), picture.getPictureDate(), picture.getUsername(), picture.getEvaluation(), imageUrl, normalSizeUrl, thumbnailSizeUrl);
}
}
\ No newline at end of file
diff --git a/hartmann-foto-documentation-app/src/test/java/marketing/heyday/hartmann/fotodocumentation/core/utils/ImageUtilTest.java b/hartmann-foto-documentation-app/src/test/java/marketing/heyday/hartmann/fotodocumentation/core/utils/ImageUtilTest.java
index dfc5805..d907def 100644
--- a/hartmann-foto-documentation-app/src/test/java/marketing/heyday/hartmann/fotodocumentation/core/utils/ImageUtilTest.java
+++ b/hartmann-foto-documentation-app/src/test/java/marketing/heyday/hartmann/fotodocumentation/core/utils/ImageUtilTest.java
@@ -164,7 +164,7 @@ class ImageUtilTest {
// --- Output format ---
@Test
- void getImage_size2_outputIsJpeg() throws IOException {
+ void getImage_size2_outputIsJpeg() {
String base64 = createTestImageBase64(2400, 1600);
byte[] result = imageUtil.getImage(base64, 2);
@@ -176,7 +176,7 @@ class ImageUtilTest {
}
@Test
- void getImage_size3_outputIsJpeg() throws IOException {
+ void getImage_size3_outputIsJpeg() {
String base64 = createTestImageBase64(2400, 1600);
byte[] result = imageUtil.getImage(base64, 3);
diff --git a/hartmann-foto-documentation-docker/src/test/java/marketing/heyday/hartmann/fotodocumentation/rest/CustomerPictureResourceTest.java b/hartmann-foto-documentation-docker/src/test/java/marketing/heyday/hartmann/fotodocumentation/rest/CustomerPictureResourceTest.java
index 067dadc..beaaca7 100644
--- a/hartmann-foto-documentation-docker/src/test/java/marketing/heyday/hartmann/fotodocumentation/rest/CustomerPictureResourceTest.java
+++ b/hartmann-foto-documentation-docker/src/test/java/marketing/heyday/hartmann/fotodocumentation/rest/CustomerPictureResourceTest.java
@@ -44,11 +44,8 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
assertEquals(3, customerCount());
assertEquals(5, pictureCount());
- //String authorization = getBasicHeader();
- //LOG.info("authorization: " + authorization);
String path = deploymentURL + PATH;
Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
- //.addHeader("Authorization", authorization)
.bodyFile(new File(BASE_UPLOAD + "add.json"), ContentType.APPLICATION_JSON);
HttpResponse httpResponse = executeRequest(request);
@@ -101,22 +98,6 @@ public class CustomerPictureResourceTest extends AbstractRestTest {
String text = getResponseText(httpResponse, "doGetAll");
System.out.println(text);
}
-
- /*
- @Test
- @Order(1)
- public void doAddCustomerPictureNoAuth() throws IOException {
- LOG.info("doAddCustomerPictureNoAuth");
-
- String path = deploymentURL + PATH;
- Request request = Request.Post(path).addHeader("Accept", "application/json; charset=utf-8")
- .bodyFile(new File(BASE_UPLOAD + "add.json"), ContentType.APPLICATION_JSON);
-
- HttpResponse httpResponse = executeRequest(request);
- int code = httpResponse.getStatusLine().getStatusCode();
- assertEquals(401, code);
- }
-*/
@Test
@Order(2)