diff --git a/pom.xml b/pom.xml
index d5e071f..d7d5242 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,96 +1,181 @@
-
-
- 4.0.0
-
- org.springframework.boot
- spring-boot-starter-parent
- 3.0.6
-
-
- com.medeiros
- SPRINGProject
- 0.0.1-SNAPSHOT
- SPRINGProject
- Demo project for Spring Boot
-
- 20
-
- 6.0.3
-
-
-
- org.springframework.boot
- spring-boot-starter-data-jpa
-
-
- org.springframework.boot
- spring-boot-starter-web
-
-
-
- org.springframework.boot
- spring-boot-devtools
- runtime
- true
-
-
- com.mysql
- mysql-connector-j
- runtime
-
-
- org.springframework.boot
- spring-boot-starter-test
- test
-
-
-
- org.springframework.boot
- spring-boot-starter-thymeleaf
- 3.0.6
-
-
-
- org.springframework.boot
- spring-boot-starter-security
-
-
-
- io.jsonwebtoken
- jjwt-api
- 0.11.5
-
-
-
-
-
-
- org.springframework.security
- spring-security-core
- 6.0.3
-
-
-
-
-
-
- io.jsonwebtoken
- jjwt-impl
- 0.11.5
- runtime
-
-
-
-
-
-
-
-
- org.springframework.boot
- spring-boot-maven-plugin
-
-
-
-
-
+
+
+ 4.0.0
+
+ org.springframework.boot
+ spring-boot-starter-parent
+ 3.0.6
+
+
+
+ com.medeiros
+ SPRINGProject
+ 0.0.1-SNAPSHOT
+ SPRINGProject
+ Demo project for Spring Boot
+
+ 20
+
+ 6.0.3
+
+
+
+ org.springframework.boot
+ spring-boot-starter-data-jpa
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-devtools
+ runtime
+ true
+
+
+ com.mysql
+ mysql-connector-j
+ runtime
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+ 3.0.6
+
+
+ org.springframework.boot
+ spring-boot-starter-security
+
+
+
+ io.jsonwebtoken
+ jjwt-api
+ 0.11.5
+
+
+
+ org.springframework.security
+ spring-security-core
+ 6.0.3
+
+
+
+
+ io.jsonwebtoken
+ jjwt-impl
+ 0.11.5
+ runtime
+
+
+ org.mockito
+ mockito-junit-jupiter
+ 2.23.4
+ test
+
+
+
+ io.spring.javaformat
+ spring-javaformat-formatter
+ 0.0.40
+
+
+
+ io.jsonwebtoken
+ jjwt-jackson
+ 0.11.5
+ runtime
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ 5.9.2
+ test
+
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ 5.9.2
+ test
+
+
+
+ org.mockito
+ mockito-core
+ 5.2.0
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.11
+
+
+
+ prepare-agent
+
+
+
+ report
+ test
+
+ report
+
+
+ coverageReport
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 3.2.5
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-report-plugin
+ 3.2.5
+
+ testReport
+
+
+
+
+ org.apache.maven.plugins
+ maven-site-plugin
+ 2.1
+
+ testReport
+
+
+
+
+ io.spring.javaformat
+ spring-javaformat-maven-plugin
+ 0.0.40
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/test/java/com/medeiros/SPRINGProject/Controllers/UserAccountControllerUpdateUserByIdTest.java b/src/test/java/com/medeiros/SPRINGProject/Controllers/UserAccountControllerUpdateUserByIdTest.java
new file mode 100644
index 0000000..b45d7a3
--- /dev/null
+++ b/src/test/java/com/medeiros/SPRINGProject/Controllers/UserAccountControllerUpdateUserByIdTest.java
@@ -0,0 +1,209 @@
+
+// ********RoostGPT********
+/*
+Test generated by RoostGPT for test java-music using AI Type Claude AI and AI Model claude-3-7-sonnet-20250219
+
+ROOST_METHOD_HASH=updateUserById_45a90e9627
+ROOST_METHOD_SIG_HASH=updateUserById_9cf5a84c94
+
+Scenario 1: Successfully Update Existing User
+
+Details:
+ TestName: successfullyUpdateExistingUser
+ Description: Verify that the method correctly updates an existing user's credentials and returns a success message.
+
+Execution:
+ Arrange:
+ - Mock UserAccRepository to return a valid User_Credentials object when findById is called with a valid ID
+ - Create a User_Credentials object with initial values
+ - Prepare new values for email, password, and username
+
+ Act:
+ - Call updateUserById with valid ID and new credential values
+
+ Assert:
+ - Verify that the returned message is "Usuário Salvo"
+ - Verify that UserAccRepository.save was called with the updated User_Credentials object
+ - Verify that the User_Credentials object was updated with the new values
+
+Validation:
+ This test confirms that the method correctly updates user credentials when a valid user ID is provided. It ensures that the repository's save method is called with the updated user object and that the appropriate success message is returned.
+
+*/
+
+// ********RoostGPT********
+
+package com.medeiros.SPRINGProject.Controllers;
+
+import com.medeiros.SPRINGProject.Models.*;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
+import org.junit.jupiter.api.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+import java.time.LocalDateTime;
+import java.util.Objects;
+import java.util.Optional;
+
+@ExtendWith(MockitoExtension.class)
+public class UserAccountControllerUpdateUserByIdTest {
+
+ @Mock
+ private UserAccRepository UserAccRepo;
+
+ @Mock
+ private UserInfoRepository UserInfoRepo;
+
+ @Mock
+ private LogRepository Log;
+
+ @InjectMocks
+ private UserAccountController userAccountController;
+
+ private User_Credentials testUser;
+
+ @BeforeEach
+ void setUp() {
+ testUser = new User_Credentials();
+ testUser.setId(1);
+ testUser.setEmail("old@example.com");
+ testUser.setPassword("oldPassword");
+ testUser.setUsername("oldUsername");
+ }
+
+ @Test
+ @Tag("valid")
+ void successfullyUpdateExistingUser() {
+ // Arrange
+ String id = "1";
+ String newEmail = "new@example.com";
+ String newPassword = "newPassword";
+ String newUsername = "newUsername";
+
+ when(UserAccRepo.findById(1)).thenReturn(testUser);
+
+ // Act
+ String result = userAccountController.updateUserById(id, newEmail, newPassword, newUsername);
+
+ // Assert
+ assertEquals("Usuário Salvo", result);
+ assertEquals(newEmail, testUser.getEmail());
+ assertEquals(newPassword, testUser.getPassword());
+ assertEquals(newUsername, testUser.getUsername());
+ verify(UserAccRepo).save(testUser);
+ }
+
+ @Test
+ @Tag("invalid")
+ void userNotFoundReturnsErrorMessage() {
+ // Arrange
+ String id = "999";
+ String email = "test@example.com";
+ String password = "password";
+ String username = "username";
+
+ when(UserAccRepo.findById(999)).thenReturn(null);
+
+ // Act
+ String result = userAccountController.updateUserById(id, email, password, username);
+
+ // Assert
+ assertEquals("User não encontrado", result);
+ verify(UserAccRepo, never()).save(any());
+ }
+
+ @Test
+ @Tag("invalid")
+ void invalidIdFormatThrowsException() {
+ // Arrange
+ String id = "invalid";
+ String email = "test@example.com";
+ String password = "password";
+ String username = "username";
+
+ // Act & Assert
+ try {
+ userAccountController.updateUserById(id, email, password, username);
+ }
+ catch (NumberFormatException e) {
+ // Expected exception
+ verify(UserAccRepo, never()).findById(anyInt());
+ verify(UserAccRepo, never()).save(any());
+ }
+ }
+
+ @Test
+ @Tag("boundary")
+ void updateUserWithEmptyFields() {
+ // Arrange
+ String id = "1";
+ String emptyEmail = "";
+ String emptyPassword = "";
+ String emptyUsername = "";
+
+ when(UserAccRepo.findById(1)).thenReturn(testUser);
+
+ // Act
+ String result = userAccountController.updateUserById(id, emptyEmail, emptyPassword, emptyUsername);
+
+ // Assert
+ assertEquals("Usuário Salvo", result);
+ assertEquals(emptyEmail, testUser.getEmail());
+ assertEquals(emptyPassword, testUser.getPassword());
+ assertEquals(emptyUsername, testUser.getUsername());
+ verify(UserAccRepo).save(testUser);
+ }
+
+ @Test
+ @Tag("boundary")
+ void updateUserWithMaxIntegerId() {
+ // Arrange
+ String id = String.valueOf(Integer.MAX_VALUE);
+ String email = "test@example.com";
+ String password = "password";
+ String username = "username";
+
+ User_Credentials maxIdUser = new User_Credentials();
+ maxIdUser.setId(Integer.MAX_VALUE);
+
+ when(UserAccRepo.findById(Integer.MAX_VALUE)).thenReturn(maxIdUser);
+
+ // Act
+ String result = userAccountController.updateUserById(id, email, password, username);
+
+ // Assert
+ assertEquals("Usuário Salvo", result);
+ verify(UserAccRepo).save(any(User_Credentials.class));
+ }
+
+ @Test
+ @Tag("integration")
+ void updateUserIntegrationTest() {
+ // Arrange
+ String id = "1";
+ String newEmail = "integration@example.com";
+ String newPassword = "integrationPassword";
+ String newUsername = "integrationUser";
+
+ when(UserAccRepo.findById(1)).thenReturn(testUser);
+
+ // Act
+ String result = userAccountController.updateUserById(id, newEmail, newPassword, newUsername);
+
+ // Assert
+ assertEquals("Usuário Salvo", result);
+ assertEquals(newEmail, testUser.getEmail());
+ assertEquals(newPassword, testUser.getPassword());
+ assertEquals(newUsername, testUser.getUsername());
+ verify(UserAccRepo).save(testUser);
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/medeiros/SPRINGProject/algorithm/AlgorithmBlenderAlgorithmCalcTest.java b/src/test/java/com/medeiros/SPRINGProject/algorithm/AlgorithmBlenderAlgorithmCalcTest.java
new file mode 100644
index 0000000..1c88f2d
--- /dev/null
+++ b/src/test/java/com/medeiros/SPRINGProject/algorithm/AlgorithmBlenderAlgorithmCalcTest.java
@@ -0,0 +1,232 @@
+
+// ********RoostGPT********
+/*
+Test generated by RoostGPT for test java-music using AI Type Claude AI and AI Model claude-3-7-sonnet-20250219
+
+ROOST_METHOD_HASH=algorithmCalc_e489e5c1fc
+ROOST_METHOD_SIG_HASH=algorithmCalc_009085eae1
+
+Scenario 1: Calculate Points for a Single Music Item
+
+Details:
+ TestName: calculatePointsForSingleMusic
+ Description: Verify that the algorithmCalc method correctly calculates and stores rhythm points for a single music item based on its likes and comments.
+
+Execution:
+ Arrange:
+ - Create a mock MusicModel with a known number of likes, comments, and music name
+ - Set up the expected behavior for AD.rithmPointsByLike() and AD.rithmPointsByComents() methods
+ - Create a list containing only this single music item
+
+ Act:
+ - Call the algorithmCalc method with the created list
+
+ Assert:
+ - Verify that the returned HashMap contains exactly one entry
+ - Verify that the key matches the music name
+ - Verify that the value matches the expected sum of like points and comment points
+
+Validation:
+ This test confirms that the basic calculation logic works correctly for a single item. It ensures that the method properly retrieves likes and comments from the music model, calculates points using the algorithm data methods, and stores the result with the correct music name as the key.
+
+*/
+
+// ********RoostGPT********
+
+package com.medeiros.SPRINGProject.algorithm;
+
+import com.medeiros.SPRINGProject.Models.MusicModel;
+import com.medeiros.SPRINGProject.utils.hashMapFunctions;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+import org.junit.jupiter.api.*;
+
+@ExtendWith(MockitoExtension.class)
+public class AlgorithmBlenderAlgorithmCalcTest {
+
+ private algorithmBlender algorithmBlender;
+
+ @Mock
+ private algorithmData mockAD;
+
+ @Mock
+ private MusicModel mockMusic;
+
+ @BeforeEach
+ void setUp() {
+ algorithmBlender = new algorithmBlender();
+ // Using reflection to set the mocked algorithmData
+ try {
+ java.lang.reflect.Field field = algorithmBlender.getClass().getDeclaredField("AD");
+ field.setAccessible(true);
+ field.set(algorithmBlender, mockAD);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ @Tag("valid")
+ void calculatePointsForSingleMusic() {
+ // Arrange
+ when(mockMusic.getNumberOfLikes()).thenReturn(10);
+ when(mockMusic.getNumberOfComents()).thenReturn(5);
+ when(mockMusic.getMusicName()).thenReturn("Test Song");
+
+ when(mockAD.rithmPointsByLike(10)).thenReturn(100);
+ when(mockAD.rithmPointsByComents(5)).thenReturn(75);
+
+ List musicList = new ArrayList<>();
+ musicList.add(mockMusic);
+
+ // Act
+ Map result = algorithmBlender.algorithmCalc(musicList);
+
+ // Assert
+ assertEquals(1, result.size());
+ assertTrue(result.containsKey("Test Song"));
+ assertEquals(175, result.get("Test Song"));
+
+ verify(mockMusic).getNumberOfLikes();
+ verify(mockMusic).getNumberOfComents();
+ verify(mockMusic).getMusicName();
+ verify(mockAD).rithmPointsByLike(10);
+ verify(mockAD).rithmPointsByComents(5);
+ }
+
+ @Test
+ @Tag("valid")
+ void calculatePointsForMultipleMusics() {
+ // Arrange
+ MusicModel music1 = mock(MusicModel.class);
+ MusicModel music2 = mock(MusicModel.class);
+
+ when(music1.getNumberOfLikes()).thenReturn(10);
+ when(music1.getNumberOfComents()).thenReturn(5);
+ when(music1.getMusicName()).thenReturn("Song 1");
+
+ when(music2.getNumberOfLikes()).thenReturn(20);
+ when(music2.getNumberOfComents()).thenReturn(10);
+ when(music2.getMusicName()).thenReturn("Song 2");
+
+ when(mockAD.rithmPointsByLike(10)).thenReturn(100);
+ when(mockAD.rithmPointsByComents(5)).thenReturn(75);
+ when(mockAD.rithmPointsByLike(20)).thenReturn(200);
+ when(mockAD.rithmPointsByComents(10)).thenReturn(150);
+
+ List musicList = new ArrayList<>();
+ musicList.add(music1);
+ musicList.add(music2);
+
+ // Act
+ Map result = algorithmBlender.algorithmCalc(musicList);
+
+ // Assert
+ assertEquals(2, result.size());
+ assertEquals(175, result.get("Song 1"));
+ assertEquals(350, result.get("Song 2"));
+ }
+
+ @Test
+ @Tag("boundary")
+ void calculatePointsForEmptyList() {
+ // Arrange
+ List emptyList = new ArrayList<>();
+
+ // Act
+ Map result = algorithmBlender.algorithmCalc(emptyList);
+
+ // Assert
+ assertNotNull(result);
+ assertTrue(result.isEmpty());
+ }
+
+ @Test
+ @Tag("boundary")
+ void calculatePointsForZeroLikesAndComments() {
+ // Arrange
+ when(mockMusic.getNumberOfLikes()).thenReturn(0);
+ when(mockMusic.getNumberOfComents()).thenReturn(0);
+ when(mockMusic.getMusicName()).thenReturn("Zero Engagement Song");
+
+ when(mockAD.rithmPointsByLike(0)).thenReturn(0);
+ when(mockAD.rithmPointsByComents(0)).thenReturn(0);
+
+ List musicList = new ArrayList<>();
+ musicList.add(mockMusic);
+
+ // Act
+ Map result = algorithmBlender.algorithmCalc(musicList);
+
+ // Assert
+ assertEquals(1, result.size());
+ assertEquals(0, result.get("Zero Engagement Song"));
+ }
+
+ @Test
+ @Tag("valid")
+ void calculatePointsForDuplicateMusicNames() {
+ // Arrange
+ MusicModel music1 = mock(MusicModel.class);
+ MusicModel music2 = mock(MusicModel.class);
+
+ when(music1.getNumberOfLikes()).thenReturn(10);
+ when(music1.getNumberOfComents()).thenReturn(5);
+ when(music1.getMusicName()).thenReturn("Same Song Name");
+
+ when(music2.getNumberOfLikes()).thenReturn(20);
+ when(music2.getNumberOfComents()).thenReturn(10);
+ when(music2.getMusicName()).thenReturn("Same Song Name");
+
+ when(mockAD.rithmPointsByLike(10)).thenReturn(100);
+ when(mockAD.rithmPointsByComents(5)).thenReturn(75);
+ when(mockAD.rithmPointsByLike(20)).thenReturn(200);
+ when(mockAD.rithmPointsByComents(10)).thenReturn(150);
+
+ List musicList = new ArrayList<>();
+ musicList.add(music1);
+ musicList.add(music2);
+
+ // Act
+ Map result = algorithmBlender.algorithmCalc(musicList);
+
+ // Assert
+ assertEquals(1, result.size());
+ assertEquals(350, result.get("Same Song Name"));
+ }
+
+ @Test
+ @Tag("boundary")
+ void calculatePointsForNegativeLikesAndComments() {
+ // Arrange
+ when(mockMusic.getNumberOfLikes()).thenReturn(-5);
+ when(mockMusic.getNumberOfComents()).thenReturn(-3);
+ when(mockMusic.getMusicName()).thenReturn("Negative Engagement Song");
+
+ when(mockAD.rithmPointsByLike(-5)).thenReturn(-50);
+ when(mockAD.rithmPointsByComents(-3)).thenReturn(-45);
+
+ List musicList = new ArrayList<>();
+ musicList.add(mockMusic);
+
+ // Act
+ Map result = algorithmBlender.algorithmCalc(musicList);
+
+ // Assert
+ assertEquals(1, result.size());
+ assertEquals(-95, result.get("Negative Engagement Song"));
+ }
+
+}
\ No newline at end of file
diff --git a/src/test/java/com/medeiros/SPRINGProject/utils/HashMapFunctionsOrdenarHashMapPorValorTest.java b/src/test/java/com/medeiros/SPRINGProject/utils/HashMapFunctionsOrdenarHashMapPorValorTest.java
new file mode 100644
index 0000000..8a8911b
--- /dev/null
+++ b/src/test/java/com/medeiros/SPRINGProject/utils/HashMapFunctionsOrdenarHashMapPorValorTest.java
@@ -0,0 +1,213 @@
+
+// ********RoostGPT********
+/*
+Test generated by RoostGPT for test java-music using AI Type Claude AI and AI Model claude-3-7-sonnet-20250219
+
+ROOST_METHOD_HASH=ordenarHashMapPorValor_29e282f5b3
+ROOST_METHOD_SIG_HASH=ordenarHashMapPorValor_afd4884fe1
+
+Scenario 1: Sort HashMap with Multiple Entries in Descending Order
+
+Details:
+ TestName: sortHashMapWithMultipleEntriesInDescendingOrder
+ Description: Verify that the method correctly sorts a HashMap with multiple entries in descending order based on their integer values.
+
+Execution:
+ Arrange: Create a HashMap with multiple string keys and integer values in random order.
+ Act: Call the ordenarHashMapPorValor method with the created HashMap.
+ Assert: Verify that the returned HashMap contains all entries sorted by their values in descending order.
+
+Validation:
+ The test confirms that the method properly sorts entries from highest to lowest value. This is the core functionality of the method and ensures that data is presented in the expected priority order.
+
+*/
+
+// ********RoostGPT********
+
+package com.medeiros.SPRINGProject.utils;
+
+import org.junit.jupiter.api.DisplayName;
+import org.junit.jupiter.api.Tag;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.stream.Stream;
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.*;
+import java.util.*;
+
+class HashMapFunctionsOrdenarHashMapPorValorTest {
+
+ @Test
+ @Tag("valid")
+ @DisplayName("Sort HashMap with Multiple Entries in Descending Order")
+ void sortHashMapWithMultipleEntriesInDescendingOrder() {
+ // Arrange
+ HashMap hashMap = new HashMap<>();
+ hashMap.put("apple", 5);
+ hashMap.put("banana", 10);
+ hashMap.put("cherry", 7);
+ hashMap.put("date", 3);
+ hashMap.put("elderberry", 8);
+ // Act
+ HashMap result = hashMapFunctions.ordenarHashMapPorValor(hashMap);
+ // Assert
+ assertEquals(5, result.size());
+
+ // Verify order is maintained by checking entries sequentially
+ int previousValue = Integer.MAX_VALUE;
+ for (Map.Entry entry : result.entrySet()) {
+ assertTrue(entry.getValue() <= previousValue);
+ previousValue = entry.getValue();
+ }
+
+ // Verify specific order
+ String[] expectedOrder = { "banana", "elderberry", "cherry", "apple", "date" };
+ int i = 0;
+ for (String key : result.keySet()) {
+ assertEquals(expectedOrder[i++], key);
+ }
+ }
+
+ @Test
+ @Tag("valid")
+ @DisplayName("Sort HashMap with Same Values")
+ void sortHashMapWithSameValues() {
+ // Arrange
+ HashMap hashMap = new HashMap<>();
+ hashMap.put("apple", 5);
+ hashMap.put("banana", 5);
+ hashMap.put("cherry", 5);
+ // Act
+ HashMap result = hashMapFunctions.ordenarHashMapPorValor(hashMap);
+ // Assert
+ assertEquals(3, result.size());
+ for (Integer value : result.values()) {
+ assertEquals(5, value);
+ }
+ }
+
+ @Test
+ @Tag("boundary")
+ @DisplayName("Sort Empty HashMap")
+ void sortEmptyHashMap() {
+ // Arrange
+ HashMap hashMap = new HashMap<>();
+ // Act
+ HashMap result = hashMapFunctions.ordenarHashMapPorValor(hashMap);
+ // Assert
+ assertTrue(result.isEmpty());
+ assertInstanceOf(LinkedHashMap.class, result);
+ }
+
+ @Test
+ @Tag("boundary")
+ @DisplayName("Sort HashMap with Single Entry")
+ void sortHashMapWithSingleEntry() {
+ // Arrange
+ HashMap hashMap = new HashMap<>();
+ hashMap.put("apple", 5);
+ // Act
+ HashMap result = hashMapFunctions.ordenarHashMapPorValor(hashMap);
+ // Assert
+ assertEquals(1, result.size());
+ assertEquals(5, result.get("apple"));
+ }
+
+ @Test
+ @Tag("valid")
+ @DisplayName("Sort HashMap with Negative Values")
+ void sortHashMapWithNegativeValues() {
+ // Arrange
+ HashMap hashMap = new HashMap<>();
+ hashMap.put("apple", -5);
+ hashMap.put("banana", -2);
+ hashMap.put("cherry", -10);
+ // Act
+ HashMap result = hashMapFunctions.ordenarHashMapPorValor(hashMap);
+ // Assert
+ assertEquals(3, result.size());
+
+ // Verify specific order (descending)
+ String[] expectedOrder = { "banana", "apple", "cherry" };
+ int i = 0;
+ for (String key : result.keySet()) {
+ assertEquals(expectedOrder[i++], key);
+ }
+ }
+
+ @Test
+ @Tag("valid")
+ @DisplayName("Sort HashMap with Mixed Positive and Negative Values")
+ void sortHashMapWithMixedValues() {
+ // Arrange
+ HashMap hashMap = new HashMap<>();
+ hashMap.put("apple", -5);
+ hashMap.put("banana", 10);
+ hashMap.put("cherry", 0);
+ hashMap.put("date", -3);
+ // Act
+ HashMap result = hashMapFunctions.ordenarHashMapPorValor(hashMap);
+ // Assert
+ assertEquals(4, result.size());
+
+ // Verify specific order (descending)
+ String[] expectedOrder = { "banana", "cherry", "date", "apple" };
+ int i = 0;
+ for (String key : result.keySet()) {
+ assertEquals(expectedOrder[i++], key);
+ }
+ }
+
+ @ParameterizedTest
+ @MethodSource("provideHashMapsForSorting")
+ @Tag("valid")
+ @DisplayName("Sort Various HashMaps")
+ void sortVariousHashMaps(HashMap input, String[] expectedOrder) {
+ // Act
+ HashMap result = hashMapFunctions.ordenarHashMapPorValor(input);
+ // Assert
+ assertEquals(input.size(), result.size());
+
+ int i = 0;
+ for (String key : result.keySet()) {
+ assertEquals(expectedOrder[i++], key);
+ }
+ }
+
+ private static Stream provideHashMapsForSorting() {
+ // Test case 1: Regular descending order
+ HashMap map1 = new HashMap<>();
+ map1.put("a", 3);
+ map1.put("b", 1);
+ map1.put("c", 2);
+ String[] expected1 = { "a", "c", "b" };
+ // Test case 2: With duplicate values
+ HashMap map2 = new HashMap<>();
+ map2.put("x", 10);
+ map2.put("y", 10);
+ map2.put("z", 5);
+ String[] expected2 = { "x", "y", "z" }; // Order of x and y may vary but both
+ // should come before z
+ // Test case 3: Large numbers
+ HashMap map3 = new HashMap<>();
+ map3.put("large", Integer.MAX_VALUE);
+ map3.put("medium", 1000);
+ map3.put("small", Integer.MIN_VALUE);
+ String[] expected3 = { "large", "medium", "small" };
+ return Stream.of(Arguments.of(map1, expected1), Arguments.of(map2, expected2), Arguments.of(map3, expected3));
+ }
+
+ @Test
+ @Tag("invalid")
+ @DisplayName("Sort HashMap with Null Input")
+ void sortHashMapWithNullInput() {
+ // Act & Assert
+ assertThrows(NullPointerException.class, () -> hashMapFunctions.ordenarHashMapPorValor(null));
+ }
+
+}
\ No newline at end of file