• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.introspect;
2 
3 import com.fasterxml.jackson.annotation.Nulls;
4 import com.fasterxml.jackson.databind.*;
5 
6 public class PropertyMetadataTest extends BaseMapTest
7 {
testPropertyName()8     public void testPropertyName()
9     {
10         PropertyName name = PropertyName.NO_NAME;
11 
12         assertFalse(name.hasSimpleName());
13         assertFalse(name.hasNamespace());
14         assertSame(name, name.internSimpleName());
15         assertSame(name, name.withSimpleName(null));
16         assertSame(name, name.withSimpleName(""));
17         assertSame(name, name.withNamespace(null));
18         assertEquals("", name.toString());
19         assertTrue(name.isEmpty());
20         assertFalse(name.hasSimpleName("foo"));
21         // just to trigger it, ensure to exception
22         name.hashCode();
23 
24         PropertyName newName = name.withNamespace("");
25         assertNotSame(name, newName);
26         assertTrue(name.equals(name));
27         assertFalse(name.equals(newName));
28         assertFalse(newName.equals(name));
29 
30         name = name.withSimpleName("foo");
31         assertEquals("foo", name.toString());
32         assertTrue(name.hasSimpleName("foo"));
33         assertFalse(name.isEmpty());
34         newName = name.withNamespace("ns");
35         assertEquals("{ns}foo", newName.toString());
36         assertFalse(newName.equals(name));
37         assertFalse(name.equals(newName));
38 
39         // just to trigger it, ensure to exception
40         name.hashCode();
41     }
42 
testPropertyMetadata()43     public void testPropertyMetadata()
44     {
45         PropertyMetadata md = PropertyMetadata.STD_OPTIONAL;
46         assertNull(md.getValueNulls());
47         assertNull(md.getContentNulls());
48         assertNull(md.getDefaultValue());
49         assertEquals(Boolean.FALSE, md.getRequired());
50 
51         md = md.withNulls(Nulls.AS_EMPTY,
52                 Nulls.FAIL);
53         assertEquals(Nulls.AS_EMPTY, md.getValueNulls());
54         assertEquals(Nulls.FAIL, md.getContentNulls());
55 
56         assertFalse(md.hasDefaultValue());
57         assertSame(md, md.withDefaultValue(null));
58         assertSame(md, md.withDefaultValue(""));
59         md = md.withDefaultValue("foo");
60         assertEquals("foo", md.getDefaultValue());
61         assertTrue(md.hasDefaultValue());
62         assertSame(md, md.withDefaultValue("foo"));
63         md = md.withDefaultValue(null);
64         assertFalse(md.hasDefaultValue());
65         assertNull(md.getDefaultValue());
66 
67         md = md.withRequired(null);
68         assertNull(md.getRequired());
69         assertFalse(md.isRequired());
70         md = md.withRequired(Boolean.TRUE);
71         assertTrue(md.isRequired());
72         assertSame(md, md.withRequired(Boolean.TRUE));
73         md = md.withRequired(null);
74         assertNull(md.getRequired());
75         assertFalse(md.isRequired());
76 
77         assertFalse(md.hasIndex());
78         md = md.withIndex(Integer.valueOf(3));
79         assertTrue(md.hasIndex());
80         assertEquals(Integer.valueOf(3), md.getIndex());
81     }
82 }
83