|
40 | 40 | import java.util.NoSuchElementException;
|
41 | 41 | import java.util.Objects;
|
42 | 42 | import java.util.Optional;
|
| 43 | +import java.util.Properties; |
43 | 44 | import java.util.function.Predicate;
|
44 | 45 | import org.junit.jupiter.api.Test;
|
45 | 46 |
|
@@ -745,4 +746,53 @@ void jobtest() {
|
745 | 746 | + "{string=Hear it all the time, come back rewind, longestWord=6}]",
|
746 | 747 | result.toString());
|
747 | 748 | }
|
| 749 | + |
| 750 | + @Test |
| 751 | + void testPropertiesToMap() { |
| 752 | + Properties properties = new Properties(); |
| 753 | + properties.setProperty("key1", "value1"); |
| 754 | + properties.setProperty("key2", "value2"); |
| 755 | + properties.setProperty("key3", "value3"); |
| 756 | + Map<String, Object> map = U.propertiesToMap(properties); |
| 757 | + assertEquals(3, map.size()); |
| 758 | + assertEquals("value1", map.get("key1")); |
| 759 | + assertEquals("value2", map.get("key2")); |
| 760 | + assertEquals("value3", map.get("key3")); |
| 761 | + } |
| 762 | + |
| 763 | + @Test |
| 764 | + void testPropertiesToMapWithEmptyProperties() { |
| 765 | + Properties properties = new Properties(); |
| 766 | + Map<String, Object> map = U.propertiesToMap(properties); |
| 767 | + assertEquals(0, map.size()); |
| 768 | + Map<String, Object> map2 = U.propertiesToMap(null); |
| 769 | + assertEquals(0, map.size()); |
| 770 | + } |
| 771 | + |
| 772 | + @Test |
| 773 | + void testMapToProperties() { |
| 774 | + Map<String, Object> map = new LinkedHashMap<>(); |
| 775 | + map.put("key1", "value1"); |
| 776 | + map.put("key2", "value2"); |
| 777 | + map.put("key3", "value3"); |
| 778 | + Properties properties = U.mapToProperties(map); |
| 779 | + assertEquals(3, properties.size()); |
| 780 | + assertEquals("value1", properties.getProperty("key1")); |
| 781 | + assertEquals("value2", properties.getProperty("key2")); |
| 782 | + assertEquals("value3", properties.getProperty("key3")); |
| 783 | + } |
| 784 | + |
| 785 | + @Test |
| 786 | + void testMapToPropertiesWithNullValues() { |
| 787 | + Map<String, Object> map = new LinkedHashMap<>(); |
| 788 | + map.put("key1", "value1"); |
| 789 | + map.put("key2", null); |
| 790 | + map.put("key3", "value3"); |
| 791 | + Properties properties = U.mapToProperties(map); |
| 792 | + assertEquals(2, properties.size()); |
| 793 | + assertEquals("value1", properties.getProperty("key1")); |
| 794 | + assertEquals("value3", properties.getProperty("key3")); |
| 795 | + Properties properties2 = U.mapToProperties(null); |
| 796 | + assertEquals(0, properties2.size()); |
| 797 | + } |
748 | 798 | }
|
0 commit comments