28
28
29
29
import org .junit .Test ;
30
30
import org .springframework .beans .factory .annotation .Value ;
31
+ import org .springframework .core .convert .converter .Converter ;
31
32
import org .springframework .data .domain .Page ;
32
33
import org .springframework .data .domain .PageImpl ;
33
34
import org .springframework .data .domain .Pageable ;
@@ -61,7 +62,7 @@ public void leavesNonProjectingResultUntouched() throws Exception {
61
62
@ Test
62
63
public void createsProjectionFromProperties () throws Exception {
63
64
64
- ResultProcessor information = getFactory ("findOneProjection" );
65
+ ResultProcessor information = getProcessor ("findOneProjection" );
65
66
66
67
SampleProjection result = information .processResult (Arrays .asList ("Matthews" ));
67
68
@@ -75,7 +76,7 @@ public void createsProjectionFromProperties() throws Exception {
75
76
@ SuppressWarnings ("unchecked" )
76
77
public void createsListOfProjectionsFormNestedLists () throws Exception {
77
78
78
- ResultProcessor information = getFactory ("findAllProjection" );
79
+ ResultProcessor information = getProcessor ("findAllProjection" );
79
80
80
81
List <String > columns = Arrays .asList ("Matthews" );
81
82
List <List <String >> source = new ArrayList <List <String >>(Arrays .asList (columns ));
@@ -93,7 +94,7 @@ public void createsListOfProjectionsFormNestedLists() throws Exception {
93
94
@ SuppressWarnings ("unchecked" )
94
95
public void createsListOfProjectionsFromMaps () throws Exception {
95
96
96
- ResultProcessor information = getFactory ("findAllProjection" );
97
+ ResultProcessor information = getProcessor ("findAllProjection" );
97
98
98
99
List <Map <String , Object >> source = new ArrayList <Map <String , Object >>(
99
100
Arrays .asList (Collections .<String , Object > singletonMap ("lastname" , "Matthews" )));
@@ -110,7 +111,7 @@ public void createsListOfProjectionsFromMaps() throws Exception {
110
111
@ Test
111
112
public void createsListOfProjectionsFromEntity () throws Exception {
112
113
113
- ResultProcessor information = getFactory ("findAllProjection" );
114
+ ResultProcessor information = getProcessor ("findAllProjection" );
114
115
115
116
List <Sample > source = new ArrayList <Sample >(Arrays .asList (new Sample ("Dave" , "Matthews" )));
116
117
List <SampleProjection > result = information .processResult (source );
@@ -125,7 +126,7 @@ public void createsListOfProjectionsFromEntity() throws Exception {
125
126
@ Test
126
127
public void createsPageOfProjectionsFromEntity () throws Exception {
127
128
128
- ResultProcessor information = getFactory ("findPageProjection" , Pageable .class );
129
+ ResultProcessor information = getProcessor ("findPageProjection" , Pageable .class );
129
130
130
131
Page <Sample > source = new PageImpl <Sample >(Arrays .asList (new Sample ("Dave" , "Matthews" )));
131
132
Page <SampleProjection > result = information .processResult (source );
@@ -140,7 +141,7 @@ public void createsPageOfProjectionsFromEntity() throws Exception {
140
141
@ Test
141
142
public void createsDynamicProjectionFromEntity () throws Exception {
142
143
143
- ResultProcessor information = getFactory ("findOneOpenProjection" );
144
+ ResultProcessor information = getProcessor ("findOneOpenProjection" );
144
145
145
146
OpenProjection result = information .processResult (new Sample ("Dave" , "Matthews" ));
146
147
@@ -156,7 +157,7 @@ public void findsDynamicProjection() throws Exception {
156
157
157
158
ParameterAccessor accessor = mock (ParameterAccessor .class );
158
159
159
- ResultProcessor factory = getFactory ("findOneDynamic" , Class .class );
160
+ ResultProcessor factory = getProcessor ("findOneDynamic" , Class .class );
160
161
assertThat (factory .withDynamicProjection (null ), is (factory ));
161
162
assertThat (factory .withDynamicProjection (accessor ), is (factory ));
162
163
@@ -166,7 +167,26 @@ public void findsDynamicProjection() throws Exception {
166
167
assertThat (processor .getReturnedType ().getReturnedType (), is (typeCompatibleWith (SampleProjection .class )));
167
168
}
168
169
169
- private static ResultProcessor getFactory (String methodName , Class <?>... parameters ) throws Exception {
170
+ /**
171
+ * @see DATACMNS-89
172
+ */
173
+ @ Test
174
+ public void refrainsFromProjectingIfThePreparingConverterReturnsACompatibleInstance () throws Exception {
175
+
176
+ ResultProcessor processor = getProcessor ("findAllDtos" );
177
+
178
+ Object result = processor .processResult (new Sample ("Dave" , "Matthews" ), new Converter <Object , Object >() {
179
+
180
+ @ Override
181
+ public Object convert (Object source ) {
182
+ return new SampleDTO ();
183
+ }
184
+ });
185
+
186
+ assertThat (result , is (instanceOf (SampleDTO .class )));
187
+ }
188
+
189
+ private static ResultProcessor getProcessor (String methodName , Class <?>... parameters ) throws Exception {
170
190
return getQueryMethod (methodName , parameters ).getResultProcessor ();
171
191
}
172
192
0 commit comments