1 package com.lexicalscope.fluentreflection.bean.endtoend;
2
3 import static com.lexicalscope.fluentreflection.bean.MapBean.bean;
4 import static org.hamcrest.MatcherAssert.assertThat;
5 import static org.hamcrest.Matchers.*;
6
7 import java.util.ArrayList;
8 import java.util.HashMap;
9 import java.util.List;
10 import java.util.Map;
11
12 import org.junit.Test;
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 public class TestMapBeanWithNoPrefixes {
31 interface Bean {
32 String property();
33 Boolean hasProperty();
34 Boolean isProperty();
35 void property(String value);
36
37 List<Integer> optionalList();
38 void optionalList(List<Integer> integer);
39 boolean isOptionalList();
40 }
41
42 private final Map<String, Object> map = new HashMap<String, Object>();
43 private final Bean bean = bean(Bean.class, map);
44
45 @Test public void mapCanBeQueriedViaInterface() throws Exception {
46 assertThat(bean.isProperty(), equalTo(false));
47
48 bean.property("my value");
49
50 assertThat(bean.isProperty(), equalTo(true));
51 }
52
53 @Test public void mapCanBeReadViaInterface() throws Exception {
54 map.put("property", "my value");
55 assertThat(bean.property(), equalTo("my value"));
56 }
57
58 @Test public void mapCanBeSetViaInterface() throws Exception {
59 bean.property("my value");
60
61 assertThat(map.get("property"), equalTo((Object) "my value"));
62 }
63
64 @Test public void mapBeanEqualToItself() throws Exception {
65 assertThat(bean, equalTo(bean));
66 assertThat(bean.hashCode(), equalTo(bean.hashCode()));
67 }
68
69 @Test public void mapBeanNotEqualToSecondBeanOnTheSameMap() throws Exception {
70 assertThat(bean, not(equalTo(bean(Bean.class, map))));
71 }
72
73 @Test public void mapBeanOptionalCollectionQueryMethodIsFalseIfTheListIsNotPresent() throws Exception {
74 assertThat(bean.isOptionalList(), equalTo(false));
75
76 bean.optionalList(new ArrayList<Integer>());
77
78 assertThat(bean.isOptionalList(), equalTo(true));
79 }
80 }