Skip to content

Replace #initMocks with MockitoRule #3805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
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
Original file line number Diff line number Diff line change
@@ -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.
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
Original file line number Diff line number Diff line change
@@ -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.
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
Original file line number Diff line number Diff line change
@@ -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.
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
Original file line number Diff line number Diff line change
@@ -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.
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
Original file line number Diff line number Diff line change
@@ -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.
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
Original file line number Diff line number Diff line change
@@ -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.
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
Original file line number Diff line number Diff line change
@@ -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.
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
Original file line number Diff line number Diff line change
@@ -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.
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
Original file line number Diff line number Diff line change
@@ -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.
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
Loading