1
+ /*
2
+ * Copyright 2017-2018 the original author or authors.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
1
16
package org .springframework .data .jdbc .repository .support ;
2
17
3
- import static org .assertj .core .api .Assertions .assertThat ;
4
- import static org .mockito .Mockito .mock ;
18
+ import static org .assertj .core .api .Assertions .* ;
19
+ import static org .mockito .Mockito .* ;
5
20
6
21
import org .junit .Before ;
7
22
import org .junit .Test ;
8
23
import org .junit .runner .RunWith ;
9
24
import org .mockito .Mock ;
10
25
import org .mockito .junit .MockitoJUnitRunner ;
11
26
import org .springframework .beans .factory .BeanFactory ;
12
- import org .springframework .beans .factory .ListableBeanFactory ;
13
27
import org .springframework .data .annotation .Id ;
14
28
import org .springframework .data .jdbc .core .DataAccessStrategy ;
29
+ import org .springframework .data .jdbc .core .DefaultDataAccessStrategy ;
15
30
import org .springframework .data .jdbc .mapping .model .JdbcMappingContext ;
31
+ import org .springframework .data .jdbc .repository .RowMapperMap ;
16
32
import org .springframework .data .repository .CrudRepository ;
17
- import org .springframework .data . repository . Repository ;
33
+ import org .springframework .test . util . ReflectionTestUtils ;
18
34
19
35
/**
20
36
* Tests the dependency injection for {@link JdbcRepositoryFactoryBean}.
21
37
*
22
38
* @author Jens Schauder
23
39
* @author Greg Turnquist
40
+ * @author Christoph Strobl
24
41
*/
25
42
@ RunWith (MockitoJUnitRunner .class )
26
43
public class JdbcRepositoryFactoryBeanUnitTests {
27
44
28
45
JdbcRepositoryFactoryBean <DummyEntityRepository , DummyEntity , Long > factoryBean ;
29
46
30
- @ Mock ListableBeanFactory beanFactory ;
31
- @ Mock Repository <?, ?> repository ;
32
47
@ Mock DataAccessStrategy dataAccessStrategy ;
33
48
@ Mock JdbcMappingContext mappingContext ;
34
49
@@ -55,6 +70,25 @@ public void requiresListableBeanFactory() {
55
70
factoryBean .setBeanFactory (mock (BeanFactory .class ));
56
71
}
57
72
73
+ @ Test (expected = IllegalStateException .class ) // DATAJDBC-155
74
+ public void afterPropertiesThowsExceptionWhenNoMappingContextSet () {
75
+
76
+ factoryBean .setMappingContext (null );
77
+ factoryBean .afterPropertiesSet ();
78
+ }
79
+
80
+ @ Test // DATAJDBC-155
81
+ public void afterPropertiesSetDefaultsNullablePropertiesCorrectly () {
82
+
83
+ factoryBean .setMappingContext (mappingContext );
84
+ factoryBean .afterPropertiesSet ();
85
+
86
+ assertThat (factoryBean .getObject ()).isNotNull ();
87
+ assertThat (ReflectionTestUtils .getField (factoryBean , "dataAccessStrategy" ))
88
+ .isInstanceOf (DefaultDataAccessStrategy .class );
89
+ assertThat (ReflectionTestUtils .getField (factoryBean , "rowMapperMap" )).isEqualTo (RowMapperMap .EMPTY );
90
+ }
91
+
58
92
private static class DummyEntity {
59
93
@ Id private Long id ;
60
94
}
0 commit comments