From 55ba184c851fe94bbff231fb9cc8193e0a633dc8 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 11 Sep 2025 13:52:04 +0000
Subject: [PATCH 1/3] Initial plan
From 7774bde5d5cad6cc5fa50a2f6af9e61d923b7f0f Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Thu, 11 Sep 2025 14:07:23 +0000
Subject: [PATCH 2/3] Phase 1 complete: Comprehensive unit tests for
turing-commons module
Co-authored-by: alegauss <331174+alegauss@users.noreply.github.com>
---
turing-commons/pom.xml | 25 ++
.../commons/file/TurFileAttributesTest.java | 209 +++++++++++
.../turing/commons/file/TurFileSizeTest.java | 172 +++++++++
.../turing/commons/sn/TurSNConfigTest.java | 80 ++++
.../bean/TurSNSiteSearchDocumentBeanTest.java | 186 ++++++++++
...rSNSiteSearchDocumentMetadataBeanTest.java | 175 +++++++++
.../commons/utils/TurCommonsUtilsTest.java | 348 ++++++++++++++++++
7 files changed, 1195 insertions(+)
create mode 100644 turing-commons/src/test/java/com/viglet/turing/commons/file/TurFileAttributesTest.java
create mode 100644 turing-commons/src/test/java/com/viglet/turing/commons/file/TurFileSizeTest.java
create mode 100644 turing-commons/src/test/java/com/viglet/turing/commons/sn/TurSNConfigTest.java
create mode 100644 turing-commons/src/test/java/com/viglet/turing/commons/sn/bean/TurSNSiteSearchDocumentBeanTest.java
create mode 100644 turing-commons/src/test/java/com/viglet/turing/commons/sn/bean/TurSNSiteSearchDocumentMetadataBeanTest.java
create mode 100644 turing-commons/src/test/java/com/viglet/turing/commons/utils/TurCommonsUtilsTest.java
diff --git a/turing-commons/pom.xml b/turing-commons/pom.xml
index 965b0fc7886..60d278e21eb 100644
--- a/turing-commons/pom.xml
+++ b/turing-commons/pom.xml
@@ -96,6 +96,31 @@
5.5.1compile
+
+
+ org.junit.jupiter
+ junit-jupiter
+ 5.11.4
+ test
+
+
+ org.mockito
+ mockito-core
+ 5.15.2
+ test
+
+
+ org.mockito
+ mockito-junit-jupiter
+ 5.15.2
+ test
+
+
+ org.assertj
+ assertj-core
+ 3.26.3
+ test
+ turing-commons
diff --git a/turing-commons/src/test/java/com/viglet/turing/commons/file/TurFileAttributesTest.java b/turing-commons/src/test/java/com/viglet/turing/commons/file/TurFileAttributesTest.java
new file mode 100644
index 00000000000..60812cf0496
--- /dev/null
+++ b/turing-commons/src/test/java/com/viglet/turing/commons/file/TurFileAttributesTest.java
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2016-2024 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If
+ * not, see .
+ */
+
+package com.viglet.turing.commons.file;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for TurFileAttributes.
+ *
+ * @author Alexandre Oliveira
+ * @since 0.3.9
+ */
+class TurFileAttributesTest {
+
+ @Test
+ void testDefaultConstructor() {
+ TurFileAttributes attributes = new TurFileAttributes();
+
+ assertThat(attributes.getContent()).isNull();
+ assertThat(attributes.getName()).isNull();
+ assertThat(attributes.getTitle()).isNull();
+ assertThat(attributes.getExtension()).isNull();
+ assertThat(attributes.getSize()).isNotNull();
+ assertThat(attributes.getLastModified()).isNotNull();
+ assertThat(attributes.getMetadata()).isNotNull().isEmpty();
+ }
+
+ @Test
+ void testBuilderPattern() {
+ Date testDate = new Date();
+ TurFileSize testSize = new TurFileSize();
+ Map testMetadata = new HashMap<>();
+ testMetadata.put("author", "Test Author");
+
+ TurFileAttributes attributes = TurFileAttributes.builder()
+ .content("Test content")
+ .name("test.txt")
+ .title("Test File")
+ .extension("txt")
+ .size(testSize)
+ .lastModified(testDate)
+ .metadata(testMetadata)
+ .build();
+
+ assertThat(attributes.getContent()).isEqualTo("Test content");
+ assertThat(attributes.getName()).isEqualTo("test.txt");
+ assertThat(attributes.getTitle()).isEqualTo("Test File");
+ assertThat(attributes.getExtension()).isEqualTo("txt");
+ assertThat(attributes.getSize()).isEqualTo(testSize);
+ assertThat(attributes.getLastModified()).isEqualTo(testDate);
+ assertThat(attributes.getMetadata()).containsEntry("author", "Test Author");
+ }
+
+ @Test
+ void testAllArgsConstructor() {
+ Date testDate = new Date();
+ TurFileSize testSize = new TurFileSize();
+ Map testMetadata = new HashMap<>();
+ testMetadata.put("type", "document");
+
+ TurFileAttributes attributes = new TurFileAttributes(
+ "Test content",
+ "document.pdf",
+ "Test Document",
+ "pdf",
+ testSize,
+ testDate,
+ testMetadata
+ );
+
+ assertThat(attributes.getContent()).isEqualTo("Test content");
+ assertThat(attributes.getName()).isEqualTo("document.pdf");
+ assertThat(attributes.getTitle()).isEqualTo("Test Document");
+ assertThat(attributes.getExtension()).isEqualTo("pdf");
+ assertThat(attributes.getSize()).isEqualTo(testSize);
+ assertThat(attributes.getLastModified()).isEqualTo(testDate);
+ assertThat(attributes.getMetadata()).containsEntry("type", "document");
+ }
+
+ @Test
+ void testSettersAndGetters() {
+ TurFileAttributes attributes = new TurFileAttributes();
+
+ attributes.setContent("Modified content");
+ attributes.setName("modified.txt");
+ attributes.setTitle("Modified Title");
+ attributes.setExtension("txt");
+
+ Date newDate = new Date(System.currentTimeMillis() + 1000);
+ attributes.setLastModified(newDate);
+
+ TurFileSize newSize = new TurFileSize();
+ attributes.setSize(newSize);
+
+ Map newMetadata = new HashMap<>();
+ newMetadata.put("updated", "true");
+ attributes.setMetadata(newMetadata);
+
+ assertThat(attributes.getContent()).isEqualTo("Modified content");
+ assertThat(attributes.getName()).isEqualTo("modified.txt");
+ assertThat(attributes.getTitle()).isEqualTo("Modified Title");
+ assertThat(attributes.getExtension()).isEqualTo("txt");
+ assertThat(attributes.getLastModified()).isEqualTo(newDate);
+ assertThat(attributes.getSize()).isEqualTo(newSize);
+ assertThat(attributes.getMetadata()).containsEntry("updated", "true");
+ }
+
+ @Test
+ void testToBuilder() {
+ TurFileAttributes original = TurFileAttributes.builder()
+ .content("Original content")
+ .name("original.txt")
+ .title("Original Title")
+ .extension("txt")
+ .build();
+
+ TurFileAttributes modified = original.toBuilder()
+ .content("Modified content")
+ .title("Modified Title")
+ .build();
+
+ // Original should be unchanged
+ assertThat(original.getContent()).isEqualTo("Original content");
+ assertThat(original.getTitle()).isEqualTo("Original Title");
+ assertThat(original.getName()).isEqualTo("original.txt");
+
+ // Modified should have new values
+ assertThat(modified.getContent()).isEqualTo("Modified content");
+ assertThat(modified.getTitle()).isEqualTo("Modified Title");
+ assertThat(modified.getName()).isEqualTo("original.txt"); // Unchanged from original
+ }
+
+ @Test
+ void testToString() {
+ TurFileAttributes attributes = TurFileAttributes.builder()
+ .content("Test content")
+ .name("test.txt")
+ .title("Test File")
+ .extension("txt")
+ .build();
+
+ String toString = attributes.toString();
+
+ assertThat(toString).contains("content=Test content");
+ assertThat(toString).contains("name=test.txt");
+ assertThat(toString).contains("title=Test File");
+ assertThat(toString).contains("extension=txt");
+ }
+
+ @Test
+ void testMetadataManipulation() {
+ TurFileAttributes attributes = new TurFileAttributes();
+
+ // Add metadata
+ attributes.getMetadata().put("format", "PDF");
+ attributes.getMetadata().put("pages", "10");
+
+ assertThat(attributes.getMetadata()).hasSize(2);
+ assertThat(attributes.getMetadata()).containsEntry("format", "PDF");
+ assertThat(attributes.getMetadata()).containsEntry("pages", "10");
+
+ // Update metadata
+ attributes.getMetadata().put("pages", "12");
+
+ assertThat(attributes.getMetadata()).hasSize(2);
+ assertThat(attributes.getMetadata()).containsEntry("pages", "12");
+
+ // Remove metadata
+ attributes.getMetadata().remove("format");
+
+ assertThat(attributes.getMetadata()).hasSize(1);
+ assertThat(attributes.getMetadata()).doesNotContainKey("format");
+ assertThat(attributes.getMetadata()).containsEntry("pages", "12");
+ }
+
+ @Test
+ void testDefaultValues() {
+ TurFileAttributes attributes = TurFileAttributes.builder().build();
+
+ // Check that default values are properly set
+ assertThat(attributes.getSize()).isNotNull();
+ assertThat(attributes.getLastModified()).isNotNull();
+ assertThat(attributes.getMetadata()).isNotNull();
+ assertThat(attributes.getMetadata()).isEmpty();
+
+ // Check that lastModified is recent
+ long timeDiff = System.currentTimeMillis() - attributes.getLastModified().getTime();
+ assertThat(timeDiff).isLessThan(1000); // Should be created within last second
+ }
+}
\ No newline at end of file
diff --git a/turing-commons/src/test/java/com/viglet/turing/commons/file/TurFileSizeTest.java b/turing-commons/src/test/java/com/viglet/turing/commons/file/TurFileSizeTest.java
new file mode 100644
index 00000000000..c3b5aaf04cf
--- /dev/null
+++ b/turing-commons/src/test/java/com/viglet/turing/commons/file/TurFileSizeTest.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2016-2024 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If
+ * not, see .
+ */
+
+package com.viglet.turing.commons.file;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for TurFileSize.
+ *
+ * @author Alexandre Oliveira
+ * @since 0.3.9
+ */
+class TurFileSizeTest {
+
+ @Test
+ void testDefaultConstructor() {
+ TurFileSize fileSize = new TurFileSize();
+
+ assertThat(fileSize.getBytes()).isEqualTo(0.0f);
+ assertThat(fileSize.getKiloBytes()).isEqualTo(0.0f);
+ assertThat(fileSize.getMegaBytes()).isEqualTo(0.0f);
+ }
+
+ @Test
+ void testConstructorWithBytes() {
+ float bytes = 1024.0f;
+ TurFileSize fileSize = new TurFileSize(bytes);
+
+ assertThat(fileSize.getBytes()).isEqualTo(1024.0f);
+ assertThat(fileSize.getKiloBytes()).isEqualTo(1.0f);
+ assertThat(fileSize.getMegaBytes()).isEqualTo(0.0f);
+ }
+
+ @Test
+ void testLargeFileSize() {
+ float bytes = 1048576.0f; // 1 MB
+ TurFileSize fileSize = new TurFileSize(bytes);
+
+ assertThat(fileSize.getBytes()).isEqualTo(1048576.0f);
+ assertThat(fileSize.getKiloBytes()).isEqualTo(1024.0f);
+ assertThat(fileSize.getMegaBytes()).isEqualTo(1.0f);
+ }
+
+ @Test
+ void testVeryLargeFileSize() {
+ float bytes = 2147483648.0f; // 2 GB
+ TurFileSize fileSize = new TurFileSize(bytes);
+
+ assertThat(fileSize.getBytes()).isEqualTo(2147483648.0f);
+ assertThat(fileSize.getKiloBytes()).isEqualTo(2097152.0f);
+ assertThat(fileSize.getMegaBytes()).isEqualTo(2048.0f);
+ }
+
+ @Test
+ void testFractionalBytes() {
+ float bytes = 1536.0f; // 1.5 KB
+ TurFileSize fileSize = new TurFileSize(bytes);
+
+ assertThat(fileSize.getBytes()).isEqualTo(1536.0f);
+ assertThat(fileSize.getKiloBytes()).isEqualTo(1.5f);
+ // Very small megabyte values get rounded to 0.0 due to two decimal precision
+ assertThat(fileSize.getMegaBytes()).isEqualTo(0.0f);
+ }
+
+ @Test
+ void testSmallFileSize() {
+ float bytes = 512.5f;
+ TurFileSize fileSize = new TurFileSize(bytes);
+
+ assertThat(fileSize.getBytes()).isEqualTo(512.5f);
+ assertThat(fileSize.getKiloBytes()).isCloseTo(0.5f, org.assertj.core.data.Offset.offset(0.01f));
+ // Very small megabyte values get rounded to 0.0 due to two decimal precision
+ assertThat(fileSize.getMegaBytes()).isEqualTo(0.0f);
+ }
+
+ @Test
+ void testTwoDecimalPrecision() {
+ float bytes = 1000.0f / 3.0f; // Should result in 333.33... bytes
+ TurFileSize fileSize = new TurFileSize(bytes);
+
+ // Verify that values are rounded to two decimal places
+ assertThat(fileSize.getBytes()).isEqualTo(333.33f);
+ assertThat(fileSize.getKiloBytes()).isCloseTo(0.33f, org.assertj.core.data.Offset.offset(0.01f));
+ }
+
+ @Test
+ void testBuilder() {
+ TurFileSize fileSize = TurFileSize.builder()
+ .bytes(2048.0f)
+ .kiloBytes(2.0f)
+ .megaBytes(0.002f)
+ .build();
+
+ assertThat(fileSize.getBytes()).isEqualTo(2048.0f);
+ assertThat(fileSize.getKiloBytes()).isEqualTo(2.0f);
+ assertThat(fileSize.getMegaBytes()).isEqualTo(0.002f);
+ }
+
+ @Test
+ void testAllArgsConstructor() {
+ TurFileSize fileSize = new TurFileSize(1024.0f, 1.0f, 0.001f);
+
+ assertThat(fileSize.getBytes()).isEqualTo(1024.0f);
+ assertThat(fileSize.getKiloBytes()).isEqualTo(1.0f);
+ assertThat(fileSize.getMegaBytes()).isEqualTo(0.001f);
+ }
+
+ @Test
+ void testToString() {
+ TurFileSize fileSize = new TurFileSize(1024.0f);
+ String toString = fileSize.toString();
+
+ assertThat(toString).contains("bytes=1024.0");
+ assertThat(toString).contains("kiloBytes=1.0");
+ assertThat(toString).contains("megaBytes=0.0");
+ }
+
+ @Test
+ void testZeroBytes() {
+ TurFileSize fileSize = new TurFileSize(0.0f);
+
+ assertThat(fileSize.getBytes()).isEqualTo(0.0f);
+ assertThat(fileSize.getKiloBytes()).isEqualTo(0.0f);
+ assertThat(fileSize.getMegaBytes()).isEqualTo(0.0f);
+ }
+
+ @Test
+ void testRoundingBehavior() {
+ // Test rounding half up
+ float bytes = 1023.995f; // Should round up to 1024.0
+ TurFileSize fileSize = new TurFileSize(bytes);
+
+ // The exact value depends on float precision, but we can test the rounding behavior
+ assertThat(fileSize.getBytes()).isCloseTo(1024.0f, org.assertj.core.data.Offset.offset(0.01f));
+ }
+
+ @Test
+ void testCommonFileSizes() {
+ // Test some common file sizes
+
+ // 1 KB
+ TurFileSize oneKB = new TurFileSize(1024.0f);
+ assertThat(oneKB.getKiloBytes()).isEqualTo(1.0f);
+
+ // 500 KB
+ TurFileSize fiveHundredKB = new TurFileSize(512000.0f);
+ assertThat(fiveHundredKB.getKiloBytes()).isEqualTo(500.0f);
+
+ // 1.5 MB
+ TurFileSize oneMBHalf = new TurFileSize(1572864.0f);
+ assertThat(oneMBHalf.getMegaBytes()).isEqualTo(1.5f);
+
+ // 10 MB
+ TurFileSize tenMB = new TurFileSize(10485760.0f);
+ assertThat(tenMB.getMegaBytes()).isEqualTo(10.0f);
+ }
+}
\ No newline at end of file
diff --git a/turing-commons/src/test/java/com/viglet/turing/commons/sn/TurSNConfigTest.java b/turing-commons/src/test/java/com/viglet/turing/commons/sn/TurSNConfigTest.java
new file mode 100644
index 00000000000..40803a397b6
--- /dev/null
+++ b/turing-commons/src/test/java/com/viglet/turing/commons/sn/TurSNConfigTest.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2016-2025 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If
+ * not, see .
+ */
+
+package com.viglet.turing.commons.sn;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.Serializable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for TurSNConfig.
+ *
+ * @author Alexandre Oliveira
+ * @since 0.3.4
+ */
+class TurSNConfigTest {
+
+ @Test
+ void testDefaultConstructor() {
+ TurSNConfig config = new TurSNConfig();
+
+ // Default boolean value should be false
+ assertThat(config.isHlEnabled()).isFalse();
+ }
+
+ @Test
+ void testSetterAndGetter() {
+ TurSNConfig config = new TurSNConfig();
+
+ config.setHlEnabled(true);
+
+ assertThat(config.isHlEnabled()).isTrue();
+ }
+
+ @Test
+ void testSetterAndGetterFalse() {
+ TurSNConfig config = new TurSNConfig();
+
+ config.setHlEnabled(false);
+
+ assertThat(config.isHlEnabled()).isFalse();
+ }
+
+ @Test
+ void testToggleHlEnabled() {
+ TurSNConfig config = new TurSNConfig();
+
+ // Start with default (false)
+ assertThat(config.isHlEnabled()).isFalse();
+
+ // Toggle to true
+ config.setHlEnabled(true);
+ assertThat(config.isHlEnabled()).isTrue();
+
+ // Toggle back to false
+ config.setHlEnabled(false);
+ assertThat(config.isHlEnabled()).isFalse();
+ }
+
+ @Test
+ void testImplementsSerializable() {
+ TurSNConfig config = new TurSNConfig();
+
+ assertThat(config).isInstanceOf(Serializable.class);
+ }
+}
\ No newline at end of file
diff --git a/turing-commons/src/test/java/com/viglet/turing/commons/sn/bean/TurSNSiteSearchDocumentBeanTest.java b/turing-commons/src/test/java/com/viglet/turing/commons/sn/bean/TurSNSiteSearchDocumentBeanTest.java
new file mode 100644
index 00000000000..10a948c24dd
--- /dev/null
+++ b/turing-commons/src/test/java/com/viglet/turing/commons/sn/bean/TurSNSiteSearchDocumentBeanTest.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2016-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.viglet.turing.commons.sn.bean;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.Serializable;
+import java.util.*;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for TurSNSiteSearchDocumentBean.
+ *
+ * @author Alexandre Oliveira
+ * @since 0.3.4
+ */
+class TurSNSiteSearchDocumentBeanTest {
+
+ @Test
+ void testBuilderPattern() {
+ List metadata = Arrays.asList(
+ TurSNSiteSearchDocumentMetadataBean.builder().build()
+ );
+ Map fields = new HashMap<>();
+ fields.put("title", "Test Document");
+ fields.put("content", "Test content");
+
+ TurSNSiteSearchDocumentBean document = TurSNSiteSearchDocumentBean.builder()
+ .source("test-source")
+ .elevate(true)
+ .metadata(metadata)
+ .fields(fields)
+ .build();
+
+ assertThat(document.getSource()).isEqualTo("test-source");
+ assertThat(document.isElevate()).isTrue();
+ assertThat(document.getMetadata()).isEqualTo(metadata);
+ assertThat(document.getFields()).isEqualTo(fields);
+ }
+
+ @Test
+ void testSettersAndGetters() {
+ // Use builder since there's no default constructor
+ TurSNSiteSearchDocumentBean document = TurSNSiteSearchDocumentBean.builder().build();
+
+ List metadata = new ArrayList<>();
+ Map fields = new HashMap<>();
+ fields.put("id", "123");
+ fields.put("score", 0.95);
+
+ document.setSource("web-source");
+ document.setElevate(false);
+ document.setMetadata(metadata);
+ document.setFields(fields);
+
+ assertThat(document.getSource()).isEqualTo("web-source");
+ assertThat(document.isElevate()).isFalse();
+ assertThat(document.getMetadata()).isEqualTo(metadata);
+ assertThat(document.getFields()).isEqualTo(fields);
+ }
+
+ @Test
+ void testDefaultConstructor() {
+ // Use builder since there's no default constructor
+ TurSNSiteSearchDocumentBean document = TurSNSiteSearchDocumentBean.builder().build();
+
+ assertThat(document.getSource()).isNull();
+ assertThat(document.isElevate()).isFalse(); // default boolean value
+ assertThat(document.getMetadata()).isNull();
+ assertThat(document.getFields()).isNull();
+ }
+
+ @Test
+ void testBuilderWithNullValues() {
+ TurSNSiteSearchDocumentBean document = TurSNSiteSearchDocumentBean.builder()
+ .source(null)
+ .elevate(false)
+ .metadata(null)
+ .fields(null)
+ .build();
+
+ assertThat(document.getSource()).isNull();
+ assertThat(document.isElevate()).isFalse();
+ assertThat(document.getMetadata()).isNull();
+ assertThat(document.getFields()).isNull();
+ }
+
+ @Test
+ void testImplementsSerializable() {
+ TurSNSiteSearchDocumentBean document = TurSNSiteSearchDocumentBean.builder().build();
+
+ assertThat(document).isInstanceOf(Serializable.class);
+ }
+
+ @Test
+ void testFieldsManipulation() {
+ TurSNSiteSearchDocumentBean document = TurSNSiteSearchDocumentBean.builder().build();
+
+ Map fields = new HashMap<>();
+ document.setFields(fields);
+
+ // Add fields
+ document.getFields().put("title", "Document Title");
+ document.getFields().put("author", "John Doe");
+ document.getFields().put("date", new Date());
+
+ assertThat(document.getFields()).hasSize(3);
+ assertThat(document.getFields()).containsKey("title");
+ assertThat(document.getFields()).containsKey("author");
+ assertThat(document.getFields()).containsKey("date");
+ assertThat(document.getFields().get("title")).isEqualTo("Document Title");
+ }
+
+ @Test
+ void testMetadataManipulation() {
+ TurSNSiteSearchDocumentBean document = TurSNSiteSearchDocumentBean.builder().build();
+
+ List metadata = new ArrayList<>();
+ document.setMetadata(metadata);
+
+ // Add metadata
+ TurSNSiteSearchDocumentMetadataBean meta1 = TurSNSiteSearchDocumentMetadataBean.builder().build();
+ TurSNSiteSearchDocumentMetadataBean meta2 = TurSNSiteSearchDocumentMetadataBean.builder().build();
+
+ document.getMetadata().add(meta1);
+ document.getMetadata().add(meta2);
+
+ assertThat(document.getMetadata()).hasSize(2);
+ assertThat(document.getMetadata()).contains(meta1, meta2);
+ }
+
+ @Test
+ void testElevateToggle() {
+ TurSNSiteSearchDocumentBean document = TurSNSiteSearchDocumentBean.builder().build();
+
+ // Default should be false
+ assertThat(document.isElevate()).isFalse();
+
+ // Set to true
+ document.setElevate(true);
+ assertThat(document.isElevate()).isTrue();
+
+ // Set back to false
+ document.setElevate(false);
+ assertThat(document.isElevate()).isFalse();
+ }
+
+ @Test
+ void testComplexFieldTypes() {
+ TurSNSiteSearchDocumentBean document = TurSNSiteSearchDocumentBean.builder().build();
+
+ Map fields = new HashMap<>();
+
+ // Test various field types
+ fields.put("stringField", "text value");
+ fields.put("intField", 42);
+ fields.put("doubleField", 3.14);
+ fields.put("booleanField", true);
+ fields.put("listField", Arrays.asList("item1", "item2", "item3"));
+ fields.put("mapField", Collections.singletonMap("nested", "value"));
+
+ document.setFields(fields);
+
+ assertThat(document.getFields().get("stringField")).isEqualTo("text value");
+ assertThat(document.getFields().get("intField")).isEqualTo(42);
+ assertThat(document.getFields().get("doubleField")).isEqualTo(3.14);
+ assertThat(document.getFields().get("booleanField")).isEqualTo(true);
+ assertThat(document.getFields().get("listField")).isInstanceOf(List.class);
+ assertThat(document.getFields().get("mapField")).isInstanceOf(Map.class);
+ }
+}
\ No newline at end of file
diff --git a/turing-commons/src/test/java/com/viglet/turing/commons/sn/bean/TurSNSiteSearchDocumentMetadataBeanTest.java b/turing-commons/src/test/java/com/viglet/turing/commons/sn/bean/TurSNSiteSearchDocumentMetadataBeanTest.java
new file mode 100644
index 00000000000..7360ac15874
--- /dev/null
+++ b/turing-commons/src/test/java/com/viglet/turing/commons/sn/bean/TurSNSiteSearchDocumentMetadataBeanTest.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2016-2021 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.viglet.turing.commons.sn.bean;
+
+import org.junit.jupiter.api.Test;
+
+import java.io.Serializable;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for TurSNSiteSearchDocumentMetadataBean.
+ *
+ * @author Alexandre Oliveira
+ * @since 0.3.4
+ */
+class TurSNSiteSearchDocumentMetadataBeanTest {
+
+ @Test
+ void testDefaultConstructor() {
+ TurSNSiteSearchDocumentMetadataBean metadata = new TurSNSiteSearchDocumentMetadataBean();
+
+ assertThat(metadata.getHref()).isNull();
+ assertThat(metadata.getText()).isNull();
+ }
+
+ @Test
+ void testAllArgsConstructor() {
+ String href = "https://example.com/document/123";
+ String text = "Example Document Title";
+
+ TurSNSiteSearchDocumentMetadataBean metadata =
+ new TurSNSiteSearchDocumentMetadataBean(href, text);
+
+ assertThat(metadata.getHref()).isEqualTo(href);
+ assertThat(metadata.getText()).isEqualTo(text);
+ }
+
+ @Test
+ void testBuilderPattern() {
+ TurSNSiteSearchDocumentMetadataBean metadata = TurSNSiteSearchDocumentMetadataBean.builder()
+ .href("https://viglet.com")
+ .text("Viglet Turing")
+ .build();
+
+ assertThat(metadata.getHref()).isEqualTo("https://viglet.com");
+ assertThat(metadata.getText()).isEqualTo("Viglet Turing");
+ }
+
+ @Test
+ void testBuilderWithNullValues() {
+ TurSNSiteSearchDocumentMetadataBean metadata = TurSNSiteSearchDocumentMetadataBean.builder()
+ .href(null)
+ .text(null)
+ .build();
+
+ assertThat(metadata.getHref()).isNull();
+ assertThat(metadata.getText()).isNull();
+ }
+
+ @Test
+ void testSettersAndGetters() {
+ TurSNSiteSearchDocumentMetadataBean metadata = new TurSNSiteSearchDocumentMetadataBean();
+
+ metadata.setHref("https://example.org/page");
+ metadata.setText("Sample Page");
+
+ assertThat(metadata.getHref()).isEqualTo("https://example.org/page");
+ assertThat(metadata.getText()).isEqualTo("Sample Page");
+ }
+
+ @Test
+ void testToBuilder() {
+ TurSNSiteSearchDocumentMetadataBean original = TurSNSiteSearchDocumentMetadataBean.builder()
+ .href("https://original.com")
+ .text("Original Text")
+ .build();
+
+ TurSNSiteSearchDocumentMetadataBean modified = original.toBuilder()
+ .text("Modified Text")
+ .build();
+
+ // Original should remain unchanged
+ assertThat(original.getHref()).isEqualTo("https://original.com");
+ assertThat(original.getText()).isEqualTo("Original Text");
+
+ // Modified should have updated text but same href
+ assertThat(modified.getHref()).isEqualTo("https://original.com");
+ assertThat(modified.getText()).isEqualTo("Modified Text");
+ }
+
+ @Test
+ void testImplementsSerializable() {
+ TurSNSiteSearchDocumentMetadataBean metadata = new TurSNSiteSearchDocumentMetadataBean();
+
+ assertThat(metadata).isInstanceOf(Serializable.class);
+ }
+
+ @Test
+ void testUpdateFields() {
+ TurSNSiteSearchDocumentMetadataBean metadata = new TurSNSiteSearchDocumentMetadataBean();
+
+ // Start with null values
+ assertThat(metadata.getHref()).isNull();
+ assertThat(metadata.getText()).isNull();
+
+ // Set initial values
+ metadata.setHref("https://first.com");
+ metadata.setText("First Text");
+
+ assertThat(metadata.getHref()).isEqualTo("https://first.com");
+ assertThat(metadata.getText()).isEqualTo("First Text");
+
+ // Update values
+ metadata.setHref("https://second.com");
+ metadata.setText("Second Text");
+
+ assertThat(metadata.getHref()).isEqualTo("https://second.com");
+ assertThat(metadata.getText()).isEqualTo("Second Text");
+ }
+
+ @Test
+ void testEmptyStringValues() {
+ TurSNSiteSearchDocumentMetadataBean metadata = TurSNSiteSearchDocumentMetadataBean.builder()
+ .href("")
+ .text("")
+ .build();
+
+ assertThat(metadata.getHref()).isEmpty();
+ assertThat(metadata.getText()).isEmpty();
+ }
+
+ @Test
+ void testLongUrlAndText() {
+ String longUrl = "https://example.com/very/long/path/to/document/with/many/segments/and/parameters?param1=value1¶m2=value2¶m3=value3";
+ String longText = "This is a very long document title that might contain multiple sentences and special characters like émotions, números, and símbolos.";
+
+ TurSNSiteSearchDocumentMetadataBean metadata = TurSNSiteSearchDocumentMetadataBean.builder()
+ .href(longUrl)
+ .text(longText)
+ .build();
+
+ assertThat(metadata.getHref()).isEqualTo(longUrl);
+ assertThat(metadata.getText()).isEqualTo(longText);
+ assertThat(metadata.getHref().length()).isGreaterThan(100);
+ assertThat(metadata.getText().length()).isGreaterThan(100);
+ }
+
+ @Test
+ void testSpecialCharacters() {
+ String specialHref = "https://example.com/документ/文档/مستند";
+ String specialText = "Document with émotions (1), números [2], and símbolos {3}";
+
+ TurSNSiteSearchDocumentMetadataBean metadata = new TurSNSiteSearchDocumentMetadataBean();
+ metadata.setHref(specialHref);
+ metadata.setText(specialText);
+
+ assertThat(metadata.getHref()).isEqualTo(specialHref);
+ assertThat(metadata.getText()).isEqualTo(specialText);
+ }
+}
\ No newline at end of file
diff --git a/turing-commons/src/test/java/com/viglet/turing/commons/utils/TurCommonsUtilsTest.java b/turing-commons/src/test/java/com/viglet/turing/commons/utils/TurCommonsUtilsTest.java
new file mode 100644
index 00000000000..55354401e33
--- /dev/null
+++ b/turing-commons/src/test/java/com/viglet/turing/commons/utils/TurCommonsUtilsTest.java
@@ -0,0 +1,348 @@
+/*
+ * Copyright (C) 2016-2024 the original author or authors.
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the
+ * GNU General Public License as published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program. If
+ * not, see .
+ */
+
+package com.viglet.turing.commons.utils;
+
+import org.apache.commons.collections4.KeyValue;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Locale;
+import java.util.Optional;
+
+import static org.assertj.core.api.Assertions.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * Unit tests for TurCommonsUtils.
+ *
+ * @author Alexandre Oliveira
+ * @since 0.3.6
+ */
+class TurCommonsUtilsTest {
+
+ @Test
+ void testGetKeyValueFromColonValid() {
+ String input = "key:value";
+ Optional> result = TurCommonsUtils.getKeyValueFromColon(input);
+
+ assertThat(result).isPresent();
+ assertThat(result.get().getKey()).isEqualTo("key");
+ assertThat(result.get().getValue()).isEqualTo("value");
+ }
+
+ @Test
+ void testGetKeyValueFromColonWithMultipleColons() {
+ String input = "key:value:extra";
+ Optional> result = TurCommonsUtils.getKeyValueFromColon(input);
+
+ assertThat(result).isPresent();
+ assertThat(result.get().getKey()).isEqualTo("key");
+ assertThat(result.get().getValue()).isEqualTo("value:extra");
+ }
+
+ @Test
+ void testGetKeyValueFromColonNoColon() {
+ String input = "keyvalue";
+ Optional> result = TurCommonsUtils.getKeyValueFromColon(input);
+
+ assertThat(result).isEmpty();
+ }
+
+ @Test
+ void testGetKeyValueFromColonEmptyValue() {
+ String input = "key:";
+ Optional> result = TurCommonsUtils.getKeyValueFromColon(input);
+
+ // Based on the actual implementation, this returns empty when there's only one part after split
+ assertThat(result).isEmpty();
+ }
+
+ @Test
+ void testIsValidUrlValidUrl() throws MalformedURLException {
+ URL validUrl = new URL("https://www.example.com");
+ boolean result = TurCommonsUtils.isValidUrl(validUrl);
+
+ assertThat(result).isTrue();
+ }
+
+ @Test
+ void testIsValidUrlLocalUrl() throws MalformedURLException {
+ URL localUrl = new URL("http://localhost:8080/api");
+ boolean result = TurCommonsUtils.isValidUrl(localUrl);
+
+ assertThat(result).isTrue();
+ }
+
+ @Test
+ void testIsValidUrlFileUrl() throws MalformedURLException {
+ URL fileUrl = new URL("file:///tmp/test.txt");
+ boolean result = TurCommonsUtils.isValidUrl(fileUrl);
+
+ // Based on the actual behavior, file URLs are considered invalid by the validator
+ assertThat(result).isFalse();
+ }
+
+ @Test
+ void testHtml2Text() {
+ String html = "
This is a test with HTML tags.
";
+ String result = TurCommonsUtils.html2Text(html);
+
+ assertThat(result).isEqualTo("This is a test with HTML tags.");
+ }
+
+ @Test
+ void testHtml2TextWithComplexHtml() {
+ String html = "