1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.reflection.wrapper;
17
18 import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
19 import static org.junit.jupiter.api.Assertions.assertTrue;
20 import static org.mockito.Mockito.verify;
21
22 import java.util.ArrayList;
23 import java.util.Collection;
24 import java.util.List;
25
26 import org.apache.ibatis.reflection.MetaObject;
27 import org.apache.ibatis.reflection.SystemMetaObject;
28 import org.apache.ibatis.reflection.property.PropertyTokenizer;
29 import org.junit.jupiter.api.BeforeEach;
30 import org.junit.jupiter.api.Test;
31 import org.junit.jupiter.api.extension.ExtendWith;
32 import org.mockito.Mock;
33 import org.mockito.junit.jupiter.MockitoExtension;
34
35
36
37
38
39
40 @ExtendWith(MockitoExtension.class)
41 class CollectionWrapperUnitTest extends ObjectWrapperBaseTest {
42
43 @Mock
44 private Collection<Object> collection;
45
46 @Mock
47 private PropertyTokenizer tokenizer;
48
49 private ObjectWrapper wrapper;
50
51 @BeforeEach
52 void setup() {
53 MetaObject metaObject = SystemMetaObject.forObject(collection);
54 this.wrapper = new CollectionWrapper(metaObject, collection);
55 }
56
57 @Test
58 @Override
59 void shouldGet() {
60 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.get(tokenizer));
61 }
62
63 @Test
64 @Override
65 void shouldSet() {
66 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.set(tokenizer, null));
67 }
68
69 @Test
70 @Override
71 void shouldFindProperty() {
72 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.findProperty("abc", true));
73 }
74
75 @Test
76 @Override
77 void shouldGetGetterNames() {
78 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.getGetterNames());
79 }
80
81 @Test
82 @Override
83 void shouldGetSetterNames() {
84 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.getSetterNames());
85 }
86
87 @Test
88 @Override
89 void shouldGetGetterType() {
90 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.getGetterType("abc"));
91 }
92
93 @Test
94 @Override
95 void shouldGetSetterType() {
96 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.getSetterType("abc"));
97 }
98
99 @Test
100 @Override
101 void shouldHasGetter() {
102 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.hasGetter("abc"));
103 }
104
105 @Test
106 @Override
107 void shouldHasSetter() {
108 assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> wrapper.hasSetter("abc"));
109 }
110
111 @Test
112 @Override
113 void shouldIsCollection() {
114 assertTrue(wrapper.isCollection());
115 }
116
117 @Test
118 @Override
119 void shouldInstantiatePropertyValue() {
120 assertThatExceptionOfType(UnsupportedOperationException.class)
121 .isThrownBy(() -> wrapper.instantiatePropertyValue("abc", tokenizer, null));
122 }
123
124 @Test
125 @Override
126 void shouldAddElement() {
127 wrapper.add("bdc");
128
129 verify(collection).add("bdc");
130 }
131
132 @Test
133 @Override
134 void shouldAddAll() {
135 List<Object> list = new ArrayList<>() {
136 {
137 add("1");
138 add("2");
139 add("3");
140 }
141 };
142 wrapper.addAll(list);
143
144 verify(collection).addAll(list);
145 }
146 }