|
12 | 12 |
|
13 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; |
14 | 14 | import static org.junit.jupiter.api.Assertions.assertNull; |
| 15 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 16 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 17 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
15 | 18 |
|
16 | 19 | public class BeanUtilTest extends DatabindTestUtil |
17 | 20 | { |
@@ -39,4 +42,76 @@ public void testGetDefaultValue() |
39 | 42 | // but POJOs have no real default |
40 | 43 | assertNull(BeanUtil.getDefaultValue(tf.constructType(getClass()))); |
41 | 44 | } |
| 45 | + |
| 46 | + @Test |
| 47 | + public void testGetDefaultValueForDate() |
| 48 | + { |
| 49 | + TypeFactory tf = defaultTypeFactory(); |
| 50 | + Object result = BeanUtil.getDefaultValue(tf.constructType(Date.class)); |
| 51 | + assertNotNull(result); |
| 52 | + assertTrue(result instanceof Date); |
| 53 | + assertEquals(0L, ((Date) result).getTime()); |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + public void testGetDefaultValueForCalendar() |
| 58 | + { |
| 59 | + TypeFactory tf = defaultTypeFactory(); |
| 60 | + Object result = BeanUtil.getDefaultValue(tf.constructType(Calendar.class)); |
| 61 | + assertNotNull(result); |
| 62 | + assertTrue(result instanceof Calendar); |
| 63 | + assertEquals(0L, ((Calendar) result).getTimeInMillis()); |
| 64 | + } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testGetDefaultValueForGregorianCalendar() |
| 68 | + { |
| 69 | + TypeFactory tf = defaultTypeFactory(); |
| 70 | + Object result = BeanUtil.getDefaultValue(tf.constructType(GregorianCalendar.class)); |
| 71 | + assertNotNull(result); |
| 72 | + assertTrue(result instanceof Calendar); |
| 73 | + assertEquals(0L, ((Calendar) result).getTimeInMillis()); |
| 74 | + } |
| 75 | + |
| 76 | + @Deprecated |
| 77 | + @Test |
| 78 | + public void testDeprecatedStdManglePropertyName() |
| 79 | + { |
| 80 | + // Empty name after offset |
| 81 | + assertNull(BeanUtil.stdManglePropertyName("get", 3)); |
| 82 | + |
| 83 | + // Starts with lowercase - return as-is |
| 84 | + assertEquals("value", BeanUtil.stdManglePropertyName("getValue", 3)); |
| 85 | + |
| 86 | + // Single uppercase letter - should lowercase |
| 87 | + assertEquals("x", BeanUtil.stdManglePropertyName("getX", 3)); |
| 88 | + |
| 89 | + // Two consecutive uppercase letters - keep as-is (Java Beans spec) |
| 90 | + assertEquals("URL", BeanUtil.stdManglePropertyName("getURL", 3)); |
| 91 | + |
| 92 | + // Standard property name |
| 93 | + assertEquals("name", BeanUtil.stdManglePropertyName("getName", 3)); |
| 94 | + |
| 95 | + // Property starting with uppercase, second lowercase - should lowercase first |
| 96 | + assertEquals("value", BeanUtil.stdManglePropertyName("Value", 0)); |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + public void testCheckUnsupportedTypeForSupportedType() |
| 101 | + { |
| 102 | + TypeFactory tf = defaultTypeFactory(); |
| 103 | + // Regular types should return null |
| 104 | + assertNull(BeanUtil.checkUnsupportedType(null, tf.constructType(String.class))); |
| 105 | + assertNull(BeanUtil.checkUnsupportedType(null, tf.constructType(Integer.class))); |
| 106 | + assertNull(BeanUtil.checkUnsupportedType(null, tf.constructType(List.class))); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void testIsJodaTimeClass() |
| 111 | + { |
| 112 | + // Test with non-Joda Time classes |
| 113 | + assertFalse(BeanUtil.isJodaTimeClass(String.class)); |
| 114 | + assertFalse(BeanUtil.isJodaTimeClass(Date.class)); |
| 115 | + assertFalse(BeanUtil.isJodaTimeClass(Calendar.class)); |
| 116 | + } |
42 | 117 | } |
0 commit comments