3232import org .assertj .core .api .Assertions ;
3333import org .junit .jupiter .api .BeforeEach ;
3434import org .junit .jupiter .api .Test ;
35+ import org .junit .jupiter .api .extension .ExtendWith ;
3536import org .mockito .Mock ;
3637import org .mockito .Mockito ;
37- import org .mockito .MockitoAnnotations ;
38+ import org .mockito .junit .jupiter .MockitoExtension ;
39+ import org .mockito .junit .jupiter .MockitoSettings ;
40+ import org .mockito .quality .Strictness ;
3841import org .springframework .batch .infrastructure .item .ExecutionContext ;
3942
4043/**
4447 *
4548 * @author Kazuki Shimizu
4649 */
50+ @ ExtendWith (MockitoExtension .class )
51+ @ MockitoSettings (strictness = Strictness .LENIENT )
4752class MyBatisPagingItemReaderBuilderTest {
4853
4954 @ Mock
@@ -57,8 +62,6 @@ class MyBatisPagingItemReaderBuilderTest {
5762
5863 @ BeforeEach
5964 void setUp () {
60- MockitoAnnotations .openMocks (this );
61-
6265 var configuration = new Configuration ();
6366 var environment = new Environment ("unittest" , new JdbcTransactionFactory (), dataSource );
6467 configuration .setEnvironment (environment );
@@ -70,19 +73,21 @@ void setUp() {
7073 parameters .put ("_page" , 0 );
7174 parameters .put ("_pagesize" , 10 );
7275 parameters .put ("_skiprows" , 0 );
76+
77+ // Most tests are using this, lenient as a result on class.
7378 Mockito .when (this .sqlSession .selectList ("selectFoo" , parameters )).thenReturn (getFoos ());
7479 }
7580
7681 @ Test
7782 void testConfiguration () throws Exception {
7883 // @formatter:off
79- var itemReader = new MyBatisPagingItemReaderBuilder <Foo >()
80- .sqlSessionFactory (this .sqlSessionFactory )
81- .queryId ("selectFoo" )
82- .parameterValues (Collections .singletonMap ("id" , 1 ))
83- .parameterValuesSupplier (() -> Collections .singletonMap ("name" , "Doe" ))
84- .build ();
85- // @formatter:on
84+ var itemReader = new MyBatisPagingItemReaderBuilder <Foo >()
85+ .sqlSessionFactory (this .sqlSessionFactory )
86+ .queryId ("selectFoo" )
87+ .parameterValues (Collections .singletonMap ("id" , 1 ))
88+ .parameterValuesSupplier (() -> Collections .singletonMap ("name" , "Doe" ))
89+ .build ();
90+ // @formatter:on
8691 itemReader .afterPropertiesSet ();
8792
8893 var executionContext = new ExecutionContext ();
@@ -102,14 +107,14 @@ void testConfiguration() throws Exception {
102107 @ Test
103108 void testConfigurationSaveStateIsFalse () throws Exception {
104109 // @formatter:off
105- var itemReader = new MyBatisPagingItemReaderBuilder <Foo >()
106- .sqlSessionFactory (this .sqlSessionFactory )
107- .queryId ("selectFoo" )
108- .parameterValues (Collections .singletonMap ("id" , 1 ))
109- .parameterValuesSupplier (() -> Collections .singletonMap ("name" , "Doe" ))
110- .saveState (false )
111- .build ();
112- // @formatter:on
110+ var itemReader = new MyBatisPagingItemReaderBuilder <Foo >()
111+ .sqlSessionFactory (this .sqlSessionFactory )
112+ .queryId ("selectFoo" )
113+ .parameterValues (Collections .singletonMap ("id" , 1 ))
114+ .parameterValuesSupplier (() -> Collections .singletonMap ("name" , "Doe" ))
115+ .saveState (false )
116+ .build ();
117+ // @formatter:on
113118 itemReader .afterPropertiesSet ();
114119
115120 var executionContext = new ExecutionContext ();
@@ -126,14 +131,14 @@ void testConfigurationSaveStateIsFalse() throws Exception {
126131 @ Test
127132 void testConfigurationMaxItemCount () throws Exception {
128133 // @formatter:off
129- var itemReader = new MyBatisPagingItemReaderBuilder <Foo >()
130- .sqlSessionFactory (this .sqlSessionFactory )
131- .queryId ("selectFoo" )
132- .parameterValues (Collections .singletonMap ("id" , 1 ))
133- .parameterValuesSupplier (() -> Collections .singletonMap ("name" , "Doe" ))
134- .maxItemCount (2 )
135- .build ();
136- // @formatter:on
134+ var itemReader = new MyBatisPagingItemReaderBuilder <Foo >()
135+ .sqlSessionFactory (this .sqlSessionFactory )
136+ .queryId ("selectFoo" )
137+ .parameterValues (Collections .singletonMap ("id" , 1 ))
138+ .parameterValuesSupplier (() -> Collections .singletonMap ("name" , "Doe" ))
139+ .maxItemCount (2 )
140+ .build ();
141+ // @formatter:on
137142 itemReader .afterPropertiesSet ();
138143
139144 var executionContext = new ExecutionContext ();
@@ -151,14 +156,14 @@ void testConfigurationMaxItemCount() throws Exception {
151156 @ Test
152157 void testConfigurationPageSize () throws Exception {
153158 // @formatter:off
154- var itemReader = new MyBatisPagingItemReaderBuilder <Foo >()
155- .sqlSessionFactory (this .sqlSessionFactory )
156- .queryId ("selectFoo" )
157- .parameterValues (Collections .singletonMap ("id" , 1 ))
158- .parameterValuesSupplier (() -> Collections .singletonMap ("name" , "Doe" ))
159- .pageSize (2 )
160- .build ();
161- // @formatter:on
159+ var itemReader = new MyBatisPagingItemReaderBuilder <Foo >()
160+ .sqlSessionFactory (this .sqlSessionFactory )
161+ .queryId ("selectFoo" )
162+ .parameterValues (Collections .singletonMap ("id" , 1 ))
163+ .parameterValuesSupplier (() -> Collections .singletonMap ("name" , "Doe" ))
164+ .pageSize (2 )
165+ .build ();
166+ // @formatter:on
162167 itemReader .afterPropertiesSet ();
163168
164169 Map <String , Object > parameters = new HashMap <>();
@@ -167,6 +172,8 @@ void testConfigurationPageSize() throws Exception {
167172 parameters .put ("name" , "Doe" );
168173 parameters .put ("_pagesize" , 2 );
169174 parameters .put ("_skiprows" , 0 );
175+
176+ // The initial mock on this needed repeated here, lenient as a result on class.
170177 Mockito .when (this .sqlSession .selectList ("selectFoo" , parameters )).thenReturn (getFoos ());
171178
172179 var executionContext = new ExecutionContext ();
0 commit comments