Remove some deprecated APIs from tests
The following deprecated APIs are not in use anymore in the project's tests: - `org.junit.rules.ExpectedException#none` - `org.mockito.MockitoAnnotations#initMocks` - `org.mockito.Mockito#verifyZeroInteractions` Issue #3838
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
7242f8fe77
commit
24422b5163
@@ -23,9 +23,7 @@ import java.util.Map;
|
||||
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;
|
||||
@@ -34,6 +32,7 @@ import org.springframework.batch.core.launch.support.RunIdIncrementer;
|
||||
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;
|
||||
@@ -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");
|
||||
@@ -204,10 +200,10 @@ public class JobParametersBuilderTests {
|
||||
|
||||
@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
|
||||
|
||||
@@ -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;
|
||||
@@ -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(
|
||||
@@ -116,20 +113,22 @@ public class JobScopeConfigurationTests {
|
||||
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
|
||||
@@ -144,11 +143,12 @@ public class JobScopeConfigurationTests {
|
||||
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 {
|
||||
|
||||
@@ -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;
|
||||
@@ -42,6 +41,7 @@ import org.springframework.lang.Nullable;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -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(
|
||||
@@ -114,20 +111,23 @@ public class StepScopeConfigurationTests {
|
||||
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
|
||||
@@ -142,11 +142,13 @@ public class StepScopeConfigurationTests {
|
||||
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 {
|
||||
|
||||
@@ -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;
|
||||
@@ -32,9 +30,6 @@ import static org.junit.Assert.fail;
|
||||
|
||||
public class JsrSplitParsingTests extends AbstractJsrTestCase {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testOneFlowInSplit() {
|
||||
try {
|
||||
|
||||
@@ -26,11 +26,10 @@ import org.aopalliance.intercept.MethodInterceptor;
|
||||
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;
|
||||
@@ -80,9 +79,6 @@ import static org.junit.Assert.assertTrue;
|
||||
*/
|
||||
public class FaultTolerantStepFactoryBeanTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
protected final Log logger = LogFactory.getLog(getClass());
|
||||
|
||||
private FaultTolerantStepFactoryBean<String, String> factory;
|
||||
@@ -142,25 +138,29 @@ public class FaultTolerantStepFactoryBeanTests {
|
||||
}
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,10 +26,9 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
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.BatchStatus;
|
||||
import org.springframework.batch.core.ChunkListener;
|
||||
import org.springframework.batch.core.ItemProcessListener;
|
||||
@@ -66,9 +65,6 @@ import org.springframework.lang.Nullable;
|
||||
*/
|
||||
public class SimpleStepFactoryBeanTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
private List<Exception> listened = new ArrayList<>();
|
||||
|
||||
private SimpleJobRepository repository = new SimpleJobRepository(new MapJobInstanceDao(), new MapJobExecutionDao(),
|
||||
@@ -99,25 +95,29 @@ public class SimpleStepFactoryBeanTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMandatoryReader() throws Exception {
|
||||
public void testMandatoryReader() {
|
||||
// given
|
||||
SimpleStepFactoryBean<String, String> factory = new SimpleStepFactoryBean<>();
|
||||
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 {
|
||||
public void testMandatoryWriter() {
|
||||
// given
|
||||
SimpleStepFactoryBean<String, String> factory = new SimpleStepFactoryBean<>();
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user