Skip to content

Remove some deprecated APIs from tests #3962

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
Expand Up @@ -23,9 +23,7 @@
import java.util.Properties;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.job.SimpleJob;
Expand All @@ -34,6 +32,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -59,9 +58,6 @@ public class JobParametersBuilderTests {

private Date date = new Date(System.currentTimeMillis());

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Before
public void initialize() {
this.job = new SimpleJob("simpleJob");
Expand Down Expand Up @@ -204,10 +200,10 @@ public void testGetNextJobParametersFirstRun(){

@Test
public void testGetNextJobParametersNoIncrementer(){
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("No job parameters incrementer found for job=simpleJob");
initializeForNextJobParameters();
this.parametersBuilder.getNextJobParameters(this.job);
final Exception expectedException = assertThrows(IllegalArgumentException.class,
() -> this.parametersBuilder.getNextJobParameters(this.job));
assertEquals("No job parameters incrementer found for job=simpleJob", expectedException.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
package org.springframework.batch.core.configuration.annotation;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.concurrent.Callable;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobInstance;
Expand Down Expand Up @@ -57,9 +57,6 @@ public class JobScopeConfigurationTests {

private JobExecution jobExecution;

@Rule
public ExpectedException expected = ExpectedException.none();

@Test
public void testXmlJobScopeWithProxyTargetClass() throws Exception {
context = new ClassPathXmlApplicationContext(
Expand Down Expand Up @@ -116,20 +113,22 @@ public void testJobScopeWithProxyTargetClassInjected() throws Exception {
public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
init(JobScopeConfigurationRequiringProxyTargetClass.class);
JobSynchronizationManager.release();
expected.expect(BeanCreationException.class);
expected.expectMessage("job scope");
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("JOB", value.call());
final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("JOB", value.call());
});
assertTrue(expectedException.getMessage().contains("job scope"));
}

@Test
public void testIntentionallyBlowupWithForcedInterface() throws Exception {
init(JobScopeConfigurationForcingInterfaceProxy.class);
JobSynchronizationManager.release();
expected.expect(BeanCreationException.class);
expected.expectMessage("job scope");
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("JOB", value.call());
final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("JOB", value.call());
});
assertTrue(expectedException.getMessage().contains("job scope"));
}

@Test
Expand All @@ -144,11 +143,12 @@ public void testJobScopeWithDefaults() throws Exception {
public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
init(JobScopeConfigurationWithDefaults.class);
JobSynchronizationManager.release();
expected.expect(BeanCreationException.class);
expected.expectMessage("job scope");
@SuppressWarnings("unchecked")
Callable<String> value = context.getBean(Callable.class);
assertEquals("JOB", value.call());
final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
@SuppressWarnings("unchecked")
Callable<String> value = context.getBean(Callable.class);
assertEquals("JOB", value.call());
});
assertTrue(expectedException.getMessage().contains("job scope"));
}

public void init(Class<?>... config) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
package org.springframework.batch.core.configuration.annotation;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.scope.context.ChunkContext;
Expand All @@ -42,6 +41,7 @@
import java.util.concurrent.Callable;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

/**
* @author Dave Syer
Expand All @@ -55,9 +55,6 @@ public class StepScopeConfigurationTests {

private StepExecution stepExecution;

@Rule
public ExpectedException expected = ExpectedException.none();

@Test
public void testXmlStepScopeWithProxyTargetClass() throws Exception {
context = new ClassPathXmlApplicationContext(
Expand Down Expand Up @@ -114,20 +111,23 @@ public void testStepScopeWithProxyTargetClassInjected() throws Exception {
public void testIntentionallyBlowUpOnMissingContextWithProxyTargetClass() throws Exception {
init(StepScopeConfigurationRequiringProxyTargetClass.class);
StepSynchronizationManager.release();
expected.expect(BeanCreationException.class);
expected.expectMessage("step scope");
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("STEP", value.call());

final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("STEP", value.call());
});
assertTrue(expectedException.getMessage().contains("step scope"));
}

@Test
public void testIntentionallyBlowupWithForcedInterface() throws Exception {
init(StepScopeConfigurationForcingInterfaceProxy.class);
StepSynchronizationManager.release();
expected.expect(BeanCreationException.class);
expected.expectMessage("step scope");
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("STEP", value.call());
final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
SimpleHolder value = context.getBean(SimpleHolder.class);
assertEquals("STEP", value.call());
});
assertTrue(expectedException.getMessage().contains("step scope"));
}

@Test
Expand All @@ -142,11 +142,13 @@ public void testStepScopeWithDefaults() throws Exception {
public void testIntentionallyBlowUpOnMissingContextWithInterface() throws Exception {
init(StepScopeConfigurationWithDefaults.class);
StepSynchronizationManager.release();
expected.expect(BeanCreationException.class);
expected.expectMessage("step scope");
@SuppressWarnings("unchecked")
Callable<String> value = context.getBean(Callable.class);
assertEquals("STEP", value.call());

final Exception expectedException = Assert.assertThrows(BeanCreationException.class, () -> {
@SuppressWarnings("unchecked")
Callable<String> value = context.getBean(Callable.class);
assertEquals("STEP", value.call());
});
assertTrue(expectedException.getMessage().contains("step scope"));
}

public void init(Class<?>... config) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ChunkListenerAdapterTests {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ItemProcessListenerAdapterTests {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ItemReadListenerAdapterTests {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ItemWriteListenerAdapterTests {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class JobListenerAdapterTests {

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class JsrJobContextTests {

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

Properties properties = new Properties();
properties.put("jobLevelProperty1", "jobLevelValue1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void setUpClass() throws Exception {

@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
factory = new JsrStepContextFactoryBean();
factory.setBatchPropertyContext(propertyContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class StepListenerAdapterTests {

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

adapter = new StepListenerAdapter(delegate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
package org.springframework.batch.core.jsr.configuration.xml;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.batch.core.jsr.AbstractJsrTestCase;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.RuntimeBeanReference;
Expand All @@ -32,9 +30,6 @@

public class JsrSplitParsingTests extends AbstractJsrTestCase {

@Rule
public ExpectedException expectedException = ExpectedException.none();

@Test
public void testOneFlowInSplit() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public class JsrJobOperatorTests extends AbstractJsrTestCase {
@Before
public void setup() throws Exception {

MockitoAnnotations.initMocks(this);
MockitoAnnotations.openMocks(this);
parameterConverter = new JobParametersConverterSupport();
jsrJobOperator = new JsrJobOperator(jobExplorer, jobRepository, parameterConverter, new ResourcelessTransactionManager());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class BatchletAdapterTests {

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

adapter = new BatchletAdapter(delegate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,10 @@
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.junit.rules.ExpectedException;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ChunkListener;
Expand Down Expand Up @@ -80,9 +79,6 @@
*/
public class FaultTolerantStepFactoryBeanTests {

@Rule
public ExpectedException expectedException = ExpectedException.none();

protected final Log logger = LogFactory.getLog(getClass());

private FaultTolerantStepFactoryBean<String, String> factory;
Expand Down Expand Up @@ -142,25 +138,29 @@ public void setUp() throws Exception {
}

@Test
public void testMandatoryReader() throws Exception {
public void testMandatoryReader() {
// given
factory = new FaultTolerantStepFactoryBean<>();
factory.setItemWriter(writer);

expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("ItemReader must be provided");
// when
final Exception expectedException = Assert.assertThrows(IllegalStateException.class, factory::getObject);

factory.getObject();
// then
assertEquals("ItemReader must be provided", expectedException.getMessage());
}

@Test
public void testMandatoryWriter() throws Exception {
// given
factory = new FaultTolerantStepFactoryBean<>();
factory.setItemReader(reader);

expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("ItemWriter must be provided");
// when
final Exception expectedException = Assert.assertThrows(IllegalStateException.class, factory::getObject);

factory.getObject();
// then
assertEquals("ItemWriter must be provided", expectedException.getMessage());
}

/**
Expand Down
Loading