• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.annotation;
2 
3 import java.util.Arrays;
4 import java.util.Collections;
5 import java.util.LinkedHashSet;
6 import java.util.Set;
7 
8 /**
9  * Tests to verify that it is possibly to merge {@link JsonIncludeProperties.Value}
10  * instances for overrides
11  */
12 public class JsonIncludePropertiesTest extends TestBase
13 {
14     @JsonIncludeProperties(value = {"foo", "bar"})
15     private final static class Bogus
16     {
17     }
18 
19     private final JsonIncludeProperties.Value ALL = JsonIncludeProperties.Value.all();
20 
testAll()21     public void testAll()
22     {
23         assertSame(ALL, JsonIncludeProperties.Value.from(null));
24         assertNull(ALL.getIncluded());
25         assertEquals(ALL, ALL);
26         assertEquals("JsonIncludeProperties.Value(included=null)", ALL.toString());
27         assertEquals(0, ALL.hashCode());
28     }
29 
testFromAnnotation()30     public void testFromAnnotation()
31     {
32         JsonIncludeProperties.Value v = JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class));
33         assertNotNull(v);
34         Set<String> included = v.getIncluded();
35         assertEquals(2, v.getIncluded().size());
36         assertEquals(_set("foo", "bar"), included);
37         assertEquals("JsonIncludeProperties.Value(included=[bar, foo])", v.toString());
38         assertEquals(v, JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class)));
39     }
40 
testWithOverridesAll()41     public void testWithOverridesAll() {
42         JsonIncludeProperties.Value v = JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class));
43         v = v.withOverrides(ALL);
44         Set<String> included = v.getIncluded();
45         assertEquals(2, included.size());
46         assertEquals(_set("foo", "bar"), included);
47     }
48 
testWithOverridesEmpty()49     public void testWithOverridesEmpty() {
50         JsonIncludeProperties.Value v = JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class));
51         v = v.withOverrides(new JsonIncludeProperties.Value(Collections.<String>emptySet()));
52         Set<String> included = v.getIncluded();
53         assertEquals(0, included.size());
54     }
55 
testWithOverridesMerge()56     public void testWithOverridesMerge() {
57         JsonIncludeProperties.Value v = JsonIncludeProperties.Value.from(Bogus.class.getAnnotation(JsonIncludeProperties.class));
58         v = v.withOverrides(new JsonIncludeProperties.Value(_set("foo")));
59         Set<String> included = v.getIncluded();
60         assertEquals(1, included.size());
61         assertEquals(_set("foo"), included);
62     }
63 
_set(String... args)64     private Set<String> _set(String... args)
65     {
66         return new LinkedHashSet<String>(Arrays.asList(args));
67     }
68 }
69