Skip to content

Commit

Permalink
Replace #initMocks with MockitoRule
Browse files Browse the repository at this point in the history
Replace all references of MockitoAnnotations#initMocks with the
MockitoRule JUnit rule.
  • Loading branch information
marschall committed Mar 13, 2021
1 parent 3fbfbb9 commit 0fb0e41
Show file tree
Hide file tree
Showing 37 changed files with 249 additions and 170 deletions.
@@ -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.
Expand All @@ -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;
Expand All @@ -39,7 +44,6 @@ public class ChunkListenerAdapterTests {

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
adapter = new ChunkListenerAdapter(delegate);
}

Expand Down
@@ -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.
Expand All @@ -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<String, String> adapter;
@Mock
private ItemProcessListener delegate;

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
adapter = new ItemProcessListenerAdapter<>(delegate);
}

Expand Down
@@ -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.
Expand All @@ -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<String> adapter;
@Mock
private ItemReadListener delegate;

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
adapter = new ItemReadListenerAdapter<>(delegate);
}

Expand Down
@@ -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.
Expand All @@ -25,21 +25,25 @@
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;
private List items = new ArrayList();

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
adapter = new ItemWriteListenerAdapter<>(delegate);
}

Expand Down
@@ -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.
Expand All @@ -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);
}

Expand Down
@@ -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.
Expand All @@ -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;
Expand All @@ -34,6 +36,9 @@

public class JsrJobContextTests {

@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();

private JsrJobContext context;
@Mock
private JobExecution execution;
Expand All @@ -42,7 +47,6 @@ public class JsrJobContextTests {

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);

Properties properties = new Properties();
properties.put("jobLevelProperty1", "jobLevelValue1");
Expand Down
@@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -45,6 +47,9 @@

public class JsrStepContextFactoryBeanTests {

@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();

private JsrStepContextFactoryBean factory;
@Mock
private BatchPropertyContext propertyContext;
Expand All @@ -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);
}
Expand Down
@@ -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.
Expand All @@ -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;
Expand All @@ -40,8 +45,6 @@ public class StepListenerAdapterTests {

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);

adapter = new StepListenerAdapter(delegate);
}

Expand Down
@@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -79,6 +80,9 @@
*/
public class JsrJobOperatorTests extends AbstractJsrTestCase {

@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();

private JobOperator jsrJobOperator;
@Mock
private JobExplorer jobExplorer;
Expand All @@ -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());
}
Expand Down
@@ -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.
Expand All @@ -24,16 +24,21 @@
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;
import org.springframework.batch.repeat.RepeatStatus;

public class BatchletAdapterTests {

@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();

private BatchletAdapter adapter;
@Mock
private Batchlet delegate;
Expand All @@ -42,8 +47,6 @@ public class BatchletAdapterTests {

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);

adapter = new BatchletAdapter(delegate);
}

Expand Down

0 comments on commit 0fb0e41

Please sign in to comment.