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();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-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.
@@ -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 @@ import static org.mockito.Mockito.when;
*/
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");

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,9 +23,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.springframework.batch.item.SpELItemKeyMapper;
import org.springframework.data.gemfire.GemfireTemplate;
import org.springframework.core.convert.converter.Converter;
@@ -33,13 +35,15 @@ import org.springframework.core.convert.converter.Converter;
@SuppressWarnings("serial")
public class GemfireItemWriterTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
private GemfireItemWriter<String, Foo> 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"));

View File

@@ -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.
@@ -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.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Order;
@@ -44,6 +45,9 @@ import static org.mockito.Mockito.when;
*/
public class MongoItemReaderTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
private MongoItemReader<String> 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<>();

View File

@@ -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.
@@ -21,6 +21,7 @@ import java.util.List;
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.verify;
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 @@ import static org.mockito.ArgumentMatchers.eq;
@SuppressWarnings("serial")
public class MongoItemWriterTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
private MongoItemWriter<Object> 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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 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.
@@ -20,11 +20,12 @@ import java.util.Collections;
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 @@ import static org.mockito.Mockito.when;
public class Neo4jItemReaderTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
@Mock
private Iterable<String> result;
@Mock
@@ -45,11 +49,6 @@ public class Neo4jItemReaderTests {
@Mock
private Session session;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
private Neo4jItemReader<String> buildSessionBasedReader() throws Exception {
Neo4jItemReader<String> reader = new Neo4jItemReader<>();

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.
@@ -18,10 +18,11 @@ package org.springframework.batch.item.data;
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 @@ import static org.mockito.Mockito.when;
public class Neo4jItemWriterTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
private Neo4jItemWriter<String> 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{

View File

@@ -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.List;
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 @@ import static org.mockito.Mockito.when;
@SuppressWarnings("serial")
public class RepositoryItemReaderTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
private RepositoryItemReader<Object> reader;
@Mock
private PagingAndSortingRepository<Object, Integer> 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);

View File

@@ -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.
@@ -27,13 +27,17 @@ 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.data.repository.CrudRepository;
public class RepositoryItemWriterTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
@Mock
private CrudRepository<String, Serializable> 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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-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.util.Arrays;
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 @@ import static org.mockito.Mockito.verify;
* @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");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-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.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.springframework.batch.item.data.MongoItemReader;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoOperations;
@@ -44,6 +45,9 @@ import static org.mockito.Mockito.when;
* @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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-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.
@@ -21,6 +21,7 @@ import java.util.List;
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.when;
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 @@ import static org.mockito.ArgumentMatchers.eq;
* @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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-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.util.Arrays;
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 @@ import static org.mockito.Mockito.when;
*/
public class Neo4jItemReaderBuilderTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
@Mock
private Iterable<String> 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<String> itemReader = new Neo4jItemReaderBuilder<String>()

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-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.
@@ -19,10 +19,11 @@ package org.springframework.batch.item.data.builder;
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 @@ import static org.mockito.Mockito.when;
*/
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<String> writer = new Neo4jItemWriterBuilder<String>().sessionFactory(this.sessionFactory).build();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-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.List;
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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-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,11 +20,11 @@ import java.io.Serializable;
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 @@ import static org.mockito.Mockito.verify;
* @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 {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017 the original author or authors.
* Copyright 2017-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.
@@ -21,10 +21,11 @@ import java.util.List;
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 @@ import static org.mockito.Mockito.when;
*/
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);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-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,10 +22,11 @@ import javax.persistence.EntityManagerFactory;
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 @@ import static org.mockito.Mockito.verify;
*/
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));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018-2020 the original author or authors.
* Copyright 2018-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.
@@ -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 @@ import static org.springframework.test.util.ReflectionTestUtils.getField;
*/
public class JsonItemReaderBuilderTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
@Mock
private Resource resource;
@Mock
private JsonObjectReader<String> jsonObjectReader;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void testValidation() {
try {

View File

@@ -20,10 +20,11 @@ import java.util.List;
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 @@ import static org.mockito.Mockito.times;
public class KafkaItemWriterTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
@Mock
private KafkaTemplate<String, String> 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();

View File

@@ -21,8 +21,8 @@ import org.junit.Rule;
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 @@ import static org.junit.Assert.assertTrue;
*/
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();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020 the original author or authors.
* Copyright 2020-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.
@@ -15,20 +15,21 @@
*/
package org.springframework.batch.item.support;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.mockito.Mock;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamWriter;
import static org.mockito.Mockito.verify;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static org.mockito.Mockito.verify;
import static org.mockito.MockitoAnnotations.initMocks;
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;
/**
* Common parent class for {@link SynchronizedItemStreamWriterTests} and
@@ -39,6 +40,9 @@ import static org.mockito.MockitoAnnotations.initMocks;
*/
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();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-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.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.springframework.batch.item.ItemProcessor;
import org.springframework.batch.item.support.CompositeItemProcessor;
@@ -38,6 +39,9 @@ import static org.mockito.Mockito.when;
*/
public class CompositeItemProcessorBuilderTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
@Mock
private ItemProcessor<Object, Object> 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);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-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.
@@ -21,11 +21,11 @@ import java.nio.charset.StandardCharsets;
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 {
"<second>five</second><third>six</third></foo><foo><first>7</first>" +
"<second>eight</second><third>nine</third></foo></foos>";
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
@Mock
private Resource resource;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
}
@Test
public void testValidation() {
try {

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.
@@ -21,20 +21,23 @@ import static org.mockito.Mockito.when;
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<String, String> adapter;
@Mock
private ItemProcessor delegate;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
adapter = new ItemProcessorAdapter<>(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.
@@ -21,10 +21,11 @@ import java.util.List;
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 @@ import static org.mockito.Mockito.when;
public class ItemReaderAdapterTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
private ItemReaderAdapter<String> 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");
}

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.
@@ -21,10 +21,11 @@ import java.util.List;
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 @@ import static org.mockito.Mockito.when;
public class ItemWriterAdapterTests {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
private ItemWriterAdapter<String> 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");