21
21
22
22
import java .util .Collection ;
23
23
import java .util .Collections ;
24
+ import java .util .EnumSet ;
24
25
import java .util .List ;
25
26
import java .util .Map ;
26
27
import java .util .Set ;
39
40
*
40
41
* @author Oliver Gierke
41
42
* @author Saulo Medeiros de Araujo
43
+ * @author Mark Paluch
42
44
*/
43
45
@ RunWith (MockitoJUnitRunner .class )
44
46
public class ProjectingMethodInterceptorUnitTests {
@@ -105,8 +107,7 @@ public void appliesProjectionToNonEmptySets() throws Throwable {
105
107
assertThat (result ).isInstanceOf (Set .class );
106
108
107
109
Set <Object > projections = (Set <Object >) result ;
108
- assertThat (projections ).hasSize (1 );
109
- assertThat (projections ).hasOnlyElementsOfType (HelperProjection .class );
110
+ assertThat (projections ).hasSize (1 ).hasOnlyElementsOfType (HelperProjection .class );
110
111
}
111
112
112
113
@ Test // DATAREST-394, DATAREST-408
@@ -122,8 +123,7 @@ public void appliesProjectionToNonEmptyLists() throws Throwable {
122
123
123
124
List <Object > projections = (List <Object >) result ;
124
125
125
- assertThat (projections ).hasSize (1 );
126
- assertThat (projections ).hasOnlyElementsOfType (HelperProjection .class );
126
+ assertThat (projections ).hasSize (1 ).hasOnlyElementsOfType (HelperProjection .class );
127
127
}
128
128
129
129
@ Test // DATAREST-394, DATAREST-408
@@ -138,8 +138,7 @@ public void allowsMaskingAnArrayIntoACollection() throws Throwable {
138
138
139
139
Collection <Object > projections = (Collection <Object >) result ;
140
140
141
- assertThat (projections ).hasSize (1 );
142
- assertThat (projections ).hasOnlyElementsOfType (HelperProjection .class );
141
+ assertThat (projections ).hasSize (1 ).hasOnlyElementsOfType (HelperProjection .class );
143
142
}
144
143
145
144
@ Test // DATAREST-394, DATAREST-408
@@ -156,8 +155,7 @@ public void appliesProjectionToNonEmptyMap() throws Throwable {
156
155
157
156
Map <String , Object > projections = (Map <String , Object >) result ;
158
157
159
- assertThat (projections ).hasSize (1 );
160
- assertThat (projections ).matches (map -> map .get ("foo" ) instanceof HelperProjection );
158
+ assertThat (projections ).hasSize (1 ).matches (map -> map .get ("foo" ) instanceof HelperProjection );
161
159
}
162
160
163
161
@ Test
@@ -173,8 +171,22 @@ public void returnsSingleElementCollectionForTargetThatReturnsNonCollection() th
173
171
174
172
Collection <?> collection = (Collection <?>) result ;
175
173
176
- assertThat (collection ).hasSize (1 );
177
- assertThat (collection ).hasOnlyElementsOfType (HelperProjection .class );
174
+ assertThat (collection ).hasSize (1 ).hasOnlyElementsOfType (HelperProjection .class );
175
+ }
176
+
177
+ @ Test // DATACMNS-1598
178
+ public void returnsEnumSet () throws Throwable {
179
+
180
+ MethodInterceptor methodInterceptor = new ProjectingMethodInterceptor (new ProxyProjectionFactory (), interceptor ,
181
+ conversionService );
182
+
183
+ Object result = methodInterceptor
184
+ .invoke (mockInvocationOf ("getHelperEnumSet" , Collections .singletonList (HelperEnum .Helpful )));
185
+
186
+ assertThat (result ).isInstanceOf (EnumSet .class );
187
+
188
+ Collection <HelperEnum > collection = (Collection <HelperEnum >) result ;
189
+ assertThat (collection ).containsOnly (HelperEnum .Helpful );
178
190
}
179
191
180
192
/**
@@ -210,11 +222,17 @@ interface Helper {
210
222
Map <String , HelperProjection > getHelperMap ();
211
223
212
224
Collection <HelperProjection > getHelperArray ();
225
+
226
+ EnumSet <HelperEnum > getHelperEnumSet ();
213
227
}
214
228
215
229
interface HelperProjection {
216
230
Helper getHelper ();
217
231
218
232
String getString ();
219
233
}
234
+
235
+ enum HelperEnum {
236
+ Helpful , NotSoMuch ;
237
+ }
220
238
}
0 commit comments