diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ChunkListenerAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ChunkListenerAdapterTests.java index aa0aef9db9..a66dce4e68 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ChunkListenerAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ChunkListenerAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,14 +23,19 @@ import javax.batch.operations.BatchRuntimeException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.tasklet.UncheckedTransactionException; public class ChunkListenerAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private ChunkListenerAdapter adapter; @Mock private ChunkListener delegate; @@ -39,7 +44,6 @@ public class ChunkListenerAdapterTests { @Before public void setUp() { - MockitoAnnotations.initMocks(this); adapter = new ChunkListenerAdapter(delegate); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemProcessListenerAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemProcessListenerAdapterTests.java index 33ad9ba6f3..673a3ba392 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemProcessListenerAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemProcessListenerAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,19 +22,23 @@ import javax.batch.operations.BatchRuntimeException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; public class ItemProcessListenerAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private ItemProcessListenerAdapter adapter; @Mock private ItemProcessListener delegate; @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); adapter = new ItemProcessListenerAdapter<>(delegate); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemReadListenerAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemReadListenerAdapterTests.java index d5412a3a8b..056ddb3089 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemReadListenerAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemReadListenerAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,19 +22,23 @@ import javax.batch.operations.BatchRuntimeException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; public class ItemReadListenerAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private ItemReadListenerAdapter adapter; @Mock private ItemReadListener delegate; @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); adapter = new ItemReadListenerAdapter<>(delegate); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemWriteListenerAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemWriteListenerAdapterTests.java index d1e7e85872..3966f9e630 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemWriteListenerAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/ItemWriteListenerAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,13 +25,18 @@ import javax.batch.operations.BatchRuntimeException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; @SuppressWarnings({"rawtypes", "unchecked"}) public class ItemWriteListenerAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private ItemWriteListenerAdapter adapter; @Mock private ItemWriteListener delegate; @@ -39,7 +44,6 @@ public class ItemWriteListenerAdapterTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); adapter = new ItemWriteListenerAdapter<>(delegate); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JobListenerAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JobListenerAdapterTests.java index e948ae748f..6934d619fe 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JobListenerAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JobListenerAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,19 +22,23 @@ import javax.batch.operations.BatchRuntimeException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; public class JobListenerAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private JobListenerAdapter adapter; @Mock private JobListener delegate; @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); adapter = new JobListenerAdapter(delegate); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrJobContextTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrJobContextTests.java index 9ec6cb1918..cfdd52b0ba 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrJobContextTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrJobContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,11 @@ import java.util.Properties; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; @@ -34,6 +36,9 @@ public class JsrJobContextTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private JsrJobContext context; @Mock private JobExecution execution; @@ -42,7 +47,6 @@ public class JsrJobContextTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); Properties properties = new Properties(); properties.put("jobLevelProperty1", "jobLevelValue1"); diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrStepContextFactoryBeanTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrStepContextFactoryBeanTests.java index 006e1a85c6..b56de31535 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrStepContextFactoryBeanTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/JsrStepContextFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,9 +32,11 @@ import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.StepExecution; import org.springframework.batch.core.jsr.configuration.support.BatchPropertyContext; @@ -45,6 +47,9 @@ public class JsrStepContextFactoryBeanTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private JsrStepContextFactoryBean factory; @Mock private BatchPropertyContext propertyContext; @@ -60,7 +65,6 @@ public static void setUpClass() throws Exception { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); factory = new JsrStepContextFactoryBean(); factory.setBatchPropertyContext(propertyContext); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/StepListenerAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/StepListenerAdapterTests.java index 102dc31941..6aade27a89 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/StepListenerAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/StepListenerAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,14 +24,19 @@ import javax.batch.operations.BatchRuntimeException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepExecution; public class StepListenerAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private StepListenerAdapter adapter; @Mock private StepListener delegate; @@ -40,8 +45,6 @@ public class StepListenerAdapterTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - adapter = new StepListenerAdapter(delegate); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java index 31fd8341b5..f61b8c1bd1 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/launch/JsrJobOperatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,11 +35,12 @@ import javax.sql.DataSource; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.core.JobExecution; import org.springframework.batch.core.JobInstance; import org.springframework.batch.core.JobParametersBuilder; @@ -79,6 +80,9 @@ */ public class JsrJobOperatorTests extends AbstractJsrTestCase { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private JobOperator jsrJobOperator; @Mock private JobExplorer jobExplorer; @@ -90,7 +94,6 @@ public class JsrJobOperatorTests extends AbstractJsrTestCase { @Before public void setup() throws Exception { - MockitoAnnotations.initMocks(this); parameterConverter = new JobParametersConverterSupport(); jsrJobOperator = new JsrJobOperator(jobExplorer, jobRepository, parameterConverter, new ResourcelessTransactionManager()); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/batchlet/BatchletAdapterTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/batchlet/BatchletAdapterTests.java index 7713e77259..ed7bf83188 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/batchlet/BatchletAdapterTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/jsr/step/batchlet/BatchletAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,9 +24,11 @@ import javax.batch.operations.BatchRuntimeException; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.scope.context.ChunkContext; @@ -34,6 +36,9 @@ public class BatchletAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private BatchletAdapter adapter; @Mock private Batchlet delegate; @@ -42,8 +47,6 @@ public class BatchletAdapterTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - adapter = new BatchletAdapter(delegate); } diff --git a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java index c7a1dd9f08..6a31e263b7 100644 --- a/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java +++ b/spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/SystemCommandTaskletIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2019 the original author or authors. + * Copyright 2008-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.core.BatchStatus; import org.springframework.batch.core.ExitStatus; import org.springframework.batch.core.JobExecution; @@ -49,6 +50,9 @@ */ public class SystemCommandTaskletIntegrationTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private static final Log log = LogFactory.getLog(SystemCommandTaskletIntegrationTests.class); private SystemCommandTasklet tasklet; @@ -61,7 +65,6 @@ public class SystemCommandTaskletIntegrationTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); initializeTasklet(); tasklet.afterPropertiesSet(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemReaderBuilderTests.java index b887ccbda0..19591145db 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,11 +16,11 @@ package org.springframework.batch.item.amqp.builder; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.amqp.core.Message; import org.springframework.batch.item.amqp.AmqpItemReader; @@ -35,14 +35,12 @@ */ public class AmqpItemReaderBuilderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock AmqpTemplate amqpTemplate; - @Before - public void setup() { - MockitoAnnotations.initMocks(this); - } - @Test public void testNoItemType() { when(this.amqpTemplate.receiveAndConvert()).thenReturn("foo"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java index b07bfde4cb..225c839899 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,11 @@ import java.util.List; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.SpELItemKeyMapper; import org.springframework.data.gemfire.GemfireTemplate; import org.springframework.core.convert.converter.Converter; @@ -33,13 +35,15 @@ @SuppressWarnings("serial") public class GemfireItemWriterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private GemfireItemWriter writer; @Mock private GemfireTemplate template; @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); writer = new GemfireItemWriter<>(); writer.setTemplate(template); writer.setItemKeyMapper(new SpELItemKeyMapper<>("bar.val")); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemReaderTests.java index c01f9018d0..c600c9fdf9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemReaderTests.java @@ -20,11 +20,12 @@ import java.util.Map; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Order; @@ -44,6 +45,9 @@ */ public class MongoItemReaderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private MongoItemReader reader; @Mock private MongoOperations template; @@ -51,7 +55,6 @@ public class MongoItemReaderTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); reader = new MongoItemReader<>(); sortOptions = new HashMap<>(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java index d2565ea214..8ceda278b0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java @@ -21,6 +21,7 @@ import org.bson.Document; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; import static org.mockito.Mockito.mock; @@ -31,8 +32,8 @@ import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.times; import static org.mockito.Mockito.never; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mongodb.core.BulkOperations; @@ -60,6 +61,9 @@ @SuppressWarnings("serial") public class MongoItemWriterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private MongoItemWriter writer; @Mock private MongoOperations template; @@ -72,7 +76,6 @@ public class MongoItemWriterTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations); when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemReaderTests.java index b8bdfcedee..670fac0a4c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2017 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,12 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.SessionFactory; @@ -38,6 +39,9 @@ public class Neo4jItemReaderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock private Iterable result; @Mock @@ -45,11 +49,6 @@ public class Neo4jItemReaderTests { @Mock private Session session; - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - private Neo4jItemReader buildSessionBasedReader() throws Exception { Neo4jItemReader reader = new Neo4jItemReader<>(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java index 85ffccadec..9d1cd921e1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,10 +18,11 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.SessionFactory; @@ -33,6 +34,9 @@ public class Neo4jItemWriterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private Neo4jItemWriter writer; @Mock @@ -40,11 +44,6 @@ public class Neo4jItemWriterTests { @Mock private Session session; - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - @Test public void testAfterPropertiesSet() throws Exception{ diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java index 22e42f1b20..ccedb4ce74 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2020 the original author or authors. + * Copyright 2013-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,12 @@ import java.util.Map; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.adapter.DynamicMethodInvocationException; import org.springframework.data.domain.Page; @@ -53,6 +54,9 @@ @SuppressWarnings("serial") public class RepositoryItemReaderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private RepositoryItemReader reader; @Mock private PagingAndSortingRepository repository; @@ -60,7 +64,6 @@ public class RepositoryItemReaderTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); sorts = Collections.singletonMap("id", Direction.ASC); reader = new RepositoryItemReader<>(); reader.setRepository(repository); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java index 867377a4d6..c955aecb32 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java @@ -27,13 +27,17 @@ import java.util.List; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.data.repository.CrudRepository; public class RepositoryItemWriterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); @Mock private CrudRepository repository; @@ -41,7 +45,6 @@ public class RepositoryItemWriterTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); writer = new RepositoryItemWriter<>(); writer.setMethodName("save"); writer.setRepository(repository); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java index cb2465b09a..4193453ecf 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,11 @@ import java.util.List; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.SpELItemKeyMapper; import org.springframework.batch.item.data.GemfireItemWriter; import org.springframework.data.gemfire.GemfireTemplate; @@ -37,6 +38,9 @@ * @author Glenn Renfro */ public class GemfireItemWriterBuilderTests { + + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); @Mock private GemfireTemplate template; @@ -46,7 +50,6 @@ public class GemfireItemWriterBuilderTests { @Before public void setUp() { - MockitoAnnotations.initMocks(this); this.items = Arrays.asList(new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val1")), new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val2"))); this.itemKeyMapper = new SpELItemKeyMapper<>("bar.val"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilderTests.java index ffab3393c7..10cce4cc87 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilderTests.java @@ -22,11 +22,12 @@ import java.util.Map; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.data.MongoItemReader; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoOperations; @@ -44,6 +45,9 @@ * @author Parikshit Dutta */ public class MongoItemReaderBuilderTests { + + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); @Mock private MongoOperations template; @@ -53,7 +57,6 @@ public class MongoItemReaderBuilderTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); this.sortOptions = new HashMap<>(); this.sortOptions.put("name", Sort.Direction.DESC); this.queryContainer = ArgumentCaptor.forClass(Query.class); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java index 534090c7d6..72ff403db2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java @@ -21,6 +21,7 @@ import org.bson.Document; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; import static org.mockito.Mockito.spy; @@ -28,8 +29,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.data.MongoItemWriter; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mongodb.core.BulkOperations; @@ -52,6 +53,9 @@ * @author Parikshit Dutta */ public class MongoItemWriterBuilderTests { + + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); @Mock private MongoOperations template; @Mock @@ -65,7 +69,6 @@ public class MongoItemWriterBuilderTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations); when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilderTests.java index 6e5c95975e..a76a266cab 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,11 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.SessionFactory; @@ -39,6 +40,9 @@ */ public class Neo4jItemReaderBuilderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock private Iterable result; @@ -48,11 +52,6 @@ public class Neo4jItemReaderBuilderTests { @Mock private Session session; - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - @Test public void testFullyQualifiedItemReader() throws Exception { Neo4jItemReader itemReader = new Neo4jItemReaderBuilder() diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java index 377adcdda2..19bab8b0cb 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,11 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.SessionFactory; @@ -39,16 +40,14 @@ */ public class Neo4jItemWriterBuilderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock private SessionFactory sessionFactory; @Mock private Session session; - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - @Test public void testBasicWriter() throws Exception{ Neo4jItemWriter writer = new Neo4jItemWriterBuilder().sessionFactory(this.sessionFactory).build(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilderTests.java index a7daf8cf32..33b91b44a9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +22,12 @@ import java.util.Map; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.data.RepositoryItemReader; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -50,6 +51,9 @@ public class RepositoryItemReaderBuilderTests { private static final String TEST_CONTENT = "FOOBAR"; + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock private TestRepository repository; @@ -62,7 +66,6 @@ public class RepositoryItemReaderBuilderTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); this.sorts = new HashMap<>(); this.sorts.put("id", Sort.Direction.ASC); this.pageRequestContainer = ArgumentCaptor.forClass(PageRequest.class); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java index e529daae6c..6882525aa1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java @@ -20,11 +20,11 @@ import java.util.Collections; import java.util.List; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.data.RepositoryItemWriter; import org.springframework.data.repository.CrudRepository; @@ -37,14 +37,12 @@ * @author Mahmoud Ben Hassine */ public class RepositoryItemWriterBuilderTests { + + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); @Mock private TestRepository repository; - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - } - @Test public void testNullRepository() throws Exception { try { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateItemWriterBuilderTests.java index ff76a491c0..bde0553a20 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,11 @@ import org.hibernate.Session; import org.hibernate.SessionFactory; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.database.HibernateItemWriter; import org.springframework.batch.item.sample.Foo; @@ -39,6 +40,9 @@ */ public class HibernateItemWriterBuilderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock private SessionFactory sessionFactory; @@ -47,7 +51,6 @@ public class HibernateItemWriterBuilderTests { @Before public void setUp() { - MockitoAnnotations.initMocks(this); when(this.sessionFactory.getCurrentSession()).thenReturn(this.session); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaItemWriterBuilderTests.java index 0eb960f6a2..1f1cf2569f 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaItemWriterBuilderTests.java @@ -22,10 +22,11 @@ import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.database.JpaItemWriter; import org.springframework.orm.jpa.EntityManagerHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -39,6 +40,9 @@ */ public class JpaItemWriterBuilderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock private EntityManagerFactory entityManagerFactory; @@ -47,7 +51,6 @@ public class JpaItemWriterBuilderTests { @Before public void setUp() { - MockitoAnnotations.initMocks(this); TransactionSynchronizationManager.bindResource(this.entityManagerFactory, new EntityManagerHolder(this.entityManager)); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonItemReaderBuilderTest.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonItemReaderBuilderTest.java index 148ab25c55..8cbb788bc3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonItemReaderBuilderTest.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonItemReaderBuilderTest.java @@ -17,11 +17,11 @@ package org.springframework.batch.item.json.builder; import org.junit.Assert; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.json.JsonItemReader; import org.springframework.batch.item.json.JsonObjectReader; import org.springframework.core.io.Resource; @@ -35,16 +35,14 @@ */ public class JsonItemReaderBuilderTest { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock private Resource resource; @Mock private JsonObjectReader jsonObjectReader; - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - } - @Test public void testValidation() { try { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java index b2fa766482..5d6a3b3a69 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java @@ -20,10 +20,11 @@ import java.util.concurrent.TimeUnit; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.core.convert.converter.Converter; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.support.SendResult; @@ -38,6 +39,8 @@ public class KafkaItemWriterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); @Mock private KafkaTemplate kafkaTemplate; @@ -50,7 +53,6 @@ public class KafkaItemWriterTests { @Before public void setUp() throws Exception { - MockitoAnnotations.openMocks(this); when(this.kafkaTemplate.getDefaultTopic()).thenReturn("defaultTopic"); when(this.kafkaTemplate.sendDefault(any(), any())).thenReturn(this.future); this.itemKeyMapper = new KafkaItemKeyMapper(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemWriterBuilderTests.java index 6aca629987..79fb0a0542 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemWriterBuilderTests.java @@ -21,8 +21,8 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.kafka.KafkaItemWriter; import org.springframework.core.convert.converter.Converter; import org.springframework.kafka.core.KafkaTemplate; @@ -37,6 +37,9 @@ */ public class KafkaItemWriterBuilderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Rule public ExpectedException thrown = ExpectedException.none(); @@ -47,7 +50,6 @@ public class KafkaItemWriterBuilderTests { @Before public void setUp() { - MockitoAnnotations.initMocks(this); this.itemKeyMapper = new KafkaItemKeyMapper(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/AbstractSynchronizedItemStreamWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/AbstractSynchronizedItemStreamWriterTests.java index 7953de936e..082dbe9b09 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/AbstractSynchronizedItemStreamWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/AbstractSynchronizedItemStreamWriterTests.java @@ -15,21 +15,22 @@ */ package org.springframework.batch.item.support; +import static org.mockito.Mockito.verify; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mock; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamWriter; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; - /** * Common parent class for {@link SynchronizedItemStreamWriterTests} and * {@link org.springframework.batch.item.support.builder.SynchronizedItemStreamWriterBuilderTests} @@ -39,6 +40,9 @@ */ public abstract class AbstractSynchronizedItemStreamWriterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Rule public ExpectedException expectedException = ExpectedException.none(); @@ -53,7 +57,6 @@ public abstract class AbstractSynchronizedItemStreamWriterTests { @Before public void init() { - initMocks(this); synchronizedItemStreamWriter = createNewSynchronizedItemStreamWriter(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemProcessorBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemProcessorBuilderTests.java index b5f266175d..2d28734d9e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemProcessorBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemProcessorBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +20,11 @@ import java.util.List; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.support.CompositeItemProcessor; @@ -38,6 +39,9 @@ */ public class CompositeItemProcessorBuilderTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock private ItemProcessor processor1; @@ -48,8 +52,6 @@ public class CompositeItemProcessorBuilderTests { @Before public void setup() { - MockitoAnnotations.initMocks(this); - this.processors = new ArrayList<>(); this.processors.add(processor1); this.processors.add(processor2); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilderTests.java index 2a8fde2eb6..9f80b108ee 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilderTests.java @@ -21,11 +21,11 @@ import javax.xml.bind.annotation.XmlRootElement; import javax.xml.stream.XMLInputFactory; -import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; import org.springframework.batch.item.xml.StaxEventItemReader; @@ -51,14 +51,12 @@ public class StaxEventItemReaderBuilderTests { "fivesix7" + "eightnine"; + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + @Mock private Resource resource; - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - } - @Test public void testValidation() { try { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemProcessorAdapterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemProcessorAdapterTests.java index ed4e60be13..bd626e5bb6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemProcessorAdapterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemProcessorAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,20 +21,23 @@ import javax.batch.api.chunk.ItemProcessor; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; public class ItemProcessorAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private ItemProcessorAdapter adapter; @Mock private ItemProcessor delegate; @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - adapter = new ItemProcessorAdapter<>(delegate); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemReaderAdapterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemReaderAdapterTests.java index a944c2975f..b3ba4a5018 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemReaderAdapterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemReaderAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,11 @@ import javax.batch.api.chunk.ItemReader; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; @@ -35,6 +36,9 @@ public class ItemReaderAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private ItemReaderAdapter adapter; @Mock private ItemReader delegate; @@ -43,8 +47,6 @@ public class ItemReaderAdapterTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - adapter = new ItemReaderAdapter<>(delegate); adapter.setName("jsrReader"); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemWriterAdapterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemWriterAdapterTests.java index 85bc6a2238..7c7c023b5a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemWriterAdapterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/jsr/item/ItemWriterAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2018 the original author or authors. + * Copyright 2013-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +21,11 @@ import javax.batch.api.chunk.ItemWriter; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; @@ -35,6 +36,9 @@ public class ItemWriterAdapterTests { + @Rule + public MockitoRule rule = MockitoJUnit.rule().silent(); + private ItemWriterAdapter adapter; @Mock private ItemWriter delegate; @@ -43,7 +47,6 @@ public class ItemWriterAdapterTests { @Before public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); adapter = new ItemWriterAdapter<>(delegate); adapter.setName("jsrWriter");