Replace #initMocks with MockitoRule

Replace all references of MockitoAnnotations#initMocks with the
MockitoRule JUnit rule.
This commit is contained in:
Philippe Marschall
2020-11-15 19:10:42 +01:00
committed by Mahmoud Ben Hassine
parent 8258325413
commit 2aa94d09d1
37 changed files with 261 additions and 182 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 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.
@@ -23,14 +23,19 @@ import javax.batch.api.chunk.listener.ChunkListener;
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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 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,19 +22,23 @@ import javax.batch.api.chunk.listener.ItemProcessListener;
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<String, String> adapter;
@Mock
private ItemProcessListener delegate;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
adapter = new ItemProcessListenerAdapter<>(delegate);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 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,19 +22,23 @@ import javax.batch.api.chunk.listener.ItemReadListener;
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<String> adapter;
@Mock
private ItemReadListener delegate;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
adapter = new ItemReadListenerAdapter<>(delegate);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 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.
@@ -25,13 +25,18 @@ import javax.batch.api.chunk.listener.ItemWriteListener;
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<String> 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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 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,19 +22,23 @@ import javax.batch.api.listener.JobListener;
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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 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,9 +22,11 @@ import static org.mockito.Mockito.when;
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 @@ import org.springframework.batch.core.JobParametersBuilder;
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");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-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.
@@ -32,9 +32,11 @@ import javax.batch.runtime.context.StepContext;
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 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor;
public class JsrStepContextFactoryBeanTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
private JsrStepContextFactoryBean factory;
@Mock
private BatchPropertyContext propertyContext;
@@ -60,7 +65,6 @@ public class JsrStepContextFactoryBeanTests {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
factory = new JsrStepContextFactoryBean();
factory.setBatchPropertyContext(propertyContext);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013 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.
@@ -24,14 +24,19 @@ import javax.batch.api.listener.StepListener;
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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2018 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.
@@ -35,11 +35,12 @@ import javax.batch.runtime.BatchStatus;
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 @@ import static org.mockito.Mockito.when;
*/
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());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2014 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.
@@ -24,9 +24,11 @@ import javax.batch.api.Batchlet;
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 @@ import org.springframework.batch.repeat.RepeatStatus;
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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2019 the original author or authors.
* Copyright 2008-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.
@@ -20,10 +20,11 @@ import java.io.File;
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 @@ import static org.mockito.Mockito.when;
*/
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();