Skip to content

Commit 0fb0e41

Browse files
committed
Replace #initMocks with MockitoRule
Replace all references of MockitoAnnotations#initMocks with the MockitoRule JUnit rule.
1 parent 3fbfbb9 commit 0fb0e41

File tree

37 files changed

+249
-170
lines changed

37 files changed

+249
-170
lines changed

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ChunkListenerAdapterTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2014 the original author or authors.
2+
* Copyright 2013-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,14 +23,19 @@
2323
import javax.batch.operations.BatchRuntimeException;
2424

2525
import org.junit.Before;
26+
import org.junit.Rule;
2627
import org.junit.Test;
2728
import org.mockito.Mock;
28-
import org.mockito.MockitoAnnotations;
29+
import org.mockito.junit.MockitoJUnit;
30+
import org.mockito.junit.MockitoRule;
2931
import org.springframework.batch.core.scope.context.ChunkContext;
3032
import org.springframework.batch.core.step.tasklet.UncheckedTransactionException;
3133

3234
public class ChunkListenerAdapterTests {
3335

36+
@Rule
37+
public MockitoRule rule = MockitoJUnit.rule().silent();
38+
3439
private ChunkListenerAdapter adapter;
3540
@Mock
3641
private ChunkListener delegate;
@@ -39,7 +44,6 @@ public class ChunkListenerAdapterTests {
3944

4045
@Before
4146
public void setUp() {
42-
MockitoAnnotations.initMocks(this);
4347
adapter = new ChunkListenerAdapter(delegate);
4448
}
4549

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemProcessListenerAdapterTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,19 +22,23 @@
2222
import javax.batch.operations.BatchRuntimeException;
2323

2424
import org.junit.Before;
25+
import org.junit.Rule;
2526
import org.junit.Test;
2627
import org.mockito.Mock;
27-
import org.mockito.MockitoAnnotations;
28+
import org.mockito.junit.MockitoJUnit;
29+
import org.mockito.junit.MockitoRule;
2830

2931
public class ItemProcessListenerAdapterTests {
3032

33+
@Rule
34+
public MockitoRule rule = MockitoJUnit.rule().silent();
35+
3136
private ItemProcessListenerAdapter<String, String> adapter;
3237
@Mock
3338
private ItemProcessListener delegate;
3439

3540
@Before
3641
public void setUp() throws Exception {
37-
MockitoAnnotations.initMocks(this);
3842
adapter = new ItemProcessListenerAdapter<>(delegate);
3943
}
4044

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemReadListenerAdapterTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,19 +22,23 @@
2222
import javax.batch.operations.BatchRuntimeException;
2323

2424
import org.junit.Before;
25+
import org.junit.Rule;
2526
import org.junit.Test;
2627
import org.mockito.Mock;
27-
import org.mockito.MockitoAnnotations;
28+
import org.mockito.junit.MockitoJUnit;
29+
import org.mockito.junit.MockitoRule;
2830

2931
public class ItemReadListenerAdapterTests {
3032

33+
@Rule
34+
public MockitoRule rule = MockitoJUnit.rule().silent();
35+
3136
private ItemReadListenerAdapter<String> adapter;
3237
@Mock
3338
private ItemReadListener delegate;
3439

3540
@Before
3641
public void setUp() throws Exception {
37-
MockitoAnnotations.initMocks(this);
3842
adapter = new ItemReadListenerAdapter<>(delegate);
3943
}
4044

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemWriteListenerAdapterTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,21 +25,25 @@
2525
import javax.batch.operations.BatchRuntimeException;
2626

2727
import org.junit.Before;
28+
import org.junit.Rule;
2829
import org.junit.Test;
2930
import org.mockito.Mock;
30-
import org.mockito.MockitoAnnotations;
31+
import org.mockito.junit.MockitoJUnit;
32+
import org.mockito.junit.MockitoRule;
3133

3234
@SuppressWarnings({"rawtypes", "unchecked"})
3335
public class ItemWriteListenerAdapterTests {
3436

37+
@Rule
38+
public MockitoRule rule = MockitoJUnit.rule().silent();
39+
3540
private ItemWriteListenerAdapter<String> adapter;
3641
@Mock
3742
private ItemWriteListener delegate;
3843
private List items = new ArrayList();
3944

4045
@Before
4146
public void setUp() throws Exception {
42-
MockitoAnnotations.initMocks(this);
4347
adapter = new ItemWriteListenerAdapter<>(delegate);
4448
}
4549

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JobListenerAdapterTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,19 +22,23 @@
2222
import javax.batch.operations.BatchRuntimeException;
2323

2424
import org.junit.Before;
25+
import org.junit.Rule;
2526
import org.junit.Test;
2627
import org.mockito.Mock;
27-
import org.mockito.MockitoAnnotations;
28+
import org.mockito.junit.MockitoJUnit;
29+
import org.mockito.junit.MockitoRule;
2830

2931
public class JobListenerAdapterTests {
3032

33+
@Rule
34+
public MockitoRule rule = MockitoJUnit.rule().silent();
35+
3136
private JobListenerAdapter adapter;
3237
@Mock
3338
private JobListener delegate;
3439

3540
@Before
3641
public void setUp() throws Exception {
37-
MockitoAnnotations.initMocks(this);
3842
adapter = new JobListenerAdapter(delegate);
3943
}
4044

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrJobContextTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,9 +22,11 @@
2222
import java.util.Properties;
2323

2424
import org.junit.Before;
25+
import org.junit.Rule;
2526
import org.junit.Test;
2627
import org.mockito.Mock;
27-
import org.mockito.MockitoAnnotations;
28+
import org.mockito.junit.MockitoJUnit;
29+
import org.mockito.junit.MockitoRule;
2830
import org.springframework.batch.core.BatchStatus;
2931
import org.springframework.batch.core.ExitStatus;
3032
import org.springframework.batch.core.JobExecution;
@@ -34,6 +36,9 @@
3436

3537
public class JsrJobContextTests {
3638

39+
@Rule
40+
public MockitoRule rule = MockitoJUnit.rule().silent();
41+
3742
private JsrJobContext context;
3843
@Mock
3944
private JobExecution execution;
@@ -42,7 +47,6 @@ public class JsrJobContextTests {
4247

4348
@Before
4449
public void setUp() throws Exception {
45-
MockitoAnnotations.initMocks(this);
4650

4751
Properties properties = new Properties();
4852
properties.put("jobLevelProperty1", "jobLevelValue1");

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrStepContextFactoryBeanTests.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014 the original author or authors.
2+
* Copyright 2014-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,9 +32,11 @@
3232
import org.junit.After;
3333
import org.junit.Before;
3434
import org.junit.BeforeClass;
35+
import org.junit.Rule;
3536
import org.junit.Test;
3637
import org.mockito.Mock;
37-
import org.mockito.MockitoAnnotations;
38+
import org.mockito.junit.MockitoJUnit;
39+
import org.mockito.junit.MockitoRule;
3840
import org.springframework.batch.core.JobExecution;
3941
import org.springframework.batch.core.StepExecution;
4042
import org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext;
@@ -45,6 +47,9 @@
4547

4648
public class JsrStepContextFactoryBeanTests {
4749

50+
@Rule
51+
public MockitoRule rule = MockitoJUnit.rule().silent();
52+
4853
private JsrStepContextFactoryBean factory;
4954
@Mock
5055
private BatchPropertyContext propertyContext;
@@ -60,7 +65,6 @@ public static void setUpClass() throws Exception {
6065

6166
@Before
6267
public void setUp() throws Exception {
63-
MockitoAnnotations.initMocks(this);
6468
factory = new JsrStepContextFactoryBean();
6569
factory.setBatchPropertyContext(propertyContext);
6670
}

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/StepListenerAdapterTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013 the original author or authors.
2+
* Copyright 2013-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,14 +24,19 @@
2424
import javax.batch.operations.BatchRuntimeException;
2525

2626
import org.junit.Before;
27+
import org.junit.Rule;
2728
import org.junit.Test;
2829
import org.mockito.Mock;
29-
import org.mockito.MockitoAnnotations;
30+
import org.mockito.junit.MockitoJUnit;
31+
import org.mockito.junit.MockitoRule;
3032
import org.springframework.batch.core.ExitStatus;
3133
import org.springframework.batch.core.StepExecution;
3234

3335
public class StepListenerAdapterTests {
3436

37+
@Rule
38+
public MockitoRule rule = MockitoJUnit.rule().silent();
39+
3540
private StepListenerAdapter adapter;
3641
@Mock
3742
private StepListener delegate;
@@ -40,8 +45,6 @@ public class StepListenerAdapterTests {
4045

4146
@Before
4247
public void setUp() throws Exception {
43-
MockitoAnnotations.initMocks(this);
44-
4548
adapter = new StepListenerAdapter(delegate);
4649
}
4750

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2018 the original author or authors.
2+
* Copyright 2013-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,11 +35,12 @@
3535
import javax.sql.DataSource;
3636

3737
import org.junit.Before;
38+
import org.junit.Rule;
3839
import org.junit.Test;
3940
import org.mockito.ArgumentCaptor;
4041
import org.mockito.Mock;
41-
import org.mockito.MockitoAnnotations;
42-
42+
import org.mockito.junit.MockitoJUnit;
43+
import org.mockito.junit.MockitoRule;
4344
import org.springframework.batch.core.JobExecution;
4445
import org.springframework.batch.core.JobInstance;
4546
import org.springframework.batch.core.JobParametersBuilder;
@@ -79,6 +80,9 @@
7980
*/
8081
public class JsrJobOperatorTests extends AbstractJsrTestCase {
8182

83+
@Rule
84+
public MockitoRule rule = MockitoJUnit.rule().silent();
85+
8286
private JobOperator jsrJobOperator;
8387
@Mock
8488
private JobExplorer jobExplorer;
@@ -90,7 +94,6 @@ public class JsrJobOperatorTests extends AbstractJsrTestCase {
9094
@Before
9195
public void setup() throws Exception {
9296

93-
MockitoAnnotations.initMocks(this);
9497
parameterConverter = new JobParametersConverterSupport();
9598
jsrJobOperator = new JsrJobOperator(jobExplorer, jobRepository, parameterConverter, new ResourcelessTransactionManager());
9699
}

spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/batchlet/BatchletAdapterTests.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2013-2014 the original author or authors.
2+
* Copyright 2013-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,16 +24,21 @@
2424
import javax.batch.operations.BatchRuntimeException;
2525

2626
import org.junit.Before;
27+
import org.junit.Rule;
2728
import org.junit.Test;
2829
import org.mockito.Mock;
29-
import org.mockito.MockitoAnnotations;
30+
import org.mockito.junit.MockitoJUnit;
31+
import org.mockito.junit.MockitoRule;
3032
import org.springframework.batch.core.ExitStatus;
3133
import org.springframework.batch.core.StepContribution;
3234
import org.springframework.batch.core.scope.context.ChunkContext;
3335
import org.springframework.batch.repeat.RepeatStatus;
3436

3537
public class BatchletAdapterTests {
3638

39+
@Rule
40+
public MockitoRule rule = MockitoJUnit.rule().silent();
41+
3742
private BatchletAdapter adapter;
3843
@Mock
3944
private Batchlet delegate;
@@ -42,8 +47,6 @@ public class BatchletAdapterTests {
4247

4348
@Before
4449
public void setUp() throws Exception {
45-
MockitoAnnotations.initMocks(this);
46-
4750
adapter = new BatchletAdapter(delegate);
4851
}
4952

0 commit comments

Comments
 (0)