• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.introspect;
2 
3 import java.util.Map;
4 
5 import com.fasterxml.jackson.databind.*;
6 import com.fasterxml.jackson.databind.introspect.BasicClassIntrospector;
7 import com.fasterxml.jackson.databind.introspect.POJOPropertiesCollector;
8 import com.fasterxml.jackson.databind.introspect.POJOPropertyBuilder;
9 
10 public class TestBuilderMethods extends BaseMapTest
11 {
12     static class SimpleBuilder
13     {
14         public int x;
15 
withX(int x0)16         public SimpleBuilder withX(int x0) {
17     		    this.x = x0;
18     		    return this;
19         }
20     }
21 
22     /*
23     /**********************************************************
24     /* Unit tests
25     /**********************************************************
26      */
27 
28     private final ObjectMapper mapper = new ObjectMapper();
29 
testSimple()30     public void testSimple()
31     {
32         POJOPropertiesCollector coll = collector(SimpleBuilder.class, "with");
33         Map<String, POJOPropertyBuilder> props = coll.getPropertyMap();
34         assertEquals(1, props.size());
35         POJOPropertyBuilder prop = props.get("x");
36         assertNotNull(prop);
37         assertTrue(prop.hasField());
38         assertFalse(prop.hasGetter());
39         assertTrue(prop.hasSetter());
40     }
41 
42     /*
43     /**********************************************************
44     /* Helper methods
45     /**********************************************************
46      */
47 
collector(Class<?> cls, String prefix)48     protected POJOPropertiesCollector collector(Class<?> cls, String prefix)
49     {
50         BasicClassIntrospector bci = new BasicClassIntrospector();
51         // no real difference between serialization, deserialization, at least here
52         return bci.collectProperties(mapper.getSerializationConfig(),
53                 mapper.constructType(cls), null, false, prefix);
54     }
55 
56 }
57