diff --git a/spring-batch-infrastructure/pom.xml b/spring-batch-infrastructure/pom.xml index 5fc2fe633f..577050e10b 100644 --- a/spring-batch-infrastructure/pom.xml +++ b/spring-batch-infrastructure/pom.xml @@ -170,16 +170,16 @@ - junit - junit - ${junit.version} + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter.version} + test + + + org.junit.jupiter + junit-jupiter-params + ${junit-jupiter.version} test - - - org.hamcrest - hamcrest-core - - org.hamcrest @@ -303,7 +303,7 @@ org.mockito - mockito-core + mockito-junit-jupiter ${mockito.version} test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/config/DatasourceTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/config/DatasourceTests.java index 121fb0c845..0a66e998cc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/config/DatasourceTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/config/DatasourceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,19 +16,16 @@ package org.springframework.batch.config; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.annotation.Transactional; -import org.junit.runner.RunWith; -import org.junit.Test; +import org.junit.jupiter.api.Test; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") +@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml") public class DatasourceTests { @Autowired diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/config/MessagingTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/config/MessagingTests.java index b56a8f7c49..50304760c5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/config/MessagingTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/config/MessagingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,28 +16,25 @@ package org.springframework.batch.config; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") +@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml") public class MessagingTests { @Autowired private JmsTemplate jmsTemplate; - @Before + @BeforeEach public void onSetUp() throws Exception { Thread.sleep(100L); getMessages(); // drain queue diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java index 12848bdd7f..9edcdb6580 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,8 +15,8 @@ */ package org.springframework.batch.container.jms; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.SortedSet; import java.util.TreeSet; @@ -29,11 +29,10 @@ import jakarta.jms.MessageListener; import jakarta.jms.TextMessage; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsTemplate; @@ -44,16 +43,14 @@ import org.springframework.retry.support.DefaultRetryState; import org.springframework.retry.support.RetryTemplate; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Dave Syer * @author Mahmoud Ben Hassine * */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") +@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml") @DirtiesContext public class BatchMessageListenerContainerIntegrationTests { @@ -67,8 +64,8 @@ public class BatchMessageListenerContainerIntegrationTests { private volatile BlockingQueue processed = new LinkedBlockingQueue<>(); - @After - @Before + @AfterEach + @BeforeEach public void drainQueue() throws Exception { container.stop(); while (jmsTemplate.receiveAndConvert("queue") != null) { @@ -77,7 +74,7 @@ public void drainQueue() throws Exception { processed.clear(); } - @AfterClass + @AfterAll public static void giveContainerTimeToStop() throws Exception { Thread.sleep(1000); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java index 207485f645..76f6c874cc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -26,17 +26,17 @@ import jakarta.jms.Session; import org.aopalliance.aop.Advice; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.interceptor.RepeatOperationsInterceptor; import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; import org.springframework.util.ReflectionUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -66,7 +66,7 @@ public void onMessage(Message arg0) { when(consumer.receive(1000)).thenReturn(message); boolean received = doExecute(session, consumer); - assertTrue("Message not received", received); + assertTrue(received, "Message not received"); } @@ -86,7 +86,7 @@ public void testReceiveAndExecuteWithCallbackReturningNull() throws Exception { when(session.getTransacted()).thenReturn(false); boolean received = doExecute(session, consumer); - assertFalse("Message not received", received); + assertFalse(received, "Message not received"); } @@ -98,7 +98,7 @@ public void testTransactionalReceiveAndExecuteWithCallbackThrowingException() th container.setSessionTransacted(true); try { boolean received = doTestWithException(new IllegalStateException("No way!"), true, 2); - assertFalse("Message received", received); + assertFalse(received, "Message received"); fail("Expected IllegalStateException"); } catch (IllegalStateException e) { @@ -113,7 +113,7 @@ public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingException() container = getContainer(template); container.setSessionTransacted(false); boolean received = doTestWithException(new IllegalStateException("No way!"), false, 2); - assertTrue("Message not received but listener not transactional so this should be true", received); + assertTrue(received, "Message not received but listener not transactional so this should be true"); } @Test @@ -124,7 +124,7 @@ public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingError() thr container.setSessionTransacted(false); try { boolean received = doTestWithException(new RuntimeException("No way!"), false, 2); - assertTrue("Message not received but listener not transactional so this should be true", received); + assertTrue(received, "Message not received but listener not transactional so this should be true"); } catch (RuntimeException e) { assertEquals("No way!", e.getMessage()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemReaderTests.java index 541f2295d7..b1b9349273 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2010 the original author or authors. + * Copyright 2009-2022 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,11 +15,11 @@ */ package org.springframework.batch.item; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.sample.Foo; /** @@ -35,7 +35,7 @@ public abstract class AbstractItemReaderTests { */ protected abstract ItemReader getItemReader() throws Exception; - @Before + @BeforeEach public void setUp() throws Exception { tested = getItemReader(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemStreamItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemStreamItemReaderTests.java index 4d8510e8e8..b509496756 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemStreamItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemStreamItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2012 the original author or authors. + * Copyright 2009-2022 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,12 +15,12 @@ */ package org.springframework.batch.item; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import org.springframework.batch.item.sample.Foo; -import org.junit.Before; -import org.junit.After; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; /** * Common tests for readers implementing both {@link ItemReader} and {@link ItemStream}. @@ -38,13 +38,13 @@ protected ItemStream testedAsStream() { } @Override - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); testedAsStream().open(executionContext); } - @After + @AfterEach public void tearDown() throws Exception { testedAsStream().close(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java index a8f32a0c7e..e8518576b0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ExecutionContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2022 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,16 +15,16 @@ */ package org.springframework.batch.item; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.Serializable; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.util.SerializationUtils; /** @@ -36,7 +36,7 @@ public class ExecutionContextTests { private ExecutionContext context; - @Before + @BeforeEach public void setUp() throws Exception { context = new ExecutionContext(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ItemRecoveryHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ItemRecoveryHandlerTests.java index df0230836d..1132f0d005 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ItemRecoveryHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/ItemRecoveryHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,12 @@ package org.springframework.batch.item; +import org.junit.jupiter.api.Test; import org.springframework.retry.interceptor.MethodInvocationRecoverer; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.fail; -public class ItemRecoveryHandlerTests extends TestCase { +public class ItemRecoveryHandlerTests { MethodInvocationRecoverer recoverer = new MethodInvocationRecoverer() { @Override @@ -29,6 +30,7 @@ public String recover(Object[] data, Throwable cause) { } }; + @Test public void testRecover() throws Exception { try { recoverer.recover(new Object[] { "foo" }, null); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java index 525351e313..734d6ea4c9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/adapter/AbstractDelegatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 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,16 +18,16 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.adapter.AbstractMethodInvokingDelegator.InvocationTargetThrowableWrapper; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for {@link AbstractMethodInvokingDelegator} @@ -44,7 +44,7 @@ private static class ConcreteDelegator extends AbstractMethodInvokingDelegator @@ -37,9 +38,9 @@ */ public class AmqpItemReaderTests { - @Test(expected = IllegalArgumentException.class) + @Test public void testNullAmqpTemplate() { - new AmqpItemReader(null); + assertThrows(IllegalArgumentException.class, () -> new AmqpItemReader(null)); } @Test @@ -96,12 +97,12 @@ public void testTypeMismatch() { } - @Test(expected = IllegalArgumentException.class) + @Test public void testNullItemType() { final AmqpTemplate amqpTemplate = mock(AmqpTemplate.class); final AmqpItemReader amqpItemReader = new AmqpItemReader<>(amqpTemplate); - amqpItemReader.setItemType(null); + assertThrows(IllegalArgumentException.class, () -> amqpItemReader.setItemType(null)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/AmqpItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/AmqpItemWriterTests.java index 980148064d..f237f888ea 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/AmqpItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/AmqpItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2022 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,9 +16,10 @@ package org.springframework.batch.item.amqp; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.amqp.core.AmqpTemplate; import java.util.Arrays; @@ -33,9 +34,9 @@ */ public class AmqpItemWriterTests { - @Test(expected = IllegalArgumentException.class) + @Test public void testNullAmqpTemplate() { - new AmqpItemWriter(null); + assertThrows(IllegalArgumentException.class, () -> new AmqpItemWriter(null)); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemReaderBuilderTests.java index 8acb1b1c47..ff2b523b41 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,28 +16,25 @@ package org.springframework.batch.item.amqp.builder; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.amqp.core.Message; import org.springframework.batch.item.amqp.AmqpItemReader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; /** * @author Glenn Renfro */ +@ExtendWith(MockitoExtension.class) public class AmqpItemReaderBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock AmqpTemplate amqpTemplate; @@ -79,8 +76,8 @@ public void testNullAmqpTemplate() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "amqpTemplate is required.", iae.getMessage()); + assertEquals("amqpTemplate is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemWriterBuilderTests.java index 5f4007dceb..bf700d09ae 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/amqp/builder/AmqpItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2022 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,14 +18,14 @@ import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.amqp.core.AmqpTemplate; import org.springframework.amqp.core.Message; import org.springframework.batch.item.amqp.AmqpItemWriter; import static org.aspectj.bridge.MessageUtil.fail; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -41,8 +41,8 @@ public void testNullAmqpTemplate() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "amqpTemplate is required.", iae.getMessage()); + assertEquals("amqpTemplate is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/AvroItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/AvroItemReaderTests.java index c8c24676ee..8909ee97b2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/AvroItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/AvroItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2022 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,12 +17,14 @@ package org.springframework.batch.item.avro; import org.apache.avro.generic.GenericRecord; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.avro.example.User; import org.springframework.batch.item.avro.support.AvroItemReaderTestSupport; import org.springframework.core.io.ClassPathResource; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * @author David Turanski */ @@ -68,14 +70,16 @@ public void readPojosWithNoEmbeddedSchema() throws Exception { verify(itemReader, plainOldUsers()); } - @Test(expected = IllegalStateException.class) + @Test public void dataResourceDoesNotExist() { - new AvroItemReader(new ClassPathResource("doesnotexist"), schemaResource); + assertThrows(IllegalStateException.class, + () -> new AvroItemReader(new ClassPathResource("doesnotexist"), schemaResource)); } - @Test(expected = IllegalStateException.class) + @Test public void schemaResourceDoesNotExist() { - new AvroItemReader(dataResource, new ClassPathResource("doesnotexist")); + assertThrows(IllegalStateException.class, + () -> new AvroItemReader(dataResource, new ClassPathResource("doesnotexist"))); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/AvroItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/AvroItemWriterTests.java index 7c2cce2357..4c31683721 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/AvroItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/AvroItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2022 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,13 +19,15 @@ import java.io.ByteArrayOutputStream; import org.apache.avro.generic.GenericRecord; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.avro.example.User; import org.springframework.batch.item.avro.support.AvroItemWriterTestSupport; import org.springframework.core.io.WritableResource; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * @author David Turanski * @author Mahmoud Ben Hassine @@ -87,15 +89,16 @@ public void itemWriterWithNoEmbeddedHeaders() throws Exception { } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldFailWitNoOutput() { - new AvroItemWriter<>(null, this.schemaResource, User.class).open(new ExecutionContext()); - + assertThrows(IllegalArgumentException.class, + () -> new AvroItemWriter<>(null, this.schemaResource, User.class).open(new ExecutionContext())); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldFailWitNoType() { - new AvroItemWriter<>(this.output, this.schemaResource, null).open(new ExecutionContext()); + assertThrows(IllegalArgumentException.class, + () -> new AvroItemWriter<>(this.output, this.schemaResource, null).open(new ExecutionContext())); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/builder/AvroItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/builder/AvroItemReaderBuilderTests.java index 034baa975b..336bab70b8 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/builder/AvroItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/builder/AvroItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2022 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,12 +17,14 @@ package org.springframework.batch.item.avro.builder; import org.apache.avro.generic.GenericRecord; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.avro.AvroItemReader; import org.springframework.batch.item.avro.example.User; import org.springframework.batch.item.avro.support.AvroItemReaderTestSupport; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * @author David Turanski */ @@ -66,20 +68,22 @@ public void itemReaderForSpecificType() throws Exception { verify(avroItemReader, avroGeneratedUsers()); } - @Test(expected = IllegalArgumentException.class) + @Test public void itemReaderWithNoSchemaStringShouldFail() { - new AvroItemReaderBuilder().schema("").resource(dataResource).build(); - + assertThrows(IllegalArgumentException.class, + () -> new AvroItemReaderBuilder().schema("").resource(dataResource).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void itemReaderWithPartialConfigurationShouldFail() { - new AvroItemReaderBuilder().resource(dataResource).build(); + assertThrows(IllegalArgumentException.class, + () -> new AvroItemReaderBuilder().resource(dataResource).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void itemReaderWithNoInputsShouldFail() { - new AvroItemReaderBuilder().schema(schemaResource).build(); + assertThrows(IllegalArgumentException.class, + () -> new AvroItemReaderBuilder().schema(schemaResource).build()); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/builder/AvroItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/builder/AvroItemWriterBuilderTests.java index 9c7425b12d..e3d194846f 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/builder/AvroItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/avro/builder/AvroItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 the original author or authors. + * Copyright 2019-2022 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,7 +19,7 @@ import java.io.ByteArrayOutputStream; import org.apache.avro.generic.GenericRecord; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.avro.AvroItemWriter; @@ -27,6 +27,8 @@ import org.springframework.batch.item.avro.support.AvroItemWriterTestSupport; import org.springframework.core.io.WritableResource; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * @author David Turanski */ @@ -90,18 +92,16 @@ public void itemWriterWithNoEmbeddedSchema() throws Exception { } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldFailWitNoOutput() { - - new AvroItemWriterBuilder().type(GenericRecord.class).build(); - + assertThrows(IllegalArgumentException.class, + () -> new AvroItemWriterBuilder().type(GenericRecord.class).build()); } - @Test(expected = IllegalArgumentException.class) + @Test public void shouldFailWitNoType() { - - new AvroItemWriterBuilder<>().resource(output).schema(schemaResource).build(); - + assertThrows(IllegalArgumentException.class, + () -> new AvroItemWriterBuilder<>().resource(output).schema(schemaResource).build()); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java index fad7cb850e..3c4b0930ee 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/GemfireItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the original author or authors. + * Copyright 2013-2022 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,35 +15,31 @@ */ package org.springframework.batch.item.data; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.SpELItemKeyMapper; import org.springframework.data.gemfire.GemfireTemplate; import org.springframework.core.convert.converter.Converter; -@SuppressWarnings("serial") +@ExtendWith(MockitoExtension.class) public class GemfireItemWriterTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - private GemfireItemWriter writer; @Mock private GemfireTemplate template; - @Before + @BeforeEach public void setUp() throws Exception { writer = new GemfireItemWriter<>(); writer.setTemplate(template); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemReaderTests.java index 936150ca85..d73ec32dbc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemReaderTests.java @@ -20,13 +20,12 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort.Order; @@ -34,10 +33,10 @@ import org.springframework.data.mongodb.core.query.Query; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -45,11 +44,9 @@ * @author Michael Minella * @author Parikshit Dutta */ +@ExtendWith(MockitoExtension.class) public class MongoItemReaderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - private MongoItemReader reader; @Mock @@ -57,7 +54,7 @@ public class MongoItemReaderTests { private Map sortOptions; - @Before + @BeforeEach public void setUp() throws Exception { reader = new MongoItemReader<>(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java index 0fe701ab66..451d20ab99 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/MongoItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the original author or authors. + * Copyright 2013-2022 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,12 @@ import java.util.List; import org.bson.Document; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; + +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verifyNoInteractions; @@ -33,8 +35,8 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.times; import static org.mockito.Mockito.never; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; + +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mongodb.core.BulkOperations; @@ -50,8 +52,8 @@ import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -61,11 +63,9 @@ * @author Parikshit Dutta * @author Mahmoud Ben Hassine */ +@ExtendWith(MockitoExtension.class) public class MongoItemWriterTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - private MongoItemWriter writer; @Mock @@ -79,14 +79,14 @@ public class MongoItemWriterTests { private PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); - @Before + @BeforeEach public void setUp() throws Exception { - when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations); - when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations); + lenient().when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations); + lenient().when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations); MappingContext, MongoPersistentProperty> mappingContext = new MongoMappingContext(); MappingMongoConverter mongoConverter = spy(new MappingMongoConverter(this.dbRefResolver, mappingContext)); - when(this.template.getConverter()).thenReturn(mongoConverter); + lenient().when(this.template.getConverter()).thenReturn(mongoConverter); writer = new MongoItemWriter<>(); writer.setTemplate(template); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemReaderTests.java index 50bbdf58bc..4ae434f512 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the original author or authors. + * Copyright 2013-2022 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,28 +20,25 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.SessionFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) public class Neo4jItemReaderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private Iterable result; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java index a4759bf85f..444bc98c40 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/Neo4jItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the original author or authors. + * Copyright 2013-2022 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,25 +18,23 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.SessionFactory; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; +@ExtendWith(MockitoExtension.class) public class Neo4jItemWriterTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - private Neo4jItemWriter writer; @Mock @@ -92,7 +90,7 @@ public void testWriteNullWithSession() throws Exception { writer.setSessionFactory(this.sessionFactory); writer.afterPropertiesSet(); - when(this.sessionFactory.openSession()).thenReturn(this.session); + lenient().when(this.sessionFactory.openSession()).thenReturn(this.session); writer.write(null); verifyNoInteractions(this.session); @@ -105,7 +103,7 @@ public void testWriteNoItemsWithSession() throws Exception { writer.setSessionFactory(this.sessionFactory); writer.afterPropertiesSet(); - when(this.sessionFactory.openSession()).thenReturn(this.session); + lenient().when(this.sessionFactory.openSession()).thenReturn(this.session); writer.write(new ArrayList<>()); verifyNoInteractions(this.session); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java index 459c4e3347..3607bc5cf8 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the original author or authors. + * Copyright 2013-2022 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,13 +21,12 @@ import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.adapter.DynamicMethodInvocationException; import org.springframework.data.domain.Page; @@ -39,24 +38,21 @@ import org.springframework.data.repository.PagingAndSortingRepository; import static java.util.Collections.singletonList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@SuppressWarnings("serial") +@ExtendWith(MockitoExtension.class) public class RepositoryItemReaderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - private RepositoryItemReader reader; @Mock @@ -64,7 +60,7 @@ public class RepositoryItemReaderTests { private Map sorts; - @Before + @BeforeEach public void setUp() throws Exception { sorts = Collections.singletonMap("id", Direction.ASC); reader = new RepositoryItemReader<>(); @@ -202,7 +198,7 @@ public void testJumpToItem() throws Exception { // the page must only actually be fetched on the next "doRead()" call final Object o = reader.doRead(); - assertSame("Fetched object should be at index 85 in the current page", o, objectList.get(85)); + assertSame(o, objectList.get(85), "Fetched object should be at index 85 in the current page"); Pageable pageRequest = pageRequestContainer.getValue(); assertEquals(400, pageRequest.getOffset()); @@ -221,7 +217,7 @@ public void testJumpToItemFirstItemOnPage() throws Exception { reader.jumpToItem(150); verify(repository, never()).findAll(any(Pageable.class)); - assertSame("Fetched object should be the first one in the current page", objectList.get(0), reader.doRead()); + assertSame(objectList.get(0), reader.doRead(), "Fetched object should be the first one in the current page"); Pageable pageRequest = pageRequestContainer.getValue(); assertEquals(150, pageRequest.getOffset()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java index 9a48768d92..4c33c12a21 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/RepositoryItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2021 the original author or authors. + * Copyright 2013-2022 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,8 +15,8 @@ */ package org.springframework.batch.item.data; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; @@ -26,25 +26,22 @@ import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.repository.CrudRepository; +@ExtendWith(MockitoExtension.class) public class RepositoryItemWriterTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private CrudRepository repository; private RepositoryItemWriter writer; - @Before + @BeforeEach public void setUp() throws Exception { writer = new RepositoryItemWriter<>(); writer.setMethodName("save"); @@ -73,8 +70,8 @@ public void testAfterPropertiesSet() throws Exception { } catch (IllegalArgumentException e) { // expected - assertEquals("Wrong message for exception: " + e.getMessage(), "methodName must not be empty.", - e.getMessage()); + assertEquals("methodName must not be empty.", e.getMessage(), + "Wrong message for exception: " + e.getMessage()); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java index 7ed9f2e544..bcb7ea8b61 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/GemfireItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,29 +19,26 @@ import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.SpELItemKeyMapper; import org.springframework.batch.item.data.GemfireItemWriter; import org.springframework.data.gemfire.GemfireTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; /** * @author Glenn Renfro */ +@ExtendWith(MockitoExtension.class) public class GemfireItemWriterBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private GemfireTemplate template; @@ -49,7 +46,7 @@ public class GemfireItemWriterBuilderTests { private List items; - @Before + @BeforeEach public void setUp() { this.items = Arrays.asList(new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val1")), new GemfireItemWriterBuilderTests.Foo(new GemfireItemWriterBuilderTests.Bar("val2"))); @@ -90,8 +87,8 @@ public void testNullTemplate() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", "template is required.", - iae.getMessage()); + assertEquals("template is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } @@ -102,8 +99,8 @@ public void testNullItemKeyMapper() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "itemKeyMapper is required.", iae.getMessage()); + assertEquals("itemKeyMapper is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilderTests.java index d32e6b9576..ab33af8784 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemReaderBuilderTests.java @@ -21,21 +21,20 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.data.MongoItemReader; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.query.Query; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import static org.springframework.data.mongodb.core.query.Criteria.where; @@ -47,11 +46,9 @@ * @author Parikshit Dutta * @author Mahmoud Ben Hassine */ +@ExtendWith(MockitoExtension.class) public class MongoItemReaderBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private MongoOperations template; @@ -59,7 +56,7 @@ public class MongoItemReaderBuilderTests { private ArgumentCaptor queryContainer; - @Before + @BeforeEach public void setUp() throws Exception { this.sortOptions = new HashMap<>(); this.sortOptions.put("name", Sort.Direction.DESC); @@ -72,7 +69,7 @@ public void testBasic() throws Exception { when(template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>()); - assertNull("reader should not return result", reader.read()); + assertNull(reader.read(), "reader should not return result"); Query query = this.queryContainer.getValue(); assertEquals(50, query.getLimit()); @@ -87,7 +84,7 @@ public void testFields() throws Exception { when(this.template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>()); - assertNull("reader should not return result", reader.read()); + assertNull(reader.read(), "reader should not return result"); Query query = this.queryContainer.getValue(); assertEquals(1, query.getFieldsObject().get("name")); @@ -101,7 +98,7 @@ public void testHint() throws Exception { when(this.template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>()); - assertNull("reader should not return result", reader.read()); + assertNull(reader.read(), "reader should not return result"); Query query = this.queryContainer.getValue(); assertEquals("{ $natural : 1}", query.getHint()); @@ -117,7 +114,7 @@ public void testCollection() throws Exception { when(this.template.find(this.queryContainer.capture(), eq(String.class), collectionContainer.capture())) .thenReturn(new ArrayList<>()); - assertNull("reader should not return result", reader.read()); + assertNull(reader.read(), "reader should not return result"); Query query = this.queryContainer.getValue(); assertEquals("{\"name\": \"foo\"}", query.getQueryObject().toJson()); @@ -135,7 +132,7 @@ public void testVarargs() throws Exception { when(this.template.find(this.queryContainer.capture(), eq(String.class), collectionContainer.capture())) .thenReturn(new ArrayList<>()); - assertNull("reader should not return result", reader.read()); + assertNull(reader.read(), "reader should not return result"); Query query = this.queryContainer.getValue(); assertEquals("{\"name\": \"foo\"}", query.getQueryObject().toJson()); @@ -151,7 +148,7 @@ public void testWithoutQueryLimit() throws Exception { when(template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>()); - assertNull("reader should not return result", reader.read()); + assertNull(reader.read(), "reader should not return result"); Query query = this.queryContainer.getValue(); assertEquals(50, query.getLimit()); @@ -164,7 +161,7 @@ public void testWithoutQueryLimitAndPageSize() throws Exception { when(template.find(this.queryContainer.capture(), eq(String.class))).thenReturn(new ArrayList<>()); - assertNull("reader should not return result", reader.read()); + assertNull(reader.read(), "reader should not return result"); Query query = this.queryContainer.getValue(); assertEquals(10, query.getLimit()); @@ -215,11 +212,11 @@ private void validateExceptionMessage(MongoItemReaderBuilder builder, St fail("Exception should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", message, - iae.getMessage()); + assertEquals(message, iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } catch (IllegalStateException ise) { - assertEquals("IllegalStateException message did not match the expected result.", message, ise.getMessage()); + assertEquals(message, ise.getMessage(), "IllegalStateException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java index 9248deb0d3..24bed1a8ac 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/MongoItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,17 +20,17 @@ import java.util.List; import org.bson.Document; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; + +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.spy; -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.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.data.MongoItemWriter; import org.springframework.data.mapping.context.MappingContext; import org.springframework.data.mongodb.core.BulkOperations; @@ -43,8 +43,8 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty; import org.springframework.data.mongodb.core.query.Query; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -54,11 +54,9 @@ * @author Mahmoud Ben Hassine * @author Parikshit Dutta */ +@ExtendWith(MockitoExtension.class) public class MongoItemWriterBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private MongoOperations template; @@ -74,14 +72,14 @@ public class MongoItemWriterBuilderTests { private List removeItems; - @Before + @BeforeEach public void setUp() throws Exception { - when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations); - when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations); + lenient().when(this.template.bulkOps(any(), anyString())).thenReturn(this.bulkOperations); + lenient().when(this.template.bulkOps(any(), any(Class.class))).thenReturn(this.bulkOperations); MappingContext, MongoPersistentProperty> mappingContext = new MongoMappingContext(); mongoConverter = spy(new MappingMongoConverter(this.dbRefResolver, mappingContext)); - when(this.template.getConverter()).thenReturn(mongoConverter); + lenient().when(this.template.getConverter()).thenReturn(mongoConverter); this.saveItems = Arrays.asList(new Item("Foo"), new Item("Bar")); this.removeItems = Arrays.asList(new Item(1), new Item(2)); @@ -130,8 +128,8 @@ public void testNullTemplate() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", "template is required.", - iae.getMessage()); + assertEquals("template is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilderTests.java index b180c58e85..55057a270f 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,29 +20,26 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.SessionFactory; import org.springframework.batch.item.data.Neo4jItemReader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.when; /** * @author Glenn Renfro */ +@ExtendWith(MockitoExtension.class) public class Neo4jItemReaderBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private Iterable result; @@ -64,9 +61,9 @@ public void testFullyQualifiedItemReader() throws Exception { .thenReturn(result); when(result.iterator()).thenReturn(Arrays.asList("foo", "bar", "baz").iterator()); - assertEquals("The expected value was not returned by reader.", "foo", itemReader.read()); - assertEquals("The expected value was not returned by reader.", "bar", itemReader.read()); - assertEquals("The expected value was not returned by reader.", "baz", itemReader.read()); + assertEquals("foo", itemReader.read(), "The expected value was not returned by reader."); + assertEquals("bar", itemReader.read(), "The expected value was not returned by reader."); + assertEquals("baz", itemReader.read(), "The expected value was not returned by reader."); } @Test @@ -80,8 +77,8 @@ public void testCurrentSize() throws Exception { .thenReturn(result); when(result.iterator()).thenReturn(Arrays.asList("foo", "bar", "baz").iterator()); - assertEquals("The expected value was not returned by reader.", "foo", itemReader.read()); - assertNull("The expected value was not should be null.", itemReader.read()); + assertEquals("foo", itemReader.read(), "The expected value was not returned by reader."); + assertNull(itemReader.read(), "The expected value was not should be null."); } @Test @@ -99,7 +96,7 @@ public void testResultsWithMatchAndWhereWithParametersWithSession() throws Excep .thenReturn(result); when(result.iterator()).thenReturn(Arrays.asList("foo", "bar", "baz").iterator()); - assertEquals("The expected value was not returned by reader.", "foo", itemReader.read()); + assertEquals("foo", itemReader.read(), "The expected value was not returned by reader."); } @Test @@ -111,8 +108,8 @@ public void testNoSessionFactory() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "sessionFactory is required.", iae.getMessage()); + assertEquals("sessionFactory is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } @@ -196,8 +193,8 @@ private void validateExceptionMessage(Neo4jItemReaderBuilder builder, String fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", message, - iae.getMessage()); + assertEquals(message, iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java index 38f143c935..be2b221d78 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/Neo4jItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,18 +19,17 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.neo4j.ogm.session.Session; import org.neo4j.ogm.session.SessionFactory; import org.springframework.batch.item.data.Neo4jItemWriter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -38,11 +37,9 @@ /** * @author Glenn Renfro */ +@ExtendWith(MockitoExtension.class) public class Neo4jItemWriterBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private SessionFactory sessionFactory; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilderTests.java index 91ffec3cc0..f0da60f5e3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,28 +21,29 @@ import java.util.List; import java.util.Map; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.data.RepositoryItemReader; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.repository.PagingAndSortingRepository; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; /** * @author Glenn Renfro * @author Drummond Dawson */ +@ExtendWith(MockitoExtension.class) public class RepositoryItemReaderBuilderTests { private static final String ARG1 = "foo"; @@ -53,9 +54,6 @@ public class RepositoryItemReaderBuilderTests { private static final String TEST_CONTENT = "FOOBAR"; - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private TestRepository repository; @@ -66,7 +64,7 @@ public class RepositoryItemReaderBuilderTests { private ArgumentCaptor pageRequestContainer; - @Before + @BeforeEach public void setUp() throws Exception { this.sorts = new HashMap<>(); this.sorts.put("id", Sort.Direction.ASC); @@ -74,9 +72,9 @@ public void setUp() throws Exception { List testResult = new ArrayList<>(); testResult.add(TEST_CONTENT); - when(page.getContent()).thenReturn(testResult); - when(page.getSize()).thenReturn(5); - when(this.repository.foo(this.pageRequestContainer.capture())).thenReturn(this.page); + lenient().when(page.getContent()).thenReturn(testResult); + lenient().when(page.getSize()).thenReturn(5); + lenient().when(this.repository.foo(this.pageRequestContainer.capture())).thenReturn(this.page); } @Test @@ -84,8 +82,8 @@ public void testBasicRead() throws Exception { RepositoryItemReader reader = new RepositoryItemReaderBuilder<>().repository(this.repository) .sorts(this.sorts).maxItemCount(5).methodName("foo").name("bar").build(); String result = (String) reader.read(); - assertEquals("Result returned from reader was not expected value.", TEST_CONTENT, result); - assertEquals("page size was not expected value.", 10, this.pageRequestContainer.getValue().getPageSize()); + assertEquals(TEST_CONTENT, result, "Result returned from reader was not expected value."); + assertEquals(10, this.pageRequestContainer.getValue().getPageSize(), "page size was not expected value."); } @Test @@ -96,8 +94,8 @@ public void testRepositoryMethodReference() throws Exception { RepositoryItemReader reader = new RepositoryItemReaderBuilder<>().repository(repositoryMethodReference) .sorts(this.sorts).maxItemCount(5).name("bar").build(); String result = (String) reader.read(); - assertEquals("Result returned from reader was not expected value.", TEST_CONTENT, result); - assertEquals("page size was not expected value.", 10, this.pageRequestContainer.getValue().getPageSize()); + assertEquals(TEST_CONTENT, result, "Result returned from reader was not expected value."); + assertEquals(10, this.pageRequestContainer.getValue().getPageSize(), "page size was not expected value."); } @Test @@ -114,7 +112,7 @@ public void testRepositoryMethodReferenceWithArgs() throws Exception { this.pageRequestContainer.capture())).thenReturn(this.page); String result = (String) reader.read(); - assertEquals("Result returned from reader was not expected value.", TEST_CONTENT, result); + assertEquals(TEST_CONTENT, result, "Result returned from reader was not expected value."); verifyMultiArgRead(arg1Captor, arg2Captor, arg3Captor, result); } @@ -122,7 +120,7 @@ public void testRepositoryMethodReferenceWithArgs() throws Exception { public void testCurrentItemCount() throws Exception { RepositoryItemReader reader = new RepositoryItemReaderBuilder<>().repository(this.repository) .sorts(this.sorts).currentItemCount(6).maxItemCount(5).methodName("foo").name("bar").build(); - assertNull("Result returned from reader was not null.", reader.read()); + assertNull(reader.read(), "Result returned from reader was not null."); } @Test @@ -130,7 +128,7 @@ public void testPageSize() throws Exception { RepositoryItemReader reader = new RepositoryItemReaderBuilder<>().repository(this.repository) .sorts(this.sorts).maxItemCount(5).methodName("foo").name("bar").pageSize(2).build(); reader.read(); - assertEquals("page size was not expected value.", 2, this.pageRequestContainer.getValue().getPageSize()); + assertEquals(2, this.pageRequestContainer.getValue().getPageSize(), "page size was not expected value."); } @Test @@ -141,8 +139,8 @@ public void testNoMethodName() throws Exception { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "methodName is required.", iae.getMessage()); + assertEquals("methodName is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } try { new RepositoryItemReaderBuilder<>().repository(this.repository).sorts(this.sorts).methodName("") @@ -151,8 +149,8 @@ public void testNoMethodName() throws Exception { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "methodName is required.", iae.getMessage()); + assertEquals("methodName is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } @@ -165,8 +163,8 @@ public void testSaveState() throws Exception { fail("IllegalArgumentException should have been thrown"); } catch (IllegalStateException ise) { - assertEquals("IllegalStateException name was not set when saveState was true.", - "A name is required when saveState is set to true.", ise.getMessage()); + assertEquals("A name is required when saveState is set to true.", ise.getMessage(), + "IllegalStateException name was not set when saveState was true."); } // No IllegalStateException for a name that is not set, should not be thrown since // saveState was false. @@ -182,8 +180,8 @@ public void testNullSort() throws Exception { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException sorts did not match the expected result.", "sorts map is required.", - iae.getMessage()); + assertEquals("sorts map is required.", iae.getMessage(), + "IllegalArgumentException sorts did not match the expected result."); } } @@ -195,8 +193,8 @@ public void testNoRepository() throws Exception { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "repository is required.", iae.getMessage()); + assertEquals("repository is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } @@ -244,12 +242,12 @@ public interface TestRepository extends PagingAndSortingRepository arg1Captor, ArgumentCaptor arg2Captor, ArgumentCaptor arg3Captor, String result) { - assertEquals("Result returned from reader was not expected value.", TEST_CONTENT, result); - assertEquals("ARG1 for calling method did not match expected result", ARG1, arg1Captor.getValue()); - assertEquals("ARG2 for calling method did not match expected result", ARG2, arg2Captor.getValue()); - assertEquals("ARG3 for calling method did not match expected result", ARG3, arg3Captor.getValue()); - assertEquals("Result Total Pages did not match expected result", 10, - this.pageRequestContainer.getValue().getPageSize()); + assertEquals(TEST_CONTENT, result, "Result returned from reader was not expected value."); + assertEquals(ARG1, arg1Captor.getValue(), "ARG1 for calling method did not match expected result"); + assertEquals(ARG2, arg2Captor.getValue(), "ARG2 for calling method did not match expected result"); + assertEquals(ARG3, arg3Captor.getValue(), "ARG3 for calling method did not match expected result"); + assertEquals(10, this.pageRequestContainer.getValue().getPageSize(), + "Result Total Pages did not match expected result"); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java index 99a1db72c6..d2b586e120 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/data/builder/RepositoryItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,27 +20,24 @@ import java.util.Collections; import java.util.List; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.data.RepositoryItemWriter; import org.springframework.data.repository.CrudRepository; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.verify; /** * @author Glenn Renfro * @author Mahmoud Ben Hassine */ +@ExtendWith(MockitoExtension.class) public class RepositoryItemWriterBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private TestRepository repository; @@ -52,8 +49,8 @@ public void testNullRepository() throws Exception { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "repository is required.", iae.getMessage()); + assertEquals("repository is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } @@ -65,8 +62,8 @@ public void testEmptyMethodName() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "methodName must not be empty.", iae.getMessage()); + assertEquals("methodName must not be empty.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDataSourceItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDataSourceItemReaderIntegrationTests.java index c80327f56b..048e4d6180 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDataSourceItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDataSourceItemReaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 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,8 +17,8 @@ import javax.sql.DataSource; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; @@ -30,10 +30,10 @@ import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.transaction.annotation.Transactional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Common scenarios for testing {@link ItemReader} implementations which read data from @@ -62,7 +62,7 @@ public void setDataSource(DataSource dataSource) { protected abstract ItemReader createItemReader() throws Exception; - @Before + @BeforeEach public void onSetUpInTransaction() throws Exception { reader = createItemReader(); executionContext = new ExecutionContext(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java index 0b61ca2b39..c2d4e72d55 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractDatabaseItemStreamItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2012 the original author or authors. + * Copyright 2009-2022 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,9 +17,9 @@ import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; @@ -28,21 +28,21 @@ import org.springframework.batch.item.sample.Foo; import org.springframework.context.support.ClassPathXmlApplicationContext; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public abstract class AbstractDatabaseItemStreamItemReaderTests extends AbstractItemStreamItemReaderTests { protected ClassPathXmlApplicationContext ctx; @Override - @Before + @BeforeEach public void setUp() throws Exception { initializeContext(); super.setUp(); } @Override - @After + @AfterEach public void tearDown() throws Exception { super.tearDown(); ctx.close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractGenericDataSourceItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractGenericDataSourceItemReaderIntegrationTests.java index b7d91e51f8..8c21753d4f 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractGenericDataSourceItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractGenericDataSourceItemReaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010 the original author or authors. + * Copyright 2010-2022 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,10 +15,8 @@ */ package org.springframework.batch.item.database; -import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Generic configuration for testing {@link ItemReader} implementations which read data @@ -26,8 +24,7 @@ * * @author Thomas Risberg */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "data-source-context.xml") +@SpringJUnitConfig(locations = "data-source-context.xml") public abstract class AbstractGenericDataSourceItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcItemReaderIntegrationTests.java index 4d2b7cfeda..078b4b5dde 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcItemReaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 the original author or authors. + * Copyright 2008-2022 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,15 +15,15 @@ */ package org.springframework.batch.item.database; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemStream; @@ -59,14 +59,14 @@ public void setDataSource(DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); } - @Before + @BeforeEach public void onSetUp() throws Exception { itemReader = createItemReader(); getAsInitializingBean(itemReader).afterPropertiesSet(); executionContext = new ExecutionContext(); } - @After + @AfterEach public void onTearDown() throws Exception { getAsDisposableBean(itemReader).destroy(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcPagingItemReaderParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcPagingItemReaderParameterTests.java index 97277ad917..143d964f56 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcPagingItemReaderParameterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractJdbcPagingItemReaderParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2022 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,7 +17,7 @@ import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Jimmy Praet diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractPagingItemReaderParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractPagingItemReaderParameterTests.java index 70c0b50314..db351d2743 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractPagingItemReaderParameterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/AbstractPagingItemReaderParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 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,10 +17,10 @@ import javax.sql.DataSource; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.sample.Foo; @@ -39,12 +39,12 @@ public abstract class AbstractPagingItemReaderParameterTests { @Autowired protected DataSource dataSource; - @Before + @BeforeEach public void setUp() throws Exception { tested = getItemReader(); } - @After + @AfterEach public void tearDown() { ((ItemStream) tested).close(); } @@ -55,19 +55,19 @@ public void testRead() throws Exception { ((ItemStream) tested).open(executionContext); Foo foo2 = tested.read(); - Assert.assertEquals(2, foo2.getValue()); + Assertions.assertEquals(2, foo2.getValue()); Foo foo3 = tested.read(); - Assert.assertEquals(3, foo3.getValue()); + Assertions.assertEquals(3, foo3.getValue()); Foo foo4 = tested.read(); - Assert.assertEquals(4, foo4.getValue()); + Assertions.assertEquals(4, foo4.getValue()); Foo foo5 = tested.read(); - Assert.assertEquals(5, foo5.getValue()); + Assertions.assertEquals(5, foo5.getValue()); Object o = tested.read(); - Assert.assertNull(o); + Assertions.assertNull(o); } @Test @@ -77,13 +77,13 @@ public void testReadAfterJumpFirstPage() throws Exception { ((ItemStream) tested).open(executionContext); Foo foo4 = tested.read(); - Assert.assertEquals(4, foo4.getValue()); + Assertions.assertEquals(4, foo4.getValue()); Foo foo5 = tested.read(); - Assert.assertEquals(5, foo5.getValue()); + Assertions.assertEquals(5, foo5.getValue()); Object o = tested.read(); - Assert.assertNull(o); + Assertions.assertNull(o); } @Test @@ -93,10 +93,10 @@ public void testReadAfterJumpSecondPage() throws Exception { ((ItemStream) tested).open(executionContext); Foo foo5 = tested.read(); - Assert.assertEquals(5, foo5.getValue()); + Assertions.assertEquals(5, foo5.getValue()); Object o = tested.read(); - Assert.assertNull(o); + Assertions.assertNull(o); } protected String getName() { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java index 06d2d74f56..118f6846b2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/ExtendedConnectionDataSourceProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2018 the original author or authors. + * Copyright 2009-2022 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,12 +17,13 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.PrintWriter; import java.sql.Connection; @@ -34,7 +35,7 @@ import javax.sql.DataSource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceUtils; @@ -66,29 +67,29 @@ public void testOperationWithDataSourceUtils() throws SQLException { Connection con1 = csds.getConnection(); Connection con2 = csds.getConnection(); - assertNotSame("shouldn't be the same connection", con1, con2); + assertNotSame(con1, con2, "shouldn't be the same connection"); - assertTrue("should be able to close connection", csds.shouldClose(con1)); + assertTrue(csds.shouldClose(con1), "should be able to close connection"); con1.close(); - assertTrue("should be able to close connection", csds.shouldClose(con2)); + assertTrue(csds.shouldClose(con2), "should be able to close connection"); con2.close(); Connection con3 = csds.getConnection(); csds.startCloseSuppression(con3); Connection con3_1 = csds.getConnection(); - assertSame("should be same connection", con3_1, con3); - assertFalse("should not be able to close connection", csds.shouldClose(con3)); + assertSame(con3_1, con3, "should be same connection"); + assertFalse(csds.shouldClose(con3), "should not be able to close connection"); con3_1.close(); // no mock call for this - should be suppressed Connection con3_2 = csds.getConnection(); - assertSame("should be same connection", con3_2, con3); + assertSame(con3_2, con3, "should be same connection"); Connection con4 = csds.getConnection(); - assertNotSame("shouldn't be same connection", con4, con3); + assertNotSame(con4, con3, "shouldn't be same connection"); csds.stopCloseSuppression(con3); - assertTrue("should be able to close connection", csds.shouldClose(con3)); + assertTrue(csds.shouldClose(con3), "should be able to close connection"); con3_1 = null; con3_2 = null; con3.close(); - assertTrue("should be able to close connection", csds.shouldClose(con4)); + assertTrue(csds.shouldClose(con4), "should be able to close connection"); con4.close(); } @@ -108,18 +109,18 @@ public void testOperationWithDirectCloseCall() throws SQLException { Connection con1 = csds.getConnection(); csds.startCloseSuppression(con1); Connection con1_1 = csds.getConnection(); - assertSame("should be same connection", con1_1, con1); + assertSame(con1_1, con1, "should be same connection"); con1_1.close(); // no mock call for this - should be suppressed Connection con1_2 = csds.getConnection(); - assertSame("should be same connection", con1_2, con1); + assertSame(con1_2, con1, "should be same connection"); Connection con2 = csds.getConnection(); - assertNotSame("shouldn't be same connection", con2, con1); + assertNotSame(con2, con1, "shouldn't be same connection"); csds.stopCloseSuppression(con1); - assertTrue("should be able to close connection", csds.shouldClose(con1)); + assertTrue(csds.shouldClose(con1), "should be able to close connection"); con1_1 = null; con1_2 = null; con1.close(); - assertTrue("should be able to close connection", csds.shouldClose(con2)); + assertTrue(csds.shouldClose(con2), "should be able to close connection"); con2.close(); } @@ -227,11 +228,11 @@ public Void doInTransaction(TransactionStatus status) { } - @Test(expected = IllegalArgumentException.class) - public void delegateIsRequired() throws Exception { + @Test + public void delegateIsRequired() { ExtendedConnectionDataSourceProxy tested = new ExtendedConnectionDataSourceProxy(null); - tested.afterPropertiesSet(); + assertThrows(IllegalArgumentException.class, tested::afterPropertiesSet); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderIntegrationTests.java index 421fafa5b2..656a2551a4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2010 the original author or authors. + * Copyright 2008-2022 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,10 +15,10 @@ */ package org.springframework.batch.item.database; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import org.hibernate.StatelessSession; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.sample.Foo; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderStatefulIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderStatefulIntegrationTests.java index 331de3f56b..7f4847293a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderStatefulIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorItemReaderStatefulIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2013 the original author or authors. + * Copyright 2008-2022 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,7 +18,7 @@ import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.query.Query; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.sample.Foo; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorProjectionItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorProjectionItemReaderIntegrationTests.java index 4404c87a5b..cc3872f676 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorProjectionItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateCursorProjectionItemReaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 the original author or authors. + * Copyright 2008-2022 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,28 +19,25 @@ import org.hibernate.SessionFactory; import org.hibernate.StatelessSession; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.orm.hibernate5.LocalSessionFactoryBean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for {@link HibernateCursorItemReader} using {@link StatelessSession}. * * @author Robert Kasanicky */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "data-source-context.xml") +@SpringJUnitConfig(locations = "data-source-context.xml") public class HibernateCursorProjectionItemReaderIntegrationTests { @Autowired diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemReaderHelperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemReaderHelperTests.java index 33d2028489..b0a94a7e17 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemReaderHelperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemReaderHelperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2009 the original author or authors. + * Copyright 2006-2022 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,12 +19,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import org.hibernate.SessionFactory; import org.hibernate.StatelessSession; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.test.util.ReflectionTestUtils; /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemWriterTests.java index 106e5e1569..f747310c86 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/HibernateItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,12 +21,12 @@ import org.hibernate.Session; import org.hibernate.SessionFactory; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -45,7 +45,7 @@ public class HibernateItemWriterTests { Session currentSession; - @Before + @BeforeEach public void setUp() throws Exception { writer = new HibernateItemWriter<>(); factory = mock(SessionFactory.class); @@ -68,7 +68,7 @@ public void testAfterPropertiesSet() throws Exception { } catch (IllegalStateException e) { // expected - assertTrue("Wrong message for exception: " + e.getMessage(), e.getMessage().indexOf("SessionFactory") >= 0); + assertTrue(e.getMessage().contains("SessionFactory"), "Wrong message for exception: " + e.getMessage()); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java index a88b699aef..df3b0671ea 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterClassicTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2008 the original author or authors. + * Copyright 2006-2022 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,7 +15,7 @@ */ package org.springframework.batch.item.database; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -25,8 +25,8 @@ import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.dao.DataAccessException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.jdbc.UncategorizedSQLException; @@ -49,7 +49,7 @@ public class JdbcBatchItemWriterClassicTests { private PreparedStatement ps; - @Before + @BeforeEach public void setUp() throws Exception { ps = mock(PreparedStatement.class); jdbcTemplate = new JdbcTemplate() { @@ -91,8 +91,8 @@ public void testAfterPropertiesSet() throws Exception { catch (IllegalArgumentException e) { // expected String message = e.getMessage(); - assertTrue("Message does not contain ' NamedParameterJdbcTemplate'.", - message.indexOf("NamedParameterJdbcTemplate") >= 0); + assertTrue(message.contains("NamedParameterJdbcTemplate"), + "Message does not contain ' NamedParameterJdbcTemplate'."); } writer.setJdbcTemplate(new NamedParameterJdbcTemplate(jdbcTemplate)); try { @@ -102,7 +102,7 @@ public void testAfterPropertiesSet() throws Exception { catch (IllegalArgumentException e) { // expected String message = e.getMessage().toLowerCase(); - assertTrue("Message does not contain 'sql'.", message.indexOf("sql") >= 0); + assertTrue(message.contains("sql"), "Message does not contain 'sql'."); } writer.setSql("select * from foo where id = ?"); try { @@ -112,8 +112,8 @@ public void testAfterPropertiesSet() throws Exception { catch (IllegalArgumentException e) { // expected String message = e.getMessage(); - assertTrue("Message does not contain 'ItemPreparedStatementSetter'.", - message.indexOf("ItemPreparedStatementSetter") >= 0); + assertTrue(message.contains("ItemPreparedStatementSetter"), + "Message does not contain 'ItemPreparedStatementSetter'."); } writer.setItemPreparedStatementSetter(new ItemPreparedStatementSetter() { @Override @@ -144,7 +144,7 @@ public void testWriteAndFlushWithEmptyUpdate() throws Exception { catch (EmptyResultDataAccessException e) { // expected String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.indexOf("did not update") >= 0); + assertTrue(message.contains("did not update"), "Wrong message: " + message); } assertEquals(2, list.size()); assertTrue(list.contains("SQL")); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java index 008a7cdaea..d14bea82a0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcBatchItemWriterNamedParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,8 +20,8 @@ import org.hamcrest.BaseMatcher; import org.hamcrest.Description; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.dao.EmptyResultDataAccessException; @@ -30,9 +30,9 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; import org.springframework.jdbc.core.namedparam.SqlParameterSource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -82,7 +82,7 @@ public void setBar(String bar) { } - @Before + @BeforeEach public void setUp() throws Exception { namedParameterJdbcOperations = mock(NamedParameterJdbcOperations.class); writer.setSql(sql); @@ -106,8 +106,8 @@ public void testAfterPropertiesSet() throws Exception { catch (IllegalArgumentException e) { // expected String message = e.getMessage(); - assertTrue("Message does not contain 'NamedParameterJdbcTemplate'.", - message.contains("NamedParameterJdbcTemplate")); + assertTrue(message.contains("NamedParameterJdbcTemplate"), + "Message does not contain 'NamedParameterJdbcTemplate'."); } writer.setJdbcTemplate(namedParameterJdbcOperations); try { @@ -117,7 +117,7 @@ public void testAfterPropertiesSet() throws Exception { catch (IllegalArgumentException e) { // expected String message = e.getMessage().toLowerCase(); - assertTrue("Message does not contain 'sql'.", message.contains("sql")); + assertTrue(message.contains("sql"), "Message does not contain 'sql'."); } writer.setSql("select * from foo where id = :id"); @@ -189,7 +189,7 @@ public void testWriteAndFlushWithEmptyUpdate() throws Exception { catch (EmptyResultDataAccessException e) { // expected String message = e.getMessage(); - assertTrue("Wrong message: " + message, message.contains("did not update")); + assertTrue(message.contains("did not update"), "Wrong message: " + message); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java index 804566cdbf..64f164b6af 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 the original author or authors. + * Copyright 2008-2022 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,15 +15,14 @@ */ package org.springframework.batch.item.database; -import org.junit.Test; -import org.junit.runners.JUnit4; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ReaderNotOpenException; import org.springframework.batch.item.sample.Foo; -@RunWith(JUnit4.class) +import static org.junit.jupiter.api.Assertions.assertThrows; + public class JdbcCursorItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests { @Override @@ -63,10 +62,10 @@ protected void pointToEmptyInput(ItemReader tested) throws Exception { reader.open(new ExecutionContext()); } - @Test(expected = ReaderNotOpenException.class) + @Test public void testReadBeforeOpen() throws Exception { tested = getItemReader(); - tested.read(); + assertThrows(ReaderNotOpenException.class, tested::read); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderConfigTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderConfigTests.java index ff963ec2ec..68f80c82a4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderConfigTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 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,9 +20,7 @@ import java.sql.ResultSet; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.batch.item.ExecutionContext; @@ -32,14 +30,13 @@ import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -@RunWith(JUnit4.class) public class JdbcCursorItemReaderConfigTests { /* diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderIntegrationTests.java index f94f336a87..8c2ff07961 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcCursorItemReaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 the original author or authors. + * Copyright 2008-2022 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,17 +15,14 @@ */ package org.springframework.batch.item.database; -import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.sample.Foo; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * Tests for {@link JdbcCursorItemReader} * * @author Robert Kasanicky */ -@RunWith(SpringJUnit4ClassRunner.class) public class JdbcCursorItemReaderIntegrationTests extends AbstractGenericDataSourceItemReaderIntegrationTests { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java index 1b340574fe..60c32b0efb 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderAsyncTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2021 the original author or authors. + * Copyright 2009-2022 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,8 +15,8 @@ */ package org.springframework.batch.item.database; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.sql.ResultSet; import java.sql.SQLException; @@ -36,10 +36,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.database.support.HsqlPagingQueryProvider; @@ -47,12 +46,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml") +@SpringJUnitConfig(locations = "JdbcPagingItemReaderCommonTests-context.xml") public class JdbcPagingItemReaderAsyncTests { /** @@ -77,7 +74,7 @@ public class JdbcPagingItemReaderAsyncTests { private int maxId; - @Before + @BeforeEach public void init() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); Integer maxIdResult = jdbcTemplate.queryForObject("SELECT MAX(ID) from T_FOOS", Integer.class); @@ -88,7 +85,7 @@ public void init() { assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); } - @After + @AfterEach public void destroy() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderClassicParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderClassicParameterTests.java index ec28c97fef..280c676af0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderClassicParameterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderClassicParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2022 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,14 +21,12 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.support.HsqlPagingQueryProvider; import org.springframework.batch.item.sample.Foo; import org.springframework.jdbc.core.RowMapper; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.util.ReflectionTestUtils; /** @@ -37,8 +35,7 @@ * @author Michael Minella * */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = "/org/springframework/batch/item/database/JdbcPagingItemReaderParameterTests-context.xml") public class JdbcPagingItemReaderClassicParameterTests extends AbstractJdbcPagingItemReaderParameterTests { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests.java index d863d05b0c..a7f979d5fe 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2022 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,8 +22,6 @@ import javax.sql.DataSource; -import org.junit.runner.RunWith; - import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; @@ -31,16 +29,14 @@ import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.RowMapper; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * @author Dave Syer * @author Thomas Risberg * @author Michael Minella */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig public class JdbcPagingItemReaderCommonTests extends AbstractItemStreamItemReaderTests { @Autowired diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderConfigTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderConfigTests.java index 460cbb6f28..b2bec1a8d6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderConfigTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2018 the original author or authors. + * Copyright 2008-2022 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,21 +15,18 @@ */ package org.springframework.batch.item.database; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.ContextConfiguration; +import org.junit.jupiter.api.Test; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.test.util.ReflectionTestUtils; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig public class JdbcPagingItemReaderConfigTests { @Autowired diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderEmptyResultSetTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderEmptyResultSetTests.java index 7582730d37..b4dd476383 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderEmptyResultSetTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderEmptyResultSetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 the original author or authors. + * Copyright 2021-2022 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,24 +15,21 @@ */ package org.springframework.batch.item.database; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.Collections; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.database.support.HsqlPagingQueryProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.SingleColumnRowMapper; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml") +@SpringJUnitConfig(locations = "JdbcPagingItemReaderCommonTests-context.xml") public class JdbcPagingItemReaderEmptyResultSetTests { private static final int PAGE_SIZE = 2; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderNamedParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderNamedParameterTests.java index f7ddbe706f..0cc2e03ee2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderNamedParameterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingItemReaderNamedParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2022 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,15 +21,13 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.support.HsqlPagingQueryProvider; import org.springframework.batch.item.sample.Foo; import org.springframework.jdbc.core.RowMapper; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.util.ReflectionTestUtils; /** @@ -37,12 +35,12 @@ * @author Thomas Risberg * @author Michael Minella */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration( +@SpringJUnitConfig( locations = "/org/springframework/batch/item/database/JdbcPagingItemReaderParameterTests-context.xml") -@Ignore("This test fails when integration tests are skipped..") // FIXME make this test - // independent of other - // tests +@Disabled("This test fails when integration tests are skipped..") // FIXME make this test + // independent of + // other + // tests public class JdbcPagingItemReaderNamedParameterTests extends AbstractJdbcPagingItemReaderParameterTests { // force jumpToItemQuery in JdbcPagingItemReader.doJumpToPage(int) diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingQueryIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingQueryIntegrationTests.java index b24504b6a3..e2ce5817cc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingQueryIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingQueryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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. @@ -26,23 +26,21 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.support.AbstractSqlPagingQueryProvider; import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Dave Syer @@ -50,8 +48,7 @@ * @author Mahmoud Ben Hassine * @since 2.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml") +@SpringJUnitConfig(locations = "JdbcPagingItemReaderCommonTests-context.xml") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) public class JdbcPagingQueryIntegrationTests { @@ -68,7 +65,7 @@ public class JdbcPagingQueryIntegrationTests { private int pageSize = 2; - @Before + @BeforeEach public void testInit() { jdbcTemplate = new JdbcTemplate(dataSource); String[] names = { "Foo", "Bar", "Baz", "Foo", "Bar", "Baz", "Foo", "Bar", "Baz" }; @@ -82,7 +79,7 @@ public void testInit() { assertEquals(itemCount, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); } - @After + @AfterEach public void destroy() { JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_FOOS"); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java index 7c931090bd..f38a3b50f0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcPagingRestartIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,9 +16,9 @@ package org.springframework.batch.item.database; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import java.sql.ResultSet; import java.sql.SQLException; @@ -30,11 +30,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; @@ -44,8 +43,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; /** @@ -53,8 +51,7 @@ * @author Michael Minella * @since 2.1 */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "JdbcPagingItemReaderCommonTests-context.xml") +@SpringJUnitConfig(locations = "JdbcPagingItemReaderCommonTests-context.xml") public class JdbcPagingRestartIntegrationTests { private static Log logger = LogFactory.getLog(JdbcPagingRestartIntegrationTests.class); @@ -70,7 +67,7 @@ public class JdbcPagingRestartIntegrationTests { private int pageSize = 2; - @Before + @BeforeEach public void init() { jdbcTemplate = new JdbcTemplate(dataSource); maxId = jdbcTemplate.queryForObject("SELECT MAX(ID) from T_FOOS", Integer.class); @@ -81,13 +78,13 @@ public void init() { assertEquals(itemCount, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); } - @After + @AfterEach public void destroy() { jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); } @Test - @Ignore // FIXME + @Disabled // FIXME public void testReaderFromStart() throws Exception { ItemReader reader = getItemReader(); @@ -110,7 +107,7 @@ public void testReaderFromStart() throws Exception { } @Test - @Ignore // FIXME + @Disabled // FIXME public void testReaderOnRestart() throws Exception { ItemReader reader = getItemReader(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcParameterUtilsTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcParameterUtilsTests.java index d6cf6dc5f5..2c4d2f2c24 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcParameterUtilsTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JdbcParameterUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2022 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,9 +16,8 @@ package org.springframework.batch.item.database; -import static org.junit.Assert.*; -import org.junit.Test; -import org.springframework.batch.item.database.JdbcParameterUtils; +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; import java.util.List; import java.util.ArrayList; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterIntegrationTests.java index ca38e7b0fb..e5e79bcc6b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 the original author or authors. + * Copyright 2019-2022 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,9 @@ import jakarta.persistence.EntityManagerFactory; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.sample.Person; import org.springframework.beans.factory.annotation.Autowired; @@ -38,16 +37,14 @@ import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = JpaItemWriterIntegrationTests.JpaConfiguration.class) +@SpringJUnitConfig(classes = JpaItemWriterIntegrationTests.JpaConfiguration.class) @Transactional @DirtiesContext public class JpaItemWriterIntegrationTests { @@ -58,12 +55,12 @@ public class JpaItemWriterIntegrationTests { @Autowired private JdbcTemplate jdbcTemplate; - @Before + @BeforeEach public void init() { this.jdbcTemplate.update("create table person (id int not null primary key, name varchar(32))"); } - @After + @AfterEach public void destroy() { JdbcTestUtils.dropTables(this.jdbcTemplate, "person"); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterTests.java index ed592d13b6..b17b7a0d3f 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,9 +16,9 @@ package org.springframework.batch.item.database; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -29,8 +29,8 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.orm.jpa.EntityManagerHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -46,7 +46,7 @@ public class JpaItemWriterTests { JpaItemWriter writer; - @Before + @BeforeEach public void setUp() throws Exception { if (TransactionSynchronizationManager.isSynchronizationActive()) { TransactionSynchronizationManager.clearSynchronization(); @@ -65,8 +65,8 @@ public void testAfterPropertiesSet() throws Exception { } catch (IllegalArgumentException e) { // expected - assertTrue("Wrong message for exception: " + e.getMessage(), - e.getMessage().indexOf("EntityManagerFactory") >= 0); + assertTrue(e.getMessage().contains("EntityManagerFactory"), + "Wrong message for exception: " + e.getMessage()); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaNativeQueryProviderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaNativeQueryProviderIntegrationTests.java index cc27124dac..2586808d63 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaNativeQueryProviderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaNativeQueryProviderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,7 +16,7 @@ package org.springframework.batch.item.database; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.List; @@ -24,13 +24,11 @@ import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Query; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.orm.JpaNativeQueryProvider; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.annotation.Transactional; /** @@ -38,8 +36,7 @@ * @author Dave Syer * @author Mahmoud Ben Hassine */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "JpaPagingItemReaderCommonTests-context.xml" }) +@SpringJUnitConfig(locations = { "JpaPagingItemReaderCommonTests-context.xml" }) public class JpaNativeQueryProviderIntegrationTests { @Autowired diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java index 53ceca5768..a7622a49e7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderAsyncTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2021 the original author or authors. + * Copyright 2009-2022 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,8 +15,8 @@ */ package org.springframework.batch.item.database; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.ArrayList; import java.util.HashSet; @@ -33,20 +33,17 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "JpaPagingItemReaderCommonTests-context.xml") +@SpringJUnitConfig(locations = "JpaPagingItemReaderCommonTests-context.xml") public class JpaPagingItemReaderAsyncTests { /** @@ -69,7 +66,7 @@ public class JpaPagingItemReaderAsyncTests { private int maxId; - @Before + @BeforeEach public void init() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); maxId = jdbcTemplate.queryForObject("SELECT MAX(ID) from T_FOOS", Integer.class); @@ -79,7 +76,7 @@ public void init() { assertEquals(ITEM_COUNT, JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_FOOS")); } - @After + @AfterEach public void destroy() { JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); jdbcTemplate.update("DELETE from T_FOOS where ID>?", maxId); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderCommonTests.java index e8d262ca11..39389dbcd7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 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,17 +17,14 @@ import jakarta.persistence.EntityManagerFactory; -import org.junit.runner.RunWith; import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@SpringJUnitConfig public class JpaPagingItemReaderCommonTests extends AbstractItemStreamItemReaderTests { @Autowired diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderNamedQueryIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderNamedQueryIntegrationTests.java index 58f5487e23..59ec3380af 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderNamedQueryIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderNamedQueryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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,13 +17,10 @@ import jakarta.persistence.EntityManagerFactory; -import org.junit.runner.RunWith; - import org.springframework.batch.item.database.orm.JpaNamedQueryProvider; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; /** * Integration Test for {@link JpaPagingItemReader} and {@link JpaNamedQueryProvider}. @@ -31,8 +28,7 @@ * @author Parikshit Dutta * @author Mahmoud Ben Hassine */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "JpaPagingItemReaderCommonTests-context.xml" }) +@SpringJUnitConfig(locations = { "JpaPagingItemReaderCommonTests-context.xml" }) public class JpaPagingItemReaderNamedQueryIntegrationTests extends AbstractPagingItemReaderParameterTests { @Autowired diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderNativeQueryIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderNativeQueryIntegrationTests.java index d6e6d10356..c05f9c63ae 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderNativeQueryIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderNativeQueryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2021 the original author or authors. + * Copyright 2010-2022 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,7 +20,6 @@ import jakarta.persistence.EntityManagerFactory; import javax.sql.DataSource; -import org.junit.runner.RunWith; import org.springframework.batch.item.database.orm.JpaNativeQueryProvider; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; @@ -33,8 +32,7 @@ import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.PlatformTransactionManager; /** @@ -42,8 +40,7 @@ * @author Dave Syer * @author Mahmoud Ben Hassine */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = JpaPagingItemReaderNativeQueryIntegrationTests.JpaConfiguration.class) +@SpringJUnitConfig(classes = JpaPagingItemReaderNativeQueryIntegrationTests.JpaConfiguration.class) public class JpaPagingItemReaderNativeQueryIntegrationTests extends AbstractPagingItemReaderParameterTests { @Autowired diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderParameterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderParameterTests.java index b98b966718..4e77f6b274 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderParameterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/JpaPagingItemReaderParameterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 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,14 +19,11 @@ import jakarta.persistence.EntityManagerFactory; -import org.junit.runner.RunWith; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "JpaPagingItemReaderCommonTests-context.xml") +@SpringJUnitConfig(locations = "JpaPagingItemReaderCommonTests-context.xml") public class JpaPagingItemReaderParameterTests extends AbstractPagingItemReaderParameterTests { @Autowired diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/RepositoryItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/RepositoryItemReaderIntegrationTests.java index f7c397b572..826ffe3fb1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/RepositoryItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/RepositoryItemReaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-2022 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,26 +15,23 @@ */ package org.springframework.batch.item.database; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.List; -import org.junit.After; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.data.RepositoryItemReader; import org.springframework.batch.item.sample.books.Author; import org.springframework.batch.item.sample.books.Book; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.annotation.Transactional; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "RepositoryItemReaderCommonTests-context.xml") +@SpringJUnitConfig(locations = "RepositoryItemReaderCommonTests-context.xml") @Transactional public class RepositoryItemReaderIntegrationTests { @@ -43,7 +40,7 @@ public class RepositoryItemReaderIntegrationTests { @Autowired private RepositoryItemReader reader; - @After + @AfterEach public void reinitializeReader() { reader.close(); } @@ -56,9 +53,9 @@ public void testReadFromFirstPos() throws Exception { assertNotNull(author); final List books = author.getBooks(); - assertEquals("Books list size must be = 2", 2, books.size()); - assertEquals("First book must be author 1 - book 1", "author 1 - book 1", books.get(0).getName()); - assertEquals("Second book must be author 1 - book 2", "author 1 - book 2", books.get(1).getName()); + assertEquals(2, books.size(), "Books list size must be = 2"); + assertEquals("author 1 - book 1", books.get(0).getName(), "First book must be author 1 - book 1"); + assertEquals("author 1 - book 2", books.get(1).getName(), "Second book must be author 1 - book 2"); } @Test @@ -70,9 +67,9 @@ public void testReadFromWithinPage() throws Exception { assertNotNull(author); final List books = author.getBooks(); - assertEquals("Books list size must be = 2", 2, books.size()); - assertEquals("First book must be author 2 - book 1", "author 2 - book 1", books.get(0).getName()); - assertEquals("Second book must be author 2 - book 2", "author 2 - book 2", books.get(1).getName()); + assertEquals(2, books.size(), "Books list size must be = 2"); + assertEquals("author 2 - book 1", books.get(0).getName(), "First book must be author 2 - book 1"); + assertEquals("author 2 - book 2", books.get(1).getName(), "Second book must be author 2 - book 2"); } @Test @@ -85,9 +82,9 @@ public void testReadFromNewPage() throws Exception { assertNotNull(author); final List books = author.getBooks(); - assertEquals("Books list size must be = 2", 2, books.size()); - assertEquals("First book must be author 3 - book 1", "author 3 - book 1", books.get(0).getName()); - assertEquals("Second book must be author 3 - book 2", "author 3 - book 2", books.get(1).getName()); + assertEquals(2, books.size(), "Books list size must be = 2"); + assertEquals("author 3 - book 1", books.get(0).getName(), "First book must be author 3 - book 1"); + assertEquals("author 3 - book 2", books.get(1).getName(), "Second book must be author 3 - book 2"); } @Test @@ -100,9 +97,9 @@ public void testReadFromWithinPage_Restart() throws Exception { assertNotNull(author); final List books = author.getBooks(); - assertEquals("Books list size must be = 2", 2, books.size()); - assertEquals("First book must be author 2 - book 1", "author 2 - book 1", books.get(0).getName()); - assertEquals("Second book must be author 2 - book 2", "author 2 - book 2", books.get(1).getName()); + assertEquals(2, books.size(), "Books list size must be = 2"); + assertEquals("author 2 - book 1", books.get(0).getName(), "First book must be author 2 - book 1"); + assertEquals("author 2 - book 2", books.get(1).getName(), "Second book must be author 2 - book 2"); } @Test @@ -116,9 +113,9 @@ public void testReadFromNewPage_Restart() throws Exception { assertNotNull(author); final List books = author.getBooks(); - assertEquals("Books list size must be = 2", 2, books.size()); - assertEquals("First book must be author 3 - book 1", "author 3 - book 1", books.get(0).getName()); - assertEquals("Second book must be author 3 - book 2", "author 3 - book 2", books.get(1).getName()); + assertEquals(2, books.size(), "Books list size must be = 2"); + assertEquals("author 3 - book 1", books.get(0).getName(), "First book must be author 3 - book 1"); + assertEquals("author 3 - book 2", books.get(1).getName(), "Second book must be author 3 - book 2"); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java index 06b463770b..c2994d928c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2013 the original author or authors. + * Copyright 2010-2022 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,9 +19,7 @@ import java.sql.SQLException; import org.hsqldb.types.Types; -import org.junit.Test; -import org.junit.runners.JUnit4; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ReaderNotOpenException; @@ -30,7 +28,8 @@ import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.SqlParameter; -@RunWith(JUnit4.class) +import static org.junit.jupiter.api.Assertions.assertThrows; + public class StoredProcedureItemReaderCommonTests extends AbstractDatabaseItemStreamItemReaderTests { @Override @@ -82,11 +81,11 @@ public void setValues(PreparedStatement ps) throws SQLException { reader.open(new ExecutionContext()); } - @Test(expected = ReaderNotOpenException.class) + @Test public void testReadBeforeOpen() throws Exception { testedAsStream().close(); tested = getItemReader(); - tested.read(); + assertThrows(ReaderNotOpenException.class, tested::read); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderIntegrationTests.java index f8ef4478ff..6a216699ce 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredProcedureItemReaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010 the original author or authors. + * Copyright 2010-2022 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,14 +15,11 @@ */ package org.springframework.batch.item.database; -import org.junit.runner.RunWith; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.sample.Foo; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "stored-procedure-context.xml") +@SpringJUnitConfig(locations = "stored-procedure-context.xml") public class StoredProcedureItemReaderIntegrationTests extends AbstractDataSourceItemReaderIntegrationTests { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java index 7228d11bb0..8aecfeeaf0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/StoredprocedureItemReaderConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2014 the original author or authors. + * Copyright 2010-2022 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. @@ -28,9 +28,7 @@ import javax.sql.DataSource; import org.hsqldb.types.Types; -import org.junit.Test; -import org.junit.runners.JUnit4; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.jdbc.core.PreparedStatementSetter; import org.springframework.jdbc.core.SqlParameter; @@ -40,7 +38,6 @@ import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -@RunWith(JUnit4.class) public class StoredprocedureItemReaderConfigTests { /* diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilderTests.java index 0e7a43d1d4..18a7f9708d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateCursorItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,9 +20,9 @@ import javax.sql.DataSource; import org.hibernate.SessionFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.database.HibernateCursorItemReader; @@ -39,9 +39,9 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.orm.hibernate5.LocalSessionFactoryBean; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Michael Minella @@ -52,13 +52,13 @@ public class HibernateCursorItemReaderBuilderTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class); this.sessionFactory = (SessionFactory) context.getBean("sessionFactory"); } - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateItemWriterBuilderTests.java index b3d7770ca8..a8d9188502 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernateItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,38 +20,35 @@ import org.hibernate.Session; import org.hibernate.SessionFactory; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.database.HibernateItemWriter; import org.springframework.batch.item.sample.Foo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; /** * @author Michael Minella */ +@ExtendWith(MockitoExtension.class) public class HibernateItemWriterBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private SessionFactory sessionFactory; @Mock private Session session; - @Before + @BeforeEach public void setUp() { - when(this.sessionFactory.getCurrentSession()).thenReturn(this.session); + lenient().when(this.sessionFactory.getCurrentSession()).thenReturn(this.session); } @Test @@ -94,7 +91,7 @@ public void testValidation() { fail("sessionFactory is required"); } catch (IllegalStateException ise) { - assertEquals("Incorrect message", "SessionFactory must be provided", ise.getMessage()); + assertEquals("SessionFactory must be provided", ise.getMessage(), "Incorrect message"); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernatePagingItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernatePagingItemReaderBuilderTests.java index f4b3b12666..0e508238c7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernatePagingItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/HibernatePagingItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,9 +20,9 @@ import javax.sql.DataSource; import org.hibernate.SessionFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.database.HibernateItemReaderHelper; @@ -41,9 +41,9 @@ import org.springframework.orm.hibernate5.LocalSessionFactoryBean; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Michael Minella @@ -55,14 +55,14 @@ public class HibernatePagingItemReaderBuilderTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new AnnotationConfigApplicationContext( HibernatePagingItemReaderBuilderTests.TestDataSourceConfiguration.class); this.sessionFactory = (SessionFactory) context.getBean("sessionFactory"); } - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java index 69fe072d12..2bc0add848 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcBatchItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2022 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,9 +21,9 @@ import java.util.Map; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.JdbcBatchItemWriter; import org.springframework.context.ConfigurableApplicationContext; @@ -43,9 +43,10 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Michael Minella @@ -56,13 +57,13 @@ public class JdbcBatchItemWriterBuilderTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class); this.dataSource = (DataSource) context.getBean("dataSource"); } - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); @@ -120,8 +121,8 @@ public void testBasicPojo() throws Exception { verifyWrite(); } - @Test(expected = EmptyResultDataAccessException.class) - public void testAssertUpdates() throws Exception { + @Test + public void testAssertUpdates() { JdbcBatchItemWriter writer = new JdbcBatchItemWriterBuilder().beanMapped().dataSource(this.dataSource) .sql("UPDATE FOO SET second = :second, third = :third WHERE first = :first").assertUpdates(true) .build(); @@ -132,7 +133,7 @@ public void testAssertUpdates() throws Exception { items.add(new Foo(1, "two", "three")); - writer.write(items); + assertThrows(EmptyResultDataAccessException.class, () -> writer.write(items)); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java index 58bdb82ca3..a4dbb7b9bd 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcCursorItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2022 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,9 +21,9 @@ import java.util.Arrays; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.database.JdbcCursorItemReader; @@ -39,10 +39,10 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Michael Minella @@ -56,13 +56,13 @@ public class JdbcCursorItemReaderBuilderTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class); this.dataSource = (DataSource) context.getBean("dataSource"); } - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilderTests.java index 89ed3babd3..707c441a06 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JdbcPagingItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,9 +19,9 @@ import java.util.Map; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.database.JdbcPagingItemReader; @@ -39,10 +39,10 @@ import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Michael Minella @@ -54,13 +54,13 @@ public class JdbcPagingItemReaderBuilderTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class); this.dataSource = (DataSource) context.getBean("dataSource"); } - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaCursorItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaCursorItemReaderBuilderTests.java index def62f2862..27abfbd620 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaCursorItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaCursorItemReaderBuilderTests.java @@ -23,9 +23,9 @@ import jakarta.persistence.EntityManagerFactory; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.database.JpaCursorItemReader; @@ -44,9 +44,9 @@ import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Mahmoud Ben Hassine @@ -57,14 +57,14 @@ public class JpaCursorItemReaderBuilderTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new AnnotationConfigApplicationContext( JpaCursorItemReaderBuilderTests.TestDataSourceConfiguration.class); this.entityManagerFactory = (EntityManagerFactory) context.getBean("entityManagerFactory"); } - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaItemWriterBuilderTests.java index fc672ea96e..959746d26d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 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,42 +20,39 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.database.JpaItemWriter; import org.springframework.orm.jpa.EntityManagerHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.verify; /** * @author Mahmoud Ben Hassine */ +@ExtendWith(MockitoExtension.class) public class JpaItemWriterBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private EntityManagerFactory entityManagerFactory; @Mock private EntityManager entityManager; - @Before + @BeforeEach public void setUp() { TransactionSynchronizationManager.bindResource(this.entityManagerFactory, new EntityManagerHolder(this.entityManager)); } - @After + @AfterEach public void tearDown() { TransactionSynchronizationManager.unbindResource(this.entityManagerFactory); } @@ -82,7 +79,7 @@ public void testValidation() { fail("Should fail if no EntityManagerFactory is provided"); } catch (IllegalStateException ise) { - assertEquals("Incorrect message", "EntityManagerFactory must be provided", ise.getMessage()); + assertEquals("EntityManagerFactory must be provided", ise.getMessage(), "Incorrect message"); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaPagingItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaPagingItemReaderBuilderTests.java index feb985709a..991959f62a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaPagingItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/JpaPagingItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,9 @@ import jakarta.persistence.EntityManagerFactory; import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.database.JpaPagingItemReader; @@ -44,10 +44,10 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Michael Minella @@ -60,14 +60,14 @@ public class JpaPagingItemReaderBuilderTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new AnnotationConfigApplicationContext( JpaPagingItemReaderBuilderTests.TestDataSourceConfiguration.class); this.entityManagerFactory = (EntityManagerFactory) context.getBean("entityManagerFactory"); } - @After + @AfterEach public void tearDown() { if (this.context != null) { this.context.close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/StoredProcedureItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/StoredProcedureItemReaderBuilderTests.java index 6f98d526da..bb544de5a5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/StoredProcedureItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/builder/StoredProcedureItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-2022 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,9 +17,9 @@ import javax.sql.DataSource; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import test.jdbc.datasource.DataSourceInitializer; import test.jdbc.datasource.DerbyDataSourceFactoryBean; import test.jdbc.datasource.DerbyShutdownBean; @@ -39,10 +39,10 @@ import org.springframework.test.util.ReflectionTestUtils; import org.springframework.transaction.PlatformTransactionManager; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Michael Minella @@ -54,13 +54,13 @@ public class StoredProcedureItemReaderBuilderTests { private ConfigurableApplicationContext context; - @Before + @BeforeEach public void setUp() { this.context = new AnnotationConfigApplicationContext(TestDataSourceConfiguration.class); this.dataSource = (DataSource) this.context.getBean("dataSource"); } - @After + @AfterEach public void tearDown() { this.context.close(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/orm/JpaNamedQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/orm/JpaNamedQueryProviderTests.java index 3bae8657ab..318737fc23 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/orm/JpaNamedQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/orm/JpaNamedQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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,12 +19,12 @@ import jakarta.persistence.Query; import jakarta.persistence.TypedQuery; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.batch.item.sample.Foo; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProviderTests.java index c4f99774f0..8163350eb4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/AbstractSqlPagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2020 the original author or authors. + * Copyright 2006-2022 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,14 +15,14 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.Order; /** @@ -36,7 +36,7 @@ public abstract class AbstractSqlPagingQueryProviderTests { protected int pageSize; - @Before + @BeforeEach public void setUp() { if (pagingQueryProvider == null) { throw new IllegalArgumentException("pagingQueryProvider can't be null"); @@ -55,14 +55,14 @@ public void setUp() { @Test public void testQueryContainsSortKey() { String s = pagingQueryProvider.generateFirstPageQuery(pageSize).toLowerCase(); - assertTrue("Wrong query: " + s, s.contains("id asc")); + assertTrue(s.contains("id asc"), "Wrong query: " + s); } @Test public void testQueryContainsSortKeyDesc() { pagingQueryProvider.getSortKeys().put("id", Order.DESCENDING); String s = pagingQueryProvider.generateFirstPageQuery(pageSize).toLowerCase(); - assertTrue("Wrong query: " + s, s.contains("id desc")); + assertTrue(s.contains("id desc"), "Wrong query: " + s); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/ColumnMapExecutionContextRowMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/ColumnMapExecutionContextRowMapperTests.java index c5fe749d0b..85bcd97fdd 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/ColumnMapExecutionContextRowMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/ColumnMapExecutionContextRowMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 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,13 +21,14 @@ import java.util.LinkedHashMap; import java.util.Map; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Lucas Ward * @author Will Schipp */ -public class ColumnMapExecutionContextRowMapperTests extends TestCase { +public class ColumnMapExecutionContextRowMapperTests { private ColumnMapItemPreparedStatementSetter mapper; @@ -35,10 +36,8 @@ public class ColumnMapExecutionContextRowMapperTests extends TestCase { private PreparedStatement ps; - @Override + @BeforeEach protected void setUp() throws Exception { - super.setUp(); - ps = mock(PreparedStatement.class); mapper = new ColumnMapItemPreparedStatementSetter(); @@ -47,11 +46,13 @@ protected void setUp() throws Exception { key.put("2", Integer.valueOf(2)); } + @Test public void testCreateExecutionContextFromEmptyKeys() throws Exception { mapper.setValues(new HashMap<>(), ps); } + @Test public void testCreateSetter() throws Exception { ps.setObject(1, Integer.valueOf(1)); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/Db2PagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/Db2PagingQueryProviderTests.java index a835e8d0ed..9b1da90c5a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/Db2PagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/Db2PagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Risberg diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactoryTests.java index f88c97d4d6..59b42ba9ea 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactoryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/DefaultDataFieldMaxValueIncrementerFactoryTests.java @@ -17,10 +17,13 @@ import javax.sql.DataSource; -import junit.framework.TestCase; - +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.jdbc.support.incrementer.Db2LuwMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.Db2MainframeMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer; @@ -29,7 +32,6 @@ import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.PostgresSequenceMaxValueIncrementer; -import org.springframework.jdbc.support.incrementer.SqlServerMaxValueIncrementer; import org.springframework.jdbc.support.incrementer.SybaseMaxValueIncrementer; /** @@ -38,23 +40,17 @@ * @author Drummond Dawson * @author Mahmoud Ben Hassine */ -public class DefaultDataFieldMaxValueIncrementerFactoryTests extends TestCase { +public class DefaultDataFieldMaxValueIncrementerFactoryTests { private DefaultDataFieldMaxValueIncrementerFactory factory; - /* - * (non-Javadoc) - * - * @see junit.framework.TestCase#setUp() - */ - @Override + @BeforeEach protected void setUp() throws Exception { - super.setUp(); - DataSource dataSource = mock(DataSource.class); factory = new DefaultDataFieldMaxValueIncrementerFactory(dataSource); } + @Test public void testSupportedDatabaseType() { assertTrue(factory.isSupportedIncrementerType("db2")); assertTrue(factory.isSupportedIncrementerType("db2zos")); @@ -69,10 +65,12 @@ public void testSupportedDatabaseType() { assertTrue(factory.isSupportedIncrementerType("hana")); } + @Test public void testUnsupportedDatabaseType() { assertFalse(factory.isSupportedIncrementerType("invalidtype")); } + @Test public void testInvalidDatabaseType() { try { factory.getIncrementer("invalidtype", "NAME"); @@ -83,6 +81,7 @@ public void testInvalidDatabaseType() { } } + @Test public void testNullIncrementerName() { try { factory.getIncrementer("db2", null); @@ -93,47 +92,58 @@ public void testNullIncrementerName() { } } + @Test public void testDb2() { assertTrue(factory.getIncrementer("db2", "NAME") instanceof Db2LuwMaxValueIncrementer); } + @Test public void testDb2zos() { assertTrue(factory.getIncrementer("db2zos", "NAME") instanceof Db2MainframeMaxValueIncrementer); } + @Test public void testMysql() { assertTrue(factory.getIncrementer("mysql", "NAME") instanceof MySQLMaxValueIncrementer); } + @Test public void testOracle() { factory.setIncrementerColumnName("ID"); assertTrue(factory.getIncrementer("oracle", "NAME") instanceof OracleSequenceMaxValueIncrementer); } + @Test public void testDerby() { assertTrue(factory.getIncrementer("derby", "NAME") instanceof DerbyMaxValueIncrementer); } + @Test public void testHsql() { assertTrue(factory.getIncrementer("hsql", "NAME") instanceof HsqlMaxValueIncrementer); } + @Test public void testPostgres() { assertTrue(factory.getIncrementer("postgres", "NAME") instanceof PostgresSequenceMaxValueIncrementer); } + @Test public void testMsSqlServer() { assertTrue(factory.getIncrementer("sqlserver", "NAME") instanceof SqlServerSequenceMaxValueIncrementer); } + @Test public void testSybase() { assertTrue(factory.getIncrementer("sybase", "NAME") instanceof SybaseMaxValueIncrementer); } + @Test public void testSqlite() { assertTrue(factory.getIncrementer("sqlite", "NAME") instanceof SqliteMaxValueIncrementer); } + @Test public void testHana() { assertTrue(factory.getIncrementer("hana", "NAME") instanceof HanaSequenceMaxValueIncrementer); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/DerbyPagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/DerbyPagingQueryProviderTests.java index 33d906d446..4c182f6616 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/DerbyPagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/DerbyPagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 the original author or authors. + * Copyright 2006-2022 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,17 +17,17 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.sql.Connection; import java.sql.DatabaseMetaData; import javax.sql.DataSource; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.Order; import org.springframework.dao.InvalidDataAccessResourceUsageException; @@ -86,7 +86,7 @@ public void testInitWithUnsupportedVersion() throws Exception { public void testGenerateFirstPageQuery() { String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY id ASC"; String s = pagingQueryProvider.generateFirstPageQuery(pageSize); - Assert.assertEquals(sql, s); + Assertions.assertEquals(sql, s); } @Test @@ -94,7 +94,7 @@ public void testGenerateFirstPageQuery() { public void testGenerateRemainingPagesQuery() { String sql = "SELECT * FROM ( SELECT TMP_ORDERED.*, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?)) ORDER BY id ASC"; String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize); - Assert.assertEquals(sql, s); + Assertions.assertEquals(sql, s); } @Test @@ -102,7 +102,7 @@ public void testGenerateRemainingPagesQuery() { public void testGenerateJumpToItemQuery() { String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC"; String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize); - Assert.assertEquals(sql, s); + Assertions.assertEquals(sql, s); } @Test @@ -110,7 +110,7 @@ public void testGenerateJumpToItemQuery() { public void testGenerateJumpToItemQueryForFirstPage() { String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER () AS ROW_NUMBER FROM (SELECT id, name, age FROM foo WHERE bar = 1 ) AS TMP_ORDERED) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC"; String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize); - Assert.assertEquals(sql, s); + Assertions.assertEquals(sql, s); } /** @@ -121,7 +121,7 @@ public void testGenerateJumpToItemQueryForFirstPage() { @Override public void testQueryContainsSortKey() { String s = pagingQueryProvider.generateFirstPageQuery(pageSize).toLowerCase(); - assertTrue("Wrong query: " + s, s.contains("id asc")); + assertTrue(s.contains("id asc"), "Wrong query: " + s); } /** @@ -133,7 +133,7 @@ public void testQueryContainsSortKey() { public void testQueryContainsSortKeyDesc() { pagingQueryProvider.getSortKeys().put("id", Order.DESCENDING); String s = pagingQueryProvider.generateFirstPageQuery(pageSize).toLowerCase(); - assertTrue("Wrong query: " + s, s.contains("id desc")); + assertTrue(s.contains("id desc"), "Wrong query: " + s); } @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/H2PagingQueryProviderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/H2PagingQueryProviderIntegrationTests.java index ce7b4f466b..54685b3471 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/H2PagingQueryProviderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/H2PagingQueryProviderIntegrationTests.java @@ -15,19 +15,16 @@ */ package org.springframework.batch.item.database.support; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; -import java.util.stream.Collectors; import javax.sql.DataSource; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.h2.engine.Mode.ModeEnum; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import org.springframework.batch.item.database.Order; import org.springframework.jdbc.core.JdbcTemplate; @@ -36,23 +33,17 @@ import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.support.TransactionTemplate; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Henning Pöttker */ -@RunWith(Parameterized.class) public class H2PagingQueryProviderIntegrationTests { - private final String compatibilityMode; - - public H2PagingQueryProviderIntegrationTests(String compatibilityMode) { - this.compatibilityMode = compatibilityMode; - } - - @Test - public void testQueryProvider() { + @ParameterizedTest + @EnumSource(ModeEnum.class) + void testQueryProvider(ModeEnum compatibilityMode) { String connectionUrl = String.format("jdbc:h2:mem:%s;MODE=%s", UUID.randomUUID(), compatibilityMode); DataSource dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", ""); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); @@ -73,11 +64,11 @@ public void testQueryProvider() { queryProvider.setSortKeys(sortKeys); List firstPage = jdbcTemplate.queryForList(queryProvider.generateFirstPageQuery(2), String.class); - assertArrayEquals("firstPage", new String[] { "Spring", "Batch" }, firstPage.toArray()); + assertArrayEquals(new String[] { "Spring", "Batch" }, firstPage.toArray(), "firstPage"); List secondPage = jdbcTemplate.queryForList(queryProvider.generateRemainingPagesQuery(2), String.class, 2); - assertArrayEquals("secondPage", new String[] { "Infrastructure" }, secondPage.toArray()); + assertArrayEquals(new String[] { "Infrastructure" }, secondPage.toArray(), "secondPage"); Integer secondItem = jdbcTemplate.queryForObject(queryProvider.generateJumpToItemQuery(3, 2), Integer.class); @@ -85,10 +76,4 @@ public void testQueryProvider() { }); } - @Parameters - public static List data() throws Exception { - return Arrays.stream(org.h2.engine.Mode.ModeEnum.values()).map(mode -> new Object[] { mode.toString() }) - .collect(Collectors.toList()); - } - } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/H2PagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/H2PagingQueryProviderTests.java index f69f7025cb..f4c488491e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/H2PagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/H2PagingQueryProviderTests.java @@ -15,9 +15,9 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Risberg diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HanaPagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HanaPagingQueryProviderTests.java index 8e2d4ea754..2f189ba5bc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HanaPagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HanaPagingQueryProviderTests.java @@ -18,11 +18,11 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.Order; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Jonathan Bregler diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderIntegrationTests.java index 03f455072d..3e8ecf3e82 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2008 the original author or authors. + * Copyright 2006-2022 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,7 +16,7 @@ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.ArrayList; import java.util.List; @@ -25,25 +25,22 @@ import org.hibernate.query.Query; import org.hibernate.SessionFactory; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.orm.HibernateNativeQueryProvider; import org.springframework.batch.item.sample.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.orm.hibernate5.LocalSessionFactoryBean; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.transaction.annotation.Transactional; /** * @author Anatoly Polinsky * @author Dave Syer */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "../data-source-context.xml") +@SpringJUnitConfig(locations = "../data-source-context.xml") public class HibernateNativeQueryProviderIntegrationTests { protected DataSource dataSource; @@ -62,7 +59,7 @@ public HibernateNativeQueryProviderIntegrationTests() { hibernateQueryProvider.setEntityClass(Foo.class); } - @Before + @BeforeEach public void setUp() throws Exception { LocalSessionFactoryBean factoryBean = new LocalSessionFactoryBean(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderTests.java index 6f46be7ba0..4414e71e13 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HibernateNativeQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2008 the original author or authors. + * Copyright 2006-2022 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,11 +19,11 @@ import org.hibernate.Session; import org.hibernate.StatelessSession; import org.hibernate.query.NativeQuery; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.orm.HibernateNativeQueryProvider; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HsqlPagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HsqlPagingQueryProviderTests.java index 0231ec272f..1b1c06e75b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HsqlPagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/HsqlPagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2015 the original author or authors. + * Copyright 2006-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Risberg diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/JpaNativeQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/JpaNativeQueryProviderTests.java index f656d66279..cbafad79a3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/JpaNativeQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/JpaNativeQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,7 +19,7 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.Query; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.orm.JpaNativeQueryProvider; import org.springframework.batch.item.sample.Foo; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java index f287970149..6aac3d9240 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/MySqlPagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2015 the original author or authors. + * Copyright 2006-2022 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,11 +18,11 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.Order; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Thomas Risberg diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/OraclePagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/OraclePagingQueryProviderTests.java index 52b7f367be..c06af5ca1b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/OraclePagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/OraclePagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012 the original author or authors. + * Copyright 2012-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Risberg diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/PostgresPagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/PostgresPagingQueryProviderTests.java index 7a9822c080..97354edac9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/PostgresPagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/PostgresPagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Risberg @@ -50,7 +50,7 @@ public void testGenerateRemainingPagesQuery() { public void testGenerateJumpToItemQuery() { String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 1 OFFSET 99"; String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize); - assertEquals("Wrong SQL for jump to", sql, s); + assertEquals(sql, s, "Wrong SQL for jump to"); } @Test @@ -58,7 +58,7 @@ public void testGenerateJumpToItemQuery() { public void testGenerateJumpToItemQueryForFirstPage() { String sql = "SELECT id FROM foo WHERE bar = 1 ORDER BY id ASC LIMIT 1 OFFSET 0"; String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize); - assertEquals("Wrong SQL for first page", sql, s); + assertEquals(sql, s, "Wrong SQL for first page"); } @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBeanTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBeanTests.java index 7170960535..defaef222a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBeanTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryProviderFactoryBeanTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 the original author or authors. + * Copyright 2006-2022 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,16 +15,17 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.LinkedHashMap; import java.util.Map; import javax.sql.DataSource; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.Order; import org.springframework.batch.item.database.PagingQueryProvider; import org.springframework.batch.support.DatabaseType; @@ -66,18 +67,16 @@ public void testSingleton() throws Exception { assertEquals(true, factory.isSingleton()); } - @Test(expected = IllegalArgumentException.class) - public void testNoDataSource() throws Exception { + @Test + public void testNoDataSource() { factory.setDataSource(null); - PagingQueryProvider provider = factory.getObject(); - assertNotNull(provider); + assertThrows(IllegalArgumentException.class, factory::getObject); } - @Test(expected = IllegalArgumentException.class) - public void testNoSortKey() throws Exception { + @Test + public void testNoSortKey() { factory.setSortKeys(null); - PagingQueryProvider provider = factory.getObject(); - assertNotNull(provider); + assertThrows(IllegalArgumentException.class, factory::getObject); } @Test @@ -85,28 +84,26 @@ public void testWhereClause() throws Exception { factory.setWhereClause("x=y"); PagingQueryProvider provider = factory.getObject(); String query = provider.generateFirstPageQuery(100); - assertTrue("Wrong query: " + query, query.contains("x=y")); + assertTrue(query.contains("x=y"), "Wrong query: " + query); } @Test public void testAscending() throws Exception { PagingQueryProvider provider = factory.getObject(); String query = provider.generateFirstPageQuery(100); - assertTrue("Wrong query: " + query, query.contains("ASC")); + assertTrue(query.contains("ASC"), "Wrong query: " + query); } - @Test(expected = IllegalArgumentException.class) - public void testWrongDatabaseType() throws Exception { + @Test + public void testWrongDatabaseType() { factory.setDatabaseType("NoSuchDb"); - PagingQueryProvider provider = factory.getObject(); - assertNotNull(provider); + assertThrows(IllegalArgumentException.class, factory::getObject); } - @Test(expected = IllegalArgumentException.class) + @Test public void testMissingMetaData() throws Exception { factory.setDataSource(DatabaseTypeTestUtils.getMockDataSource(new MetaDataAccessException("foo"))); - PagingQueryProvider provider = factory.getObject(); - assertNotNull(provider); + assertThrows(IllegalArgumentException.class, factory::getObject); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryUtilsTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryUtilsTests.java index 1cf0992eea..3e89159d9e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryUtilsTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlPagingQueryUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2015 the original author or authors. + * Copyright 2006-2022 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,14 +16,14 @@ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.Order; import org.springframework.util.StringUtils; @@ -37,7 +37,7 @@ public class SqlPagingQueryUtilsTests { private Map sortKeys; - @Before + @BeforeEach public void setUp() { sortKeys = new LinkedHashMap<>(); sortKeys.put("ID", Order.ASCENDING); @@ -151,11 +151,11 @@ public void testGenerateTopJumpQueryDescending() { sortKeys.put("ID", Order.DESCENDING); AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys); String query = SqlPagingQueryUtils.generateTopJumpToQuery(qp, "TOP 100, 1"); - assertTrue("Wrong query: " + query, query.contains("ID DESC")); - assertEquals("Wrong query: " + query, 0, StringUtils.countOccurrencesOf(query, "ASC")); - assertEquals("Wrong query: " + query, 1, StringUtils.countOccurrencesOf(query, "DESC")); + assertTrue(query.contains("ID DESC"), "Wrong query: " + query); + assertEquals(0, StringUtils.countOccurrencesOf(query, "ASC"), "Wrong query: " + query); + assertEquals(1, StringUtils.countOccurrencesOf(query, "DESC"), "Wrong query: " + query); qp.setWhereClause("BAZ IS NOT NULL"); - assertTrue("Wrong query: " + query, query.contains("ID DESC")); + assertTrue(query.contains("ID DESC"), "Wrong query: " + query); } @Test @@ -163,11 +163,11 @@ public void testGenerateLimitJumpQueryDescending() { sortKeys.put("ID", Order.DESCENDING); AbstractSqlPagingQueryProvider qp = new TestSqlPagingQueryProvider("FOO", "BAR", sortKeys); String query = SqlPagingQueryUtils.generateLimitJumpToQuery(qp, "LIMIT 100, 1"); - assertTrue("Wrong query: " + query, query.contains("ID DESC")); - assertEquals("Wrong query: " + query, 0, StringUtils.countOccurrencesOf(query, "ASC")); - assertEquals("Wrong query: " + query, 1, StringUtils.countOccurrencesOf(query, "DESC")); + assertTrue(query.contains("ID DESC"), "Wrong query: " + query); + assertEquals(0, StringUtils.countOccurrencesOf(query, "ASC"), "Wrong query: " + query); + assertEquals(1, StringUtils.countOccurrencesOf(query, "DESC"), "Wrong query: " + query); qp.setWhereClause("BAZ IS NOT NULL"); - assertTrue("Wrong query: " + query, query.contains("ID DESC")); + assertTrue(query.contains("ID DESC"), "Wrong query: " + query); } private static class TestSqlPagingQueryProvider extends AbstractSqlPagingQueryProvider { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProviderTests.java index 8267490bc2..54fb5b00df 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlServerPagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Risberg diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlServerSequenceMaxValueIncrementerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlServerSequenceMaxValueIncrementerTests.java index 0f271397cf..49f6c9208d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlServerSequenceMaxValueIncrementerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlServerSequenceMaxValueIncrementerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 the original author or authors. + * Copyright 2021-2022 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,18 +17,16 @@ import javax.sql.DataSource; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -import static org.junit.Assert.assertEquals; +import org.mockito.junit.jupiter.MockitoExtension; /** * @author Mahmoud Ben Hassine */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SqlServerSequenceMaxValueIncrementerTests { @Mock @@ -45,7 +43,7 @@ public void testGetSequenceQuery() { String sequenceQuery = this.incrementer.getSequenceQuery(); // then - Assert.assertEquals("select next value for BATCH_JOB_SEQ", sequenceQuery); + Assertions.assertEquals("select next value for BATCH_JOB_SEQ", sequenceQuery); } } \ No newline at end of file diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProviderTests.java index a110b56955..08fb142244 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlWindowingPagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 the original author or authors. + * Copyright 2006-2022 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,14 +15,14 @@ */ package org.springframework.batch.item.database.support; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.database.Order; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Thomas Risberg @@ -39,7 +39,7 @@ public SqlWindowingPagingQueryProviderTests() { public void testGenerateFirstPageQuery() { String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 ORDER BY id ASC"; String s = pagingQueryProvider.generateFirstPageQuery(pageSize); - assertEquals("", sql, s); + assertEquals(sql, s); } @Test @@ -47,7 +47,7 @@ public void testGenerateFirstPageQuery() { public void testGenerateRemainingPagesQuery() { String sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER <= 100 AND ((id > ?)) ORDER BY id ASC"; String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize); - assertEquals("", sql, s); + assertEquals(sql, s); } @Test @@ -55,7 +55,7 @@ public void testGenerateRemainingPagesQuery() { public void testGenerateJumpToItemQuery() { String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 100 ORDER BY id ASC"; String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize); - assertEquals("", sql, s); + assertEquals(sql, s); } @Test @@ -63,7 +63,7 @@ public void testGenerateJumpToItemQuery() { public void testGenerateJumpToItemQueryForFirstPage() { String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) AS TMP_SUB WHERE TMP_SUB.ROW_NUMBER = 1 ORDER BY id ASC"; String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize); - Assert.assertEquals("", sql, s); + Assertions.assertEquals(sql, s); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqliteMaxValueIncrementerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqliteMaxValueIncrementerTests.java index 758947768c..aa813d4932 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqliteMaxValueIncrementerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqliteMaxValueIncrementerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2022 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,13 +15,13 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.File; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.SimpleDriverDataSource; import org.springframework.test.jdbc.JdbcTestUtils; @@ -36,7 +36,7 @@ public class SqliteMaxValueIncrementerTests { static SimpleDriverDataSource dataSource; static JdbcTemplate template; - @BeforeClass + @BeforeAll public static void setUp() { dbFile = System.getProperty("java.io.tmpdir") + File.separator + "batch_sqlite_inc.db"; dataSource = new SimpleDriverDataSource(); @@ -46,7 +46,7 @@ public static void setUp() { template.execute("create table max_value (id integer primary key autoincrement)"); } - @AfterClass + @AfterAll public static void removeDbFile() { File db = new File(dbFile); if (db.exists()) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlitePagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlitePagingQueryProviderTests.java index 6f461750e3..09bf0a04f0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlitePagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SqlitePagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Risberg diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SybasePagingQueryProviderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SybasePagingQueryProviderTests.java index 9c72fb2935..88d84eaa66 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SybasePagingQueryProviderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/database/support/SybasePagingQueryProviderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.database.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Thomas Risberg @@ -34,7 +34,7 @@ public SybasePagingQueryProviderTests() { public void testGenerateFirstPageQuery() { String sql = "SELECT TOP 100 id, name, age FROM foo WHERE bar = 1 ORDER BY id ASC"; String s = pagingQueryProvider.generateFirstPageQuery(pageSize); - assertEquals("", sql, s); + assertEquals(sql, s); } @Test @@ -42,7 +42,7 @@ public void testGenerateFirstPageQuery() { public void testGenerateRemainingPagesQuery() { String sql = "SELECT TOP 100 id, name, age FROM foo WHERE (bar = 1) AND ((id > ?)) ORDER BY id ASC"; String s = pagingQueryProvider.generateRemainingPagesQuery(pageSize); - assertEquals("", sql, s); + assertEquals(sql, s); } @Test @@ -50,7 +50,7 @@ public void testGenerateRemainingPagesQuery() { public void testGenerateJumpToItemQuery() { String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 100 ORDER BY id ASC"; String s = pagingQueryProvider.generateJumpToItemQuery(145, pageSize); - assertEquals("", sql, s); + assertEquals(sql, s); } @Test @@ -58,7 +58,7 @@ public void testGenerateJumpToItemQuery() { public void testGenerateJumpToItemQueryForFirstPage() { String sql = "SELECT id FROM ( SELECT id, ROW_NUMBER() OVER ( ORDER BY id ASC) AS ROW_NUMBER FROM foo WHERE bar = 1) WHERE ROW_NUMBER = 1 ORDER BY id ASC"; String s = pagingQueryProvider.generateJumpToItemQuery(45, pageSize); - assertEquals("", sql, s); + assertEquals(sql, s); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/DefaultBufferedReaderFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/DefaultBufferedReaderFactoryTests.java index 0ca3073fd6..0b5df944b8 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/DefaultBufferedReaderFactoryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/DefaultBufferedReaderFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,11 +15,11 @@ */ package org.springframework.batch.item.file; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.BufferedReader; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.io.ByteArrayResource; /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemReaderTests.java index 811c03460c..c4d10b6f59 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 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,17 +18,18 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.endsWith; import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.IOException; import java.io.InputStream; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemCountAware; @@ -62,7 +63,7 @@ public class FlatFileItemReaderTests { private Resource inputResource1 = getInputResource( "testLine1\ntestLine2\ntestLine3\ntestLine4\ntestLine5\ntestLine6"); - @Before + @BeforeEach public void setUp() { reader.setResource(inputResource1); @@ -433,7 +434,7 @@ public void testRuntimeFileCreation() throws Exception { /** * In strict mode, resource must exist at the time reader is opened. */ - @Test(expected = ItemStreamException.class) + @Test public void testStrictness() throws Exception { Resource resource = new NonExistentResource(); @@ -443,7 +444,7 @@ public void testStrictness() throws Exception { reader.afterPropertiesSet(); - reader.open(executionContext); + assertThrows(ItemStreamException.class, () -> reader.open(executionContext)); } /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemWriterTests.java index 152c10725c..c5ddad754f 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileItemWriterTests.java @@ -28,9 +28,9 @@ import java.util.Collections; import java.util.List; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; @@ -46,12 +46,12 @@ import org.springframework.transaction.support.TransactionTemplate; import org.springframework.util.ClassUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests of regular usage for {@link FlatFileItemWriter} Exception cases will be in @@ -82,7 +82,7 @@ public class FlatFileItemWriterTests { * Create temporary output file, define mock behaviour, set dependencies and * initialize the object under test */ - @Before + @BeforeEach public void setUp() throws Exception { outputFile = File.createTempFile("flatfile-test-output-", ".tmp"); @@ -99,7 +99,7 @@ public void setUp() throws Exception { /** * Release resources and delete the temporary output file */ - @After + @AfterEach public void tearDown() throws Exception { if (reader != null) { reader.close(); @@ -531,9 +531,9 @@ public void testOpenWithNonWritableFile() throws Exception { writer.setResource(file); new File(file.getFile().getParent()).mkdirs(); file.getFile().createNewFile(); - assertTrue("Test file must exist: " + file, file.exists()); - assertTrue("Test file set to read-only: " + file, file.getFile().setReadOnly()); - assertFalse("Should be readonly file: " + file, file.getFile().canWrite()); + assertTrue(file.exists(), "Test file must exist: " + file); + assertTrue(file.getFile().setReadOnly(), "Test file set to read-only: " + file); + assertFalse(file.getFile().canWrite(), "Should be readonly file: " + file); writer.afterPropertiesSet(); try { writer.open(executionContext); @@ -541,7 +541,7 @@ public void testOpenWithNonWritableFile() throws Exception { } catch (IllegalStateException e) { String message = e.getMessage(); - assertTrue("Message does not contain 'writable': " + message, message.indexOf("writable") >= 0); + assertTrue(message.contains("writable"), "Message does not contain 'writable': " + message); } } @@ -844,13 +844,13 @@ public void testAppendToNotYetExistingFile() throws Exception { outputFile = toBeCreated.getFile(); // enable easy content reading and auto-delete // the file - assertFalse("output file does not exist yet", toBeCreated.exists()); + assertFalse(toBeCreated.exists(), "output file does not exist yet"); writer.setResource(toBeCreated); writer.setAppendAllowed(true); writer.afterPropertiesSet(); writer.open(executionContext); - assertTrue("output file was created", toBeCreated.exists()); + assertTrue(toBeCreated.exists(), "output file was created"); writer.write(Collections.singletonList("test1")); writer.close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileParseExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileParseExceptionTests.java index eb8ca0f0b3..34dcf07831 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileParseExceptionTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/FlatFileParseExceptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,8 +16,11 @@ package org.springframework.batch.item.file; +import org.junit.jupiter.api.Test; import org.springframework.batch.support.AbstractExceptionTests; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class FlatFileParseExceptionTests extends AbstractExceptionTests { @Override @@ -30,6 +33,7 @@ public Exception getException(String msg, Throwable t) throws Exception { return new FlatFileParseException(msg, t, "bar", 100); } + @Test public void testMessageInputLineCount() throws Exception { FlatFileParseException exception = new FlatFileParseException("foo", "bar", 100); assertEquals("foo", exception.getMessage()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderFlatFileTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderFlatFileTests.java index bdf721d701..bb680081f1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderFlatFileTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderFlatFileTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 the original author or authors. + * Copyright 2008-2022 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,8 +17,6 @@ import java.util.Comparator; -import org.junit.runners.JUnit4; -import org.junit.runner.RunWith; import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; @@ -26,7 +24,6 @@ import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; -@RunWith(JUnit4.class) public class MultiResourceItemReaderFlatFileTests extends AbstractItemStreamItemReaderTests { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderIntegrationTests.java index 145db1766b..231f36c478 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 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,14 +15,14 @@ */ package org.springframework.batch.item.file; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import java.io.IOException; import java.io.InputStream; import java.util.Comparator; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; @@ -62,7 +62,7 @@ public class MultiResourceItemReaderIntegrationTests { /** * Setup the tested reader to read from the test resources. */ - @Before + @BeforeEach public void setUp() throws Exception { itemReader.setLineMapper(new PassThroughLineMapper()); @@ -406,12 +406,12 @@ public String getDescription() { /** * No resources to read should result in error in strict mode. */ - @Test(expected = IllegalStateException.class) - public void testStrictModeEnabled() throws Exception { + @Test + public void testStrictModeEnabled() { tested.setResources(new Resource[] {}); tested.setStrict(true); - tested.open(ctx); + assertThrows(IllegalStateException.class, () -> tested.open(ctx)); } /** @@ -423,7 +423,7 @@ public void testStrictModeDisabled() throws Exception { tested.setStrict(false); tested.open(ctx); - assertTrue("empty input doesn't cause an error", true); + assertTrue(true, "empty input doesn't cause an error"); } /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderResourceAwareTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderResourceAwareTests.java index 093d1ab644..999b7bb723 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderResourceAwareTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderResourceAwareTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2022 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,15 +15,15 @@ */ package org.springframework.batch.item.file; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ResourceAware; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; import java.util.Comparator; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; /** * Tests to ensure that the current Resource is correctly being set on items that @@ -52,7 +52,7 @@ public class MultiResourceItemReaderResourceAwareTests { /** * Setup the tested reader to read from the test resources. */ - @Before + @BeforeEach public void setUp() throws Exception { itemReader.setLineMapper(new FooLineMapper()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderXmlTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderXmlTests.java index c486e79246..11c04005b1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderXmlTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemReaderXmlTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 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,7 +15,7 @@ */ package org.springframework.batch.item.file; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.util.Comparator; @@ -25,8 +25,6 @@ import javax.xml.stream.events.StartElement; import javax.xml.transform.Source; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemReader; @@ -38,7 +36,6 @@ import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.XmlMappingException; -@RunWith(JUnit4.class) public class MultiResourceItemReaderXmlTests extends AbstractItemStreamItemReaderTests { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemWriterFlatFileTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemWriterFlatFileTests.java index 38b206d1e1..4514d3d808 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemWriterFlatFileTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemWriterFlatFileTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2017 the original author or authors. + * Copyright 2008-2022 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,8 +15,8 @@ */ package org.springframework.batch.item.file; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -24,8 +24,8 @@ import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.PassThroughLineAggregator; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.transaction.TransactionStatus; @@ -65,7 +65,7 @@ public Void doInTransaction(TransactionStatus status) { private FlatFileItemWriter delegate; - @Before + @BeforeEach public void setUp() throws Exception { super.createFile(); delegate = new FlatFileItemWriter<>(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemWriterXmlTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemWriterXmlTests.java index cc103f1cbb..1a6ff625bf 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemWriterXmlTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/MultiResourceItemWriterXmlTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2017 the original author or authors. + * Copyright 2009-2022 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,8 +15,8 @@ */ package org.springframework.batch.item.file; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.File; import java.io.IOException; @@ -26,8 +26,8 @@ import javax.xml.stream.XMLEventWriter; import javax.xml.transform.Result; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.xml.StaxEventItemWriter; import org.springframework.batch.item.xml.StaxTestUtils; import org.springframework.oxm.Marshaller; @@ -45,7 +45,7 @@ public class MultiResourceItemWriterXmlTests extends AbstractMultiResourceItemWr private StaxEventItemWriter delegate; - @Before + @BeforeEach public void setUp() throws Exception { super.createFile(); delegate = new StaxEventItemWriter<>(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/ResourcesItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/ResourcesItemReaderTests.java index 70ee71ed33..8a2863d9ae 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/ResourcesItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/ResourcesItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2013 the original author or authors. + * Copyright 2009-2022 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,10 +15,10 @@ */ package org.springframework.batch.item.file; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; @@ -27,7 +27,7 @@ public class ResourcesItemReaderTests { private ResourcesItemReader reader = new ResourcesItemReader(); - @Before + @BeforeEach public void init() { reader.setResources( new Resource[] { new ByteArrayResource("foo".getBytes()), new ByteArrayResource("bar".getBytes()) }); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactoryTests.java index 250fbb86a1..ecb29d1edc 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactoryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleBinaryBufferedReaderFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,11 +15,11 @@ */ package org.springframework.batch.item.file; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.BufferedReader; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.io.ByteArrayResource; /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleResourceSuffixCreatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleResourceSuffixCreatorTests.java index 323b8d9393..eb6dcc8d4d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleResourceSuffixCreatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/SimpleResourceSuffixCreatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 the original author or authors. + * Copyright 2008-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.file; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link SimpleResourceSuffixCreator}. diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java index b3eb2a5e93..ca0cf06464 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2020 the original author or authors. + * Copyright 2016-2022 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,7 +20,7 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.file.FlatFileItemReader; @@ -40,10 +40,10 @@ import org.springframework.core.io.Resource; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Michael Minella @@ -382,15 +382,17 @@ public void testName() throws Exception { catch (IllegalStateException iae) { assertEquals("A name is required when saveState is set to true.", iae.getMessage()); } - assertNotNull("builder should return new instance of FlatFileItemReader", + assertNotNull( new FlatFileItemReaderBuilder().resource(getResource("1 2 3")).fixedLength() .columns(new Range(1, 3), new Range(4, 6), new Range(7)).names("first", "second", "third") - .targetType(Foo.class).saveState(false).build()); + .targetType(Foo.class).saveState(false).build(), + "builder should return new instance of FlatFileItemReader"); - assertNotNull("builder should return new instance of FlatFileItemReader", + assertNotNull( new FlatFileItemReaderBuilder().resource(getResource("1 2 3")).fixedLength() .columns(new Range(1, 3), new Range(4, 6), new Range(7)).names("first", "second", "third") - .targetType(Foo.class).name("foobar").build()); + .targetType(Foo.class).name("foobar").build(), + "builder should return new instance of FlatFileItemReader"); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java index 2c175eec8f..bb64a88c7a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/FlatFileItemWriterBuilderTests.java @@ -22,7 +22,7 @@ import java.nio.charset.Charset; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; @@ -33,9 +33,10 @@ import org.springframework.core.io.WritableResource; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Michael Minella @@ -48,17 +49,20 @@ public class FlatFileItemWriterBuilderTests { // reads the output file to check the result private BufferedReader reader; - @Test(expected = IllegalArgumentException.class) + @Test public void testMissingLineAggregator() { - new FlatFileItemWriterBuilder().build(); + FlatFileItemWriterBuilder builder = new FlatFileItemWriterBuilder<>(); + assertThrows(IllegalArgumentException.class, builder::build); } - @Test(expected = IllegalStateException.class) + @Test public void testMultipleLineAggregators() throws IOException { WritableResource output = new FileSystemResource(File.createTempFile("foo", "txt")); - new FlatFileItemWriterBuilder().name("itemWriter").resource(output).delimited().delimiter(";") - .names("foo", "bar").formatted().format("%2s%2s").names("foo", "bar").build(); + FlatFileItemWriterBuilder builder = new FlatFileItemWriterBuilder().name("itemWriter") + .resource(output).delimited().delimiter(";").names("foo", "bar").formatted().format("%2s%2s") + .names("foo", "bar"); + assertThrows(IllegalStateException.class, builder::build); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/MultiResourceItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/MultiResourceItemReaderBuilderTests.java index e03c964d7c..a5c65738c9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/MultiResourceItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/MultiResourceItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2022 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,7 +18,7 @@ import java.util.Comparator; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.AbstractItemStreamItemReaderTests; import org.springframework.batch.item.ExecutionContext; @@ -29,8 +29,8 @@ import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; /** @@ -70,8 +70,8 @@ public void testNullDelegate() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException ise) { - assertEquals("IllegalArgumentException message did not match the expected result.", "delegate is required.", - ise.getMessage()); + assertEquals("delegate is required.", ise.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } @@ -83,8 +83,8 @@ public void testNullResources() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException ise) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "resources array is required.", ise.getMessage()); + assertEquals("resources array is required.", ise.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/MultiResourceItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/MultiResourceItemWriterBuilderTests.java index 5dcb8358c7..a494b0240b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/MultiResourceItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/builder/MultiResourceItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2022 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,9 +21,9 @@ import java.io.FileReader; import java.util.Arrays; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.file.FlatFileItemWriter; @@ -34,9 +34,9 @@ import org.springframework.batch.item.file.transform.PassThroughLineAggregator; import org.springframework.core.io.FileSystemResource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Glenn Renfro @@ -58,7 +58,7 @@ public String getSuffix(int index) { private FlatFileItemWriter delegate; - @Before + @BeforeEach public void setUp() throws Exception { this.delegate = new FlatFileItemWriter<>(); this.delegate.setLineAggregator(new PassThroughLineAggregator<>()); @@ -66,7 +66,7 @@ public void setUp() throws Exception { this.writer = null; } - @After + @AfterEach public void tearDown() { if (this.writer != null) { this.writer.close(); @@ -212,8 +212,8 @@ public void testSaveStateNoName() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException ise) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "A name is required when saveState is true.", ise.getMessage()); + assertEquals("A name is required when saveState is true.", ise.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } @@ -226,8 +226,8 @@ public void testNoResource() throws Exception { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException ise) { - assertEquals("IllegalArgumentException message did not match the expected result.", "resource is required.", - ise.getMessage()); + assertEquals("resource is required.", ise.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } @@ -240,8 +240,8 @@ public void testNoDelegateNoName() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException ise) { - assertEquals("IllegalArgumentException message did not match the expected result.", "delegate is required.", - ise.getMessage()); + assertEquals("delegate is required.", ise.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperConcurrentTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperConcurrentTests.java index 58067bce01..1be17623a1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperConcurrentTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperConcurrentTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,7 +16,7 @@ package org.springframework.batch.item.file.mapping; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.Collection; @@ -25,8 +25,8 @@ import java.util.concurrent.Executors; import java.util.concurrent.Future; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; public class BeanWrapperFieldSetMapperConcurrentTests { @@ -49,7 +49,7 @@ public void testConcurrentUsage() throws Exception { public Boolean call() throws Exception { for (int i = 0; i < 10; i++) { GreenBean bean = mapper.mapFieldSet(lineTokenizer.tokenize("blue,green")); - Assert.assertEquals("green", bean.getGreen()); + Assertions.assertEquals("green", bean.getGreen()); } return true; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperFuzzyMatchingTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperFuzzyMatchingTests.java index 13cfd7b9d0..ebe02edcae 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperFuzzyMatchingTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperFuzzyMatchingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,24 +16,26 @@ package org.springframework.batch.item.file.mapping; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; import org.springframework.beans.NotWritablePropertyException; import org.springframework.validation.BindException; +import static org.junit.jupiter.api.Assertions.assertThrows; + public class BeanWrapperFieldSetMapperFuzzyMatchingTests { - @Test(expected = NotWritablePropertyException.class) - public void testFuzzyMatchingWithKeyCandidateCollision() throws BindException { + @Test + public void testFuzzyMatchingWithKeyCandidateCollision() { BeanWrapperFieldSetMapper mapper = new BeanWrapperFieldSetMapper<>(); mapper.setStrict(true); mapper.setTargetType(GreenBean.class); DelimitedLineTokenizer lineTokenizer = new DelimitedLineTokenizer(); String[] names = { "brown", "green", "great", "groin", "braun" }; lineTokenizer.setNames(names); - GreenBean bean = mapper.mapFieldSet(lineTokenizer.tokenize("brown,green,great,groin,braun")); - Assert.assertEquals("green", bean.getGreen()); + assertThrows(NotWritablePropertyException.class, + () -> mapper.mapFieldSet(lineTokenizer.tokenize("brown,green,great,groin,braun"))); } @Test @@ -46,7 +48,7 @@ public void testFuzzyMatchingWithLowerLimit() throws BindException { String[] names = { "brown", "green", "great", "groin", "braun" }; lineTokenizer.setNames(names); GreenBean bean = mapper.mapFieldSet(lineTokenizer.tokenize("brown,green,great,groin,braun")); - Assert.assertEquals("green", bean.getGreen()); + Assertions.assertEquals("green", bean.getGreen()); } @Test @@ -59,8 +61,8 @@ public void testFuzzyMatchingWithPropertyCollision() throws BindException { lineTokenizer.setNames(names); BlueBean bean = mapper.mapFieldSet(lineTokenizer.tokenize("blue")); // An exact match always wins... - Assert.assertEquals("blue", bean.getBlue()); - Assert.assertEquals(null, bean.getBleu()); + Assertions.assertEquals("blue", bean.getBlue()); + Assertions.assertEquals(null, bean.getBleu()); } public static class GreenBean { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java index be029609f0..7a56390808 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/BeanWrapperFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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. @@ -29,9 +29,9 @@ import java.util.Properties; import java.util.TimeZone; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.DefaultFieldSet; import org.springframework.batch.item.file.transform.FieldSet; @@ -51,9 +51,9 @@ import org.springframework.validation.BindException; import org.springframework.validation.DataBinder; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class BeanWrapperFieldSetMapperTests { @@ -61,12 +61,12 @@ public class BeanWrapperFieldSetMapperTests { private TimeZone defaultTimeZone = TimeZone.getDefault(); - @Before + @BeforeEach public void setUp() { TimeZone.setDefault(UTC_TIME_ZONE); } - @After + @AfterEach public void tearDown() { TimeZone.setDefault(defaultTimeZone); } @@ -466,7 +466,7 @@ public void testConversionWithTestConverter() throws Exception { mapper.afterPropertiesSet(); TestObject bean = mapper.mapFieldSet(fieldSet); - assertEquals("Expecting the conversion to have returned \"CONVERTED\"", bean.getVarString(), "CONVERTED"); + assertEquals(bean.getVarString(), "CONVERTED", "Expecting the conversion to have returned \"CONVERTED\""); } @Test @@ -491,17 +491,17 @@ public void testDefaultConversion() throws Exception { TestObject bean = mapper.mapFieldSet(fieldSet); - assertEquals("Expected 12 for varInt", bean.getVarInt(), 12); - assertEquals("Expected 12345 for varLong", bean.getVarLong(), 12345L); - assertEquals("Expected true for varBoolean", bean.isVarBoolean(), true); - assertEquals("Expected Z for varChar", bean.getVarChar(), 'Z'); - assertEquals("Expected A for varByte", bean.getVarByte(), 123); - assertEquals("Expected 12345 for varFloat", bean.getVarFloat(), 12345F, 1F); - assertEquals("Expected 12345 for varDouble", bean.getVarDouble(), 12345D, 1D); - assertEquals("Expected 12 for varShort", bean.getVarShort(), 12); - assertEquals("Expected currentDate for varDate", bean.getVarDate().toString(), dateString); - assertEquals("Expected 12345 for varBigDecimal", bean.getVarBigDecimal(), bigDecimal); - assertEquals("Expected " + sampleString + " for varString", bean.getVarString(), sampleString); + assertEquals(bean.getVarInt(), 12, "Expected 12 for varInt"); + assertEquals(bean.getVarLong(), 12345L, "Expected 12345 for varLong"); + assertEquals(bean.isVarBoolean(), true, "Expected true for varBoolean"); + assertEquals(bean.getVarChar(), 'Z', "Expected Z for varChar"); + assertEquals(bean.getVarByte(), 123, "Expected A for varByte"); + assertEquals(bean.getVarFloat(), 12345F, 1F, "Expected 12345 for varFloat"); + assertEquals(bean.getVarDouble(), 12345D, 1D, "Expected 12345 for varDouble"); + assertEquals(bean.getVarShort(), 12, "Expected 12 for varShort"); + assertEquals(bean.getVarDate().toString(), dateString, "Expected currentDate for varDate"); + assertEquals(bean.getVarBigDecimal(), bigDecimal, "Expected 12345 for varBigDecimal"); + assertEquals(bean.getVarString(), sampleString, "Expected " + sampleString + " for varString"); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java index 0e76fe5404..32c394ef40 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/DefaultLineMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2013 the original author or authors. + * Copyright 2008-2022 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,11 +15,12 @@ */ package org.springframework.batch.item.file.mapping; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertSame; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.DefaultFieldSet; import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; import org.springframework.batch.item.file.transform.FieldSet; @@ -32,17 +33,15 @@ public class DefaultLineMapperTests { private DefaultLineMapper tested = new DefaultLineMapper<>(); - @Test(expected = IllegalArgumentException.class) - public void testMandatoryTokenizer() throws Exception { - tested.afterPropertiesSet(); - tested.mapLine("foo", 1); + @Test + public void testMandatoryTokenizer() { + assertThrows(IllegalArgumentException.class, tested::afterPropertiesSet); } - @Test(expected = IllegalArgumentException.class) - public void testMandatoryMapper() throws Exception { + @Test + public void testMandatoryMapper() { tested.setLineTokenizer(new DelimitedLineTokenizer()); - tested.afterPropertiesSet(); - tested.mapLine("foo", 1); + assertThrows(IllegalArgumentException.class, tested::afterPropertiesSet); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/JsonLineMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/JsonLineMapperTests.java index 6ff2d2584b..37e55fe4f3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/JsonLineMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/JsonLineMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2010 the original author or authors. + * Copyright 2009-2022 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,9 +18,10 @@ import java.util.Map; import com.fasterxml.jackson.core.JsonParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; public class JsonLineMapperTests { @@ -40,10 +41,9 @@ public void testMapNested() throws Exception { assertEquals(2, ((Map) map.get("bar")).get("foo")); } - @Test(expected = JsonParseException.class) - public void testMappingError() throws Exception { - Map map = mapper.mapLine("{\"foo\": 1", 1); - assertEquals(1, map.get("foo")); + @Test + public void testMappingError() { + assertThrows(JsonParseException.class, () -> mapper.mapLine("{\"foo\": 1", 1)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PassThroughFieldSetMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PassThroughFieldSetMapperTests.java index 59b34ffb17..39a19bd72e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PassThroughFieldSetMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PassThroughFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,16 +15,17 @@ */ package org.springframework.batch.item.file.mapping; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.DefaultFieldSet; import org.springframework.batch.item.file.transform.FieldSet; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Dave Syer * */ -public class PassThroughFieldSetMapperTests extends TestCase { +public class PassThroughFieldSetMapperTests { private PassThroughFieldSetMapper mapper = new PassThroughFieldSetMapper(); @@ -32,6 +33,7 @@ public class PassThroughFieldSetMapperTests extends TestCase { * Test method for * {@link org.springframework.batch.item.file.mapping.PassThroughFieldSetMapper#mapFieldSet(org.springframework.batch.item.file.transform.FieldSet)}. */ + @Test public void testMapLine() { FieldSet fieldSet = new DefaultFieldSet(new String[] { "foo", "bar" }); assertEquals(fieldSet, mapper.mapFieldSet(fieldSet)); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PassThroughLineMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PassThroughLineMapperTests.java index e66b2a2e55..c19f985a5e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PassThroughLineMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PassThroughLineMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 the original author or authors. + * Copyright 2008-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.file.mapping; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link PassThroughLineMapper}. diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PatternMatchingCompositeLineMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PatternMatchingCompositeLineMapperTests.java index cf6c41de04..7b96b78750 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PatternMatchingCompositeLineMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PatternMatchingCompositeLineMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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,13 +16,14 @@ package org.springframework.batch.item.file.mapping; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.DefaultFieldSet; import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; import org.springframework.batch.item.file.transform.FieldSet; @@ -39,12 +40,11 @@ public class PatternMatchingCompositeLineMapperTests { private PatternMatchingCompositeLineMapper mapper = new PatternMatchingCompositeLineMapper<>(); - @Test(expected = IllegalArgumentException.class) - public void testNoMappers() throws Exception { + @Test + public void testNoMappers() { mapper.setTokenizers(Collections.singletonMap("", (LineTokenizer) new DelimitedLineTokenizer())); Map> fieldSetMappers = Collections.emptyMap(); - mapper.setFieldSetMappers(fieldSetMappers); - mapper.afterPropertiesSet(); + assertThrows(IllegalArgumentException.class, () -> mapper.setFieldSetMappers(fieldSetMappers)); } @Test @@ -83,7 +83,7 @@ public Name mapFieldSet(FieldSet fs) { assertEquals(new Name("d", "c", 0), name); } - @Test(expected = IllegalStateException.class) + @Test public void testMapperKeyNotFound() throws Exception { Map tokenizers = new HashMap<>(); tokenizers.put("foo*", new LineTokenizer() { @@ -109,8 +109,7 @@ public Name mapFieldSet(FieldSet fs) { }); mapper.setFieldSetMappers(fieldSetMappers); - Name name = mapper.mapLine("bar", 1); - assertEquals(new Name("d", "c", 0), name); + assertThrows(IllegalStateException.class, () -> mapper.mapLine("bar", 1)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PropertyMatchesTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PropertyMatchesTests.java index 5d948b86fc..443cf5caeb 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PropertyMatchesTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/PropertyMatchesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,51 +16,70 @@ package org.springframework.batch.item.file.mapping; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public class PropertyMatchesTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; - public void setDuckSoup(String duckSoup) { - } - - public void setDuckPate(String duckPate) { - } - - public void setDuckBreast(String duckBreast) { - } +public class PropertyMatchesTests { - public void testPropertyMatchesWithMaxDistance() throws Exception { - String[] matches = PropertyMatches.forProperty("DUCK_SOUP", getClass(), 2).getPossibleMatches(); + @Test + public void testPropertyMatchesWithMaxDistance() { + String[] matches = PropertyMatches.forProperty("DUCK_SOUP", PropertyBean.class, 2).getPossibleMatches(); assertEquals(1, matches.length); } - public void testPropertyMatchesWithDefault() throws Exception { - String[] matches = PropertyMatches.forProperty("DUCK_SOUP", getClass()).getPossibleMatches(); + @Test + public void testPropertyMatchesWithDefault() { + String[] matches = PropertyMatches.forProperty("DUCK_SOUP", PropertyBean.class).getPossibleMatches(); assertEquals(1, matches.length); } - public void testBuildErrorMessageNoMatches() throws Exception { - String msg = PropertyMatches.forProperty("foo", getClass(), 2).buildErrorMessage(); - assertTrue(msg.indexOf("foo") >= 0); + @Test + public void testBuildErrorMessageNoMatches() { + String msg = PropertyMatches.forProperty("foo", PropertyBean.class, 2).buildErrorMessage(); + assertTrue(msg.contains("foo")); } - public void testBuildErrorMessagePossibleMatch() throws Exception { - String msg = PropertyMatches.forProperty("DUCKSOUP", getClass(), 1).buildErrorMessage(); + @Test + public void testBuildErrorMessagePossibleMatch() { + String msg = PropertyMatches.forProperty("DUCKSOUP", PropertyBean.class, 1).buildErrorMessage(); // the message contains the close match - assertTrue(msg.indexOf("duckSoup") >= 0); + assertTrue(msg.contains("duckSoup")); } - public void testBuildErrorMessageMultiplePossibleMatches() throws Exception { - String msg = PropertyMatches.forProperty("DUCKCRAP", getClass(), 4).buildErrorMessage(); + @Test + public void testBuildErrorMessageMultiplePossibleMatches() { + String msg = PropertyMatches.forProperty("DUCKCRAP", PropertyBean.class, 4).buildErrorMessage(); // the message contains the close matches - assertTrue(msg.indexOf("duckSoup") >= 0); - assertTrue(msg.indexOf("duckPate") >= 0); + assertTrue(msg.contains("duckSoup")); + assertTrue(msg.contains("duckPate")); } - public void testEmptyString() throws Exception { - String[] matches = PropertyMatches.forProperty("", getClass(), 4).getPossibleMatches(); - // TestCase base class has a name property + @Test + public void testEmptyString() { + String[] matches = PropertyMatches.forProperty("", PropertyBean.class, 4).getPossibleMatches(); assertEquals("name", matches[0]); } + private static class BaseBean { + + public void setName(String name) { + } + + } + + private static class PropertyBean extends BaseBean { + + public void setDuckSoup(String duckSoup) { + } + + public void setDuckPate(String duckPate) { + } + + public void setDuckBreast(String duckBreast) { + } + + } + } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/RecordFieldSetMapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/RecordFieldSetMapperTests.java index 5a94a1a0d4..e4ef27def5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/RecordFieldSetMapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/mapping/RecordFieldSetMapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020 the original author or authors. + * Copyright 2020-2022 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,13 +15,13 @@ */ package org.springframework.batch.item.file.mapping; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.file.transform.DefaultFieldSet; import org.springframework.batch.item.file.transform.FieldSet; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Mahmoud Ben Hassine @@ -38,9 +38,9 @@ public void testMapFieldSet() { Person person = recordFieldSetMapper.mapFieldSet(fieldSet); // then - Assert.assertNotNull(person); - Assert.assertEquals(1, person.id()); - Assert.assertEquals("foo", person.name()); + Assertions.assertNotNull(person); + Assertions.assertEquals(1, person.id()); + Assertions.assertEquals("foo", person.name()); } @Test @@ -56,7 +56,7 @@ public void testMapFieldSetWhenFieldCountIsIncorrect() { } catch (IllegalArgumentException e) { // then - Assert.assertEquals("Fields count must be equal to record components count", e.getMessage()); + Assertions.assertEquals("Fields count must be equal to record components count", e.getMessage()); } } @@ -73,7 +73,7 @@ public void testMapFieldSetWhenFieldNamesAreNotSpecified() { } catch (IllegalArgumentException e) { // then - Assert.assertEquals("Field names must specified", e.getMessage()); + Assertions.assertEquals("Field names must specified", e.getMessage()); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/DefaultRecordSeparatorPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/DefaultRecordSeparatorPolicyTests.java index c20bcd151c..5963fac3c5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/DefaultRecordSeparatorPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/DefaultRecordSeparatorPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,60 +16,75 @@ package org.springframework.batch.item.file.separator; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public class DefaultRecordSeparatorPolicyTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class DefaultRecordSeparatorPolicyTests { DefaultRecordSeparatorPolicy policy = new DefaultRecordSeparatorPolicy(); + @Test public void testNormalLine() throws Exception { assertTrue(policy.isEndOfRecord("a string")); } + @Test public void testQuoteUnterminatedLine() throws Exception { assertFalse(policy.isEndOfRecord("a string\"one")); } + @Test public void testEmptyLine() throws Exception { assertTrue(policy.isEndOfRecord("")); } + @Test public void testNullLine() throws Exception { assertTrue(policy.isEndOfRecord(null)); } + @Test public void testPostProcess() throws Exception { String line = "foo\nbar"; assertEquals(line, policy.postProcess(line)); } + @Test public void testPreProcessWithQuote() throws Exception { String line = "foo\"bar"; assertEquals(line + "\n", policy.preProcess(line)); } + @Test public void testPreProcessWithNotDefaultQuote() throws Exception { String line = "foo'bar"; policy.setQuoteCharacter("'"); assertEquals(line + "\n", policy.preProcess(line)); } + @Test public void testPreProcessWithoutQuote() throws Exception { String line = "foo"; assertEquals(line, policy.preProcess(line)); } + @Test public void testContinuationMarkerNotEnd() throws Exception { String line = "foo\\"; assertFalse(policy.isEndOfRecord(line)); } + @Test public void testNotDefaultContinuationMarkerNotEnd() throws Exception { String line = "foo bar"; policy.setContinuation("bar"); assertFalse(policy.isEndOfRecord(line)); } + @Test public void testContinuationMarkerRemoved() throws Exception { String line = "foo\\"; assertEquals("foo", policy.preProcess(line)); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/JsonRecordSeparatorPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/JsonRecordSeparatorPolicyTests.java index 4c99b963b1..b9e2903aee 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/JsonRecordSeparatorPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/JsonRecordSeparatorPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009 the original author or authors. + * Copyright 2009-2022 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,9 +15,9 @@ */ package org.springframework.batch.item.file.separator; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class JsonRecordSeparatorPolicyTests { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/SimpleRecordSeparatorPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/SimpleRecordSeparatorPolicyTests.java index be8b58dd98..2487fa4056 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/SimpleRecordSeparatorPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/SimpleRecordSeparatorPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,29 +16,37 @@ package org.springframework.batch.item.file.separator; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public class SimpleRecordSeparatorPolicyTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SimpleRecordSeparatorPolicyTests { SimpleRecordSeparatorPolicy policy = new SimpleRecordSeparatorPolicy(); + @Test public void testNormalLine() throws Exception { assertTrue(policy.isEndOfRecord("a string")); } + @Test public void testEmptyLine() throws Exception { assertTrue(policy.isEndOfRecord("")); } + @Test public void testNullLine() throws Exception { assertTrue(policy.isEndOfRecord(null)); } + @Test public void testPostProcess() throws Exception { String line = "foo\nbar"; assertEquals(line, policy.postProcess(line)); } + @Test public void testPreProcess() throws Exception { String line = "foo\nbar"; assertEquals(line, policy.preProcess(line)); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/SuffixRecordSeparatorPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/SuffixRecordSeparatorPolicyTests.java index c6de1354b0..bc14c55cf9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/SuffixRecordSeparatorPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/separator/SuffixRecordSeparatorPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,50 +16,63 @@ package org.springframework.batch.item.file.separator; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public class SuffixRecordSeparatorPolicyTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SuffixRecordSeparatorPolicyTests { private static final String LINE = "a string"; SuffixRecordSeparatorPolicy policy = new SuffixRecordSeparatorPolicy(); + @Test public void testNormalLine() throws Exception { assertFalse(policy.isEndOfRecord(LINE)); } + @Test public void testNormalLineWithDefaultSuffix() throws Exception { assertTrue(policy.isEndOfRecord(LINE + SuffixRecordSeparatorPolicy.DEFAULT_SUFFIX)); } + @Test public void testNormalLineWithNonDefaultSuffix() throws Exception { policy.setSuffix(":foo"); assertTrue(policy.isEndOfRecord(LINE + ":foo")); } + @Test public void testNormalLineWithDefaultSuffixAndWhitespace() throws Exception { assertTrue(policy.isEndOfRecord(LINE + SuffixRecordSeparatorPolicy.DEFAULT_SUFFIX + " ")); } + @Test public void testNormalLineWithDefaultSuffixWithIgnoreWhitespace() throws Exception { policy.setIgnoreWhitespace(false); assertFalse(policy.isEndOfRecord(LINE + SuffixRecordSeparatorPolicy.DEFAULT_SUFFIX + " ")); } + @Test public void testEmptyLine() throws Exception { assertFalse(policy.isEndOfRecord("")); } + @Test public void testNullLineIsEndOfRecord() throws Exception { assertTrue(policy.isEndOfRecord(null)); } + @Test public void testPostProcessSunnyDay() throws Exception { String line = LINE; String record = line + SuffixRecordSeparatorPolicy.DEFAULT_SUFFIX; assertEquals(line, policy.postProcess(record)); } + @Test public void testPostProcessNullLine() throws Exception { String line = null; assertEquals(null, policy.postProcess(line)); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/BeanWrapperFieldExtractorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/BeanWrapperFieldExtractorTests.java index 100bc351d6..57a9f20e55 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/BeanWrapperFieldExtractorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/BeanWrapperFieldExtractorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,12 @@ package org.springframework.batch.item.file.transform; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.NotReadablePropertyException; /** @@ -69,10 +70,9 @@ public void testExtract_invalidProperty() throws Exception { } } - @Test(expected = IllegalArgumentException.class) - public void testNamesPropertyMustBeSet() throws Exception { - extractor.setNames(null); - extractor.afterPropertiesSet(); + @Test + public void testNamesPropertyMustBeSet() { + assertThrows(IllegalArgumentException.class, () -> extractor.setNames(null)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/CommonLineTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/CommonLineTokenizerTests.java index 0a04c98337..58bbdd2652 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/CommonLineTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/CommonLineTokenizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 the original author or authors. + * Copyright 2008-2022 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,7 +18,10 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Tests for {@link AbstractLineTokenizer}. @@ -26,12 +29,13 @@ * @author Robert Kasanicky * @author Dave Syer */ -public class CommonLineTokenizerTests extends TestCase { +public class CommonLineTokenizerTests { /** * Columns names are considered to be specified if they are not null or * empty. */ + @Test public void testHasNames() { AbstractLineTokenizer tokenizer = new AbstractLineTokenizer() { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactoryTests.java index b68cd4b3a7..434239bd5a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactoryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2010 the original author or authors. + * Copyright 2006-2022 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,13 +15,13 @@ */ package org.springframework.batch.item.file.transform; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.text.NumberFormat; import java.text.SimpleDateFormat; import java.util.Locale; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Dave Syer diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetTests.java index e99825a577..ab9f980073 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DefaultFieldSetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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.file.transform; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.math.BigDecimal; import java.text.NumberFormat; @@ -29,8 +29,8 @@ import java.util.Date; import java.util.Locale; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class DefaultFieldSetTests { @@ -40,7 +40,7 @@ public class DefaultFieldSetTests { String[] names; - @Before + @BeforeEach public void setUp() throws Exception { tokens = new String[] { "TestString", "true", "C", "10", "-472", "354224", "543", "124.3", "424.3", "1,3245", @@ -475,7 +475,7 @@ public void testStrictReadDateWithPattern() throws Exception { } catch (IllegalArgumentException e) { String message = e.getMessage(); - assertTrue("Message did not contain: " + message, message.indexOf("dd-MM-yyyy") > 0); + assertTrue(message.contains("dd-MM-yyyy"), "Message did not contain: " + message); } } @@ -489,7 +489,7 @@ public void testStrictReadDateWithPatternAndStrangeDate() throws Exception { } catch (IllegalArgumentException e) { String message = e.getMessage(); - assertTrue("Message did not contain: " + message, message.indexOf("yyyyMMdd") > 0); + assertTrue(message.contains("yyyyMMdd"), "Message did not contain: " + message); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineAggregatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineAggregatorTests.java index a86b26a296..d4a09efab2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineAggregatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineAggregatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,10 +15,10 @@ */ package org.springframework.batch.item.file.transform; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Dave Syer @@ -35,7 +35,7 @@ public Object[] extract(String[] item) { } }; - @Before + @BeforeEach public void setup() { aggregator = new DelimitedLineAggregator<>(); aggregator.setFieldExtractor(defaultFieldExtractor); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java index 053217d8c4..c454deb0ed 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/DelimitedLineTokenizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2022 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,12 @@ package org.springframework.batch.item.file.transform; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class DelimitedLineTokenizerTests { @@ -32,29 +33,29 @@ public class DelimitedLineTokenizerTests { public void testTokenizeRegularUse() { FieldSet tokens = tokenizer.tokenize("sfd,\"Well,I have no idea what to do in the afternoon\",sFj, asdf,,as\n"); assertEquals(6, tokens.getFieldCount()); - assertTrue(TOKEN_MATCHES, tokens.readString(0).equals("sfd")); - assertTrue(TOKEN_MATCHES, tokens.readString(1).equals("Well,I have no idea what to do in the afternoon")); - assertTrue(TOKEN_MATCHES, tokens.readString(2).equals("sFj")); - assertTrue(TOKEN_MATCHES, tokens.readString(3).equals("asdf")); - assertTrue(TOKEN_MATCHES, tokens.readString(4).equals("")); - assertTrue(TOKEN_MATCHES, tokens.readString(5).equals("as")); + assertTrue(tokens.readString(0).equals("sfd"), TOKEN_MATCHES); + assertTrue(tokens.readString(1).equals("Well,I have no idea what to do in the afternoon"), TOKEN_MATCHES); + assertTrue(tokens.readString(2).equals("sFj"), TOKEN_MATCHES); + assertTrue(tokens.readString(3).equals("asdf"), TOKEN_MATCHES); + assertTrue(tokens.readString(4).equals(""), TOKEN_MATCHES); + assertTrue(tokens.readString(5).equals("as"), TOKEN_MATCHES); tokens = tokenizer.tokenize("First string,"); assertEquals(2, tokens.getFieldCount()); - assertTrue(TOKEN_MATCHES, tokens.readString(0).equals("First string")); - assertTrue(TOKEN_MATCHES, tokens.readString(1).equals("")); + assertTrue(tokens.readString(0).equals("First string"), TOKEN_MATCHES); + assertTrue(tokens.readString(1).equals(""), TOKEN_MATCHES); } @Test public void testBlankString() { FieldSet tokens = tokenizer.tokenize(" "); - assertTrue(TOKEN_MATCHES, tokens.readString(0).equals("")); + assertTrue(tokens.readString(0).equals(""), TOKEN_MATCHES); } @Test public void testEmptyString() { FieldSet tokens = tokenizer.tokenize("\"\""); - assertTrue(TOKEN_MATCHES, tokens.readString(0).equals("")); + assertTrue(tokens.readString(0).equals(""), TOKEN_MATCHES); } @Test @@ -103,8 +104,8 @@ public void testTooFewNamesNotStrict() { FieldSet tokens = tokenizer.tokenize("a,b,c"); - assertTrue(TOKEN_MATCHES, tokens.readString(0).equals("a")); - assertTrue(TOKEN_MATCHES, tokens.readString(1).equals("b")); + assertTrue(tokens.readString(0).equals("a"), TOKEN_MATCHES); + assertTrue(tokens.readString(1).equals("b"), TOKEN_MATCHES); } @Test @@ -128,11 +129,11 @@ public void testTooManyNamesNotStrict() { FieldSet tokens = tokenizer.tokenize("a,b,c"); - assertTrue(TOKEN_MATCHES, tokens.readString(0).equals("a")); - assertTrue(TOKEN_MATCHES, tokens.readString(1).equals("b")); - assertTrue(TOKEN_MATCHES, tokens.readString(2).equals("c")); - assertTrue(TOKEN_MATCHES, tokens.readString(3).equals("")); - assertTrue(TOKEN_MATCHES, tokens.readString(4).equals("")); + assertTrue(tokens.readString(0).equals("a"), TOKEN_MATCHES); + assertTrue(tokens.readString(1).equals("b"), TOKEN_MATCHES); + assertTrue(tokens.readString(2).equals("c"), TOKEN_MATCHES); + assertTrue(tokens.readString(3).equals(""), TOKEN_MATCHES); + assertTrue(tokens.readString(4).equals(""), TOKEN_MATCHES); } @Test @@ -142,17 +143,15 @@ public void testDelimitedLineTokenizerChar() { assertEquals(3, line.getFieldCount()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testDelimitedLineTokenizerNullDelimiter() { - AbstractLineTokenizer tokenizer = new DelimitedLineTokenizer(null); - tokenizer.tokenize("a b c"); + assertThrows(IllegalArgumentException.class, () -> new DelimitedLineTokenizer(null)); } - @Test(expected = IllegalArgumentException.class) - public void testDelimitedLineTokenizerEmptyString() throws Exception { + @Test + public void testDelimitedLineTokenizerEmptyString() { DelimitedLineTokenizer tokenizer = new DelimitedLineTokenizer(""); - tokenizer.afterPropertiesSet(); - tokenizer.tokenize("a b c"); + assertThrows(IllegalArgumentException.class, tokenizer::afterPropertiesSet); } @Test @@ -371,22 +370,18 @@ public void testTokenizeWithIncludedFieldsAndNames() { assertEquals("c", line.readString("bar")); } - @Test(expected = IncorrectTokenCountException.class) + @Test public void testTokenizeWithIncludedFieldsAndTooFewNames() { tokenizer.setIncludedFields(new int[] { 1, 2 }); tokenizer.setNames(new String[] { "foo" }); - FieldSet line = tokenizer.tokenize("\"a\",\"b\",\"c\",\"d\""); - assertEquals(2, line.getFieldCount()); - assertEquals("c", line.readString("bar")); + assertThrows(IncorrectTokenCountException.class, () -> tokenizer.tokenize("\"a\",\"b\",\"c\",\"d\"")); } - @Test(expected = IncorrectTokenCountException.class) + @Test public void testTokenizeWithIncludedFieldsAndTooManyNames() { tokenizer.setIncludedFields(new int[] { 1, 2 }); tokenizer.setNames(new String[] { "foo", "bar", "spam" }); - FieldSet line = tokenizer.tokenize("\"a\",\"b\",\"c\",\"d\""); - assertEquals(2, line.getFieldCount()); - assertEquals("c", line.readString("bar")); + assertThrows(IncorrectTokenCountException.class, () -> tokenizer.tokenize("\"a\",\"b\",\"c\",\"d\"")); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FixedLengthTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FixedLengthTokenizerTests.java index 00f4650815..394b920efb 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FixedLengthTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FixedLengthTokenizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2014 the original author or authors. + * Copyright 2006-2022 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,10 +16,10 @@ package org.springframework.batch.item.file.transform; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class FixedLengthTokenizerTests { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FormatterLineAggregatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FormatterLineAggregatorTests.java index 28859fddb6..afaf512c02 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FormatterLineAggregatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/FormatterLineAggregatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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.file.transform; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * Unit tests for {@link FormatterLineAggregator} @@ -39,7 +39,7 @@ public Object[] extract(String[] item) { } }; - @Before + @BeforeEach public void setup() { aggregator = new FormatterLineAggregator<>(); aggregator.setFieldExtractor(defaultFieldExtractor); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PassThroughFieldExtractorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PassThroughFieldExtractorTests.java index 9c4389a82b..cec86a5ca5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PassThroughFieldExtractorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PassThroughFieldExtractorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,14 +15,14 @@ */ package org.springframework.batch.item.file.transform; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Dan Garrette diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PassThroughLineAggregatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PassThroughLineAggregatorTests.java index e46ea4e7fd..5d7d328e9c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PassThroughLineAggregatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PassThroughLineAggregatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 the original author or authors. + * Copyright 2008-2022 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.file.transform; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -import org.springframework.batch.item.file.transform.LineAggregator; -import org.springframework.batch.item.file.transform.PassThroughLineAggregator; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class PassThroughLineAggregatorTests extends TestCase { +public class PassThroughLineAggregatorTests { private LineAggregator mapper = new PassThroughLineAggregator<>(); + @Test public void testUnmapItemAsFieldSet() throws Exception { Object item = new Object(); assertEquals(item.toString(), mapper.aggregate(item)); } + @Test public void testUnmapItemAsString() throws Exception { assertEquals("foo", mapper.aggregate("foo")); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizerTests.java index 790dca73df..9778002146 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/PatternMatchingCompositeLineTokenizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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,14 +16,15 @@ package org.springframework.batch.item.file.transform; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.lang.Nullable; /** @@ -35,10 +36,9 @@ public class PatternMatchingCompositeLineTokenizerTests { private PatternMatchingCompositeLineTokenizer tokenizer = new PatternMatchingCompositeLineTokenizer(); - @Test(expected = IllegalArgumentException.class) - public void testNoTokenizers() throws Exception { - tokenizer.afterPropertiesSet(); - tokenizer.tokenize("a line"); + @Test + public void testNoTokenizers() { + assertThrows(IllegalArgumentException.class, tokenizer::afterPropertiesSet); } @Test @@ -74,11 +74,11 @@ public FieldSet tokenize(@Nullable String line) { assertEquals("bar", fields.readString(1)); } - @Test(expected = IllegalStateException.class) + @Test public void testNoMatch() throws Exception { tokenizer.setTokenizers(Collections.singletonMap("foo", (LineTokenizer) new DelimitedLineTokenizer())); tokenizer.afterPropertiesSet(); - tokenizer.tokenize("nomatch"); + assertThrows(IllegalStateException.class, () -> tokenizer.tokenize("nomatch")); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RangeArrayPropertyEditorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RangeArrayPropertyEditorTests.java index 3ed0734294..ac415369d7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RangeArrayPropertyEditorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RangeArrayPropertyEditorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 the original author or authors. + * Copyright 2008-2022 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,15 +15,20 @@ */ package org.springframework.batch.item.file.transform; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class RangeArrayPropertyEditorTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; + +public class RangeArrayPropertyEditorTests { private Range[] ranges; private RangeArrayPropertyEditor pe; - @Override + @BeforeEach public void setUp() { ranges = null; @@ -41,6 +46,7 @@ public Object getValue() { }; } + @Test public void testSetAsText() { pe.setAsText("15, 32, 1-10, 33"); @@ -56,6 +62,7 @@ public void testSetAsText() { assertFalse(ranges[3].hasMaxValue()); } + @Test public void testSetAsTextWithNoSpaces() { pe.setAsText("15,32"); @@ -67,12 +74,14 @@ public void testSetAsTextWithNoSpaces() { assertFalse(ranges[1].hasMaxValue()); } + @Test public void testGetAsText() { ranges = new Range[] { new Range(20), new Range(6, 15), new Range(2), new Range(26, 95) }; assertEquals("20, 6-15, 2, 26-95", pe.getAsText()); } + @Test public void testValidDisjointRanges() { pe.setForceDisjointRanges(true); @@ -87,6 +96,7 @@ public void testValidDisjointRanges() { } + @Test public void testInvalidOverlappingRanges() { pe.setForceDisjointRanges(true); @@ -101,6 +111,7 @@ public void testInvalidOverlappingRanges() { } } + @Test public void testValidOverlappingRanges() { // test joint ranges @@ -113,6 +124,7 @@ public void testValidOverlappingRanges() { } + @Test public void testInvalidInput() { try { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RecursiveCollectionItemTransformerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RecursiveCollectionItemTransformerTests.java index 3633f3edd5..ce0fa67649 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RecursiveCollectionItemTransformerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RecursiveCollectionItemTransformerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,20 +18,22 @@ import java.util.Arrays; import java.util.Collections; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author Dave Syer * */ -public class RecursiveCollectionItemTransformerTests extends TestCase { +public class RecursiveCollectionItemTransformerTests { private static final String LINE_SEPARATOR = System.getProperty("line.separator"); private RecursiveCollectionLineAggregator aggregator = new RecursiveCollectionLineAggregator<>(); + @Test public void testSetDelegateAndPassInString() throws Exception { aggregator.setDelegate(new LineAggregator() { @Override @@ -42,6 +44,7 @@ public String aggregate(String item) { assertEquals("bar", aggregator.aggregate(Collections.singleton("foo"))); } + @Test public void testTransformList() throws Exception { String result = aggregator.aggregate(Arrays.asList(StringUtils.commaDelimitedListToStringArray("foo,bar"))); String[] array = StringUtils.delimitedListToStringArray(result, LINE_SEPARATOR); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RegexLineTokenizerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RegexLineTokenizerTests.java index bec27cea0a..ac89f9ae01 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RegexLineTokenizerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/file/transform/RegexLineTokenizerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2012 the original author or authors. + * Copyright 2006-2022 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,9 +17,9 @@ import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class RegexLineTokenizerTests { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/function/FunctionItemProcessorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/function/FunctionItemProcessorTests.java index a6b13ffc54..4d440f13d2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/function/FunctionItemProcessorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/function/FunctionItemProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2022 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,13 +17,13 @@ import java.util.function.Function; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemProcessor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Michael Minella @@ -32,7 +32,7 @@ public class FunctionItemProcessorTests { private Function function; - @Before + @BeforeEach public void setUp() { this.function = o -> o.toString(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemReaderTests.java index daaf9cd073..d274b3f442 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,18 +16,19 @@ package org.springframework.batch.item.jms; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Date; import jakarta.jms.Message; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.jms.core.JmsOperations; import org.springframework.jms.core.JmsTemplate; @@ -98,18 +99,18 @@ public void testNextMessageSunnyDay() { assertEquals(message, itemReader.read()); } - @Test(expected = IllegalArgumentException.class) - public void testTemplateWithNoDefaultDestination() throws Exception { + @Test + public void testTemplateWithNoDefaultDestination() { JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setReceiveTimeout(100L); - itemReader.setJmsTemplate(jmsTemplate); + assertThrows(IllegalArgumentException.class, () -> itemReader.setJmsTemplate(jmsTemplate)); } - @Test(expected = IllegalArgumentException.class) - public void testTemplateWithNoTimeout() throws Exception { + @Test + public void testTemplateWithNoTimeout() { JmsTemplate jmsTemplate = new JmsTemplate(); jmsTemplate.setDefaultDestinationName("foo"); - itemReader.setJmsTemplate(jmsTemplate); + assertThrows(IllegalArgumentException.class, () -> itemReader.setJmsTemplate(jmsTemplate)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemWriterTests.java index 5138921af5..680d5bd8d3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,12 @@ package org.springframework.batch.item.jms; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.jms.core.JmsOperations; import org.springframework.jms.core.JmsTemplate; @@ -38,10 +39,10 @@ public void testNoItemTypeSunnyDay() throws Exception { itemWriter.write(Arrays.asList("foo", "bar")); } - @Test(expected = IllegalArgumentException.class) - public void testTemplateWithNoDefaultDestination() throws Exception { + @Test + public void testTemplateWithNoDefaultDestination() { JmsTemplate jmsTemplate = new JmsTemplate(); - itemWriter.setJmsTemplate(jmsTemplate); + assertThrows(IllegalArgumentException.class, () -> itemWriter.setJmsTemplate(jmsTemplate)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGeneratorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGeneratorTests.java index 3710e91a96..36eaf97699 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGeneratorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsMethodArgumentsKeyGeneratorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,13 +15,13 @@ */ package org.springframework.batch.item.jms; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import jakarta.jms.Message; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Dave Syer diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsMethodInvocationRecovererTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsMethodInvocationRecovererTests.java index 26fbfdeabc..7f61798473 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsMethodInvocationRecovererTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsMethodInvocationRecovererTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,7 +17,7 @@ import static org.mockito.Mockito.mock; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.jms.core.JmsOperations; /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifierTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifierTests.java index 139e0a06a9..a0346910db 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifierTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/JmsNewMethodArgumentsIdentifierTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,13 +15,13 @@ */ package org.springframework.batch.item.jms; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import jakarta.jms.Message; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Dave Syer diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/builder/JmsItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/builder/JmsItemReaderBuilderTests.java index cfa938bceb..5791f37709 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/builder/JmsItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/builder/JmsItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,15 +20,15 @@ import jakarta.jms.Message; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.jms.JmsItemReader; import org.springframework.jms.core.JmsOperations; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -40,7 +40,7 @@ public class JmsItemReaderBuilderTests { private JmsOperations defaultJmsTemplate; - @Before + @BeforeEach public void setupJmsTemplate() { this.defaultJmsTemplate = mock(JmsOperations.class); when(this.defaultJmsTemplate.receiveAndConvert()).thenReturn("foo"); @@ -97,8 +97,8 @@ public void testNullJmsTemplate() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException ise) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "jmsTemplate is required.", ise.getMessage()); + assertEquals("jmsTemplate is required.", ise.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/builder/JmsItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/builder/JmsItemWriterBuilderTests.java index cd1a7b7034..d16a0b0c8b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/builder/JmsItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/jms/builder/JmsItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-2022 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,14 +18,14 @@ import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.batch.item.jms.JmsItemWriter; import org.springframework.jms.core.JmsOperations; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -43,8 +43,8 @@ public void testNoItem() throws Exception { ArgumentCaptor argCaptor = ArgumentCaptor.forClass(String.class); itemWriter.write(Arrays.asList("foo", "bar")); verify(jmsTemplate, times(2)).convertAndSend(argCaptor.capture()); - assertEquals("Expected foo", "foo", argCaptor.getAllValues().get(0)); - assertEquals("Expected bar", "bar", argCaptor.getAllValues().get(1)); + assertEquals("foo", argCaptor.getAllValues().get(0), "Expected foo"); + assertEquals("bar", argCaptor.getAllValues().get(1), "Expected bar"); } @Test @@ -54,8 +54,8 @@ public void testNullJmsTemplate() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException ise) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "jmsTemplate is required.", ise.getMessage()); + assertEquals("jmsTemplate is required.", ise.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/GsonJsonObjectMarshallerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/GsonJsonObjectMarshallerTests.java index f29f97bfc9..a88e037928 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/GsonJsonObjectMarshallerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/GsonJsonObjectMarshallerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 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,8 +16,8 @@ package org.springframework.batch.item.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @author Mahmoud Ben Hassine @@ -33,7 +33,7 @@ public void testJsonMarshalling() { String foo = jsonObjectMarshaller.marshal(new Foo(1, "foo")); // then - Assert.assertEquals("{\"id\":1,\"name\":\"foo\"}", foo); + Assertions.assertEquals("{\"id\":1,\"name\":\"foo\"}", foo); } public static class Foo { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JacksonJsonObjectMarshallerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JacksonJsonObjectMarshallerTests.java index 00f85aa8b6..c8ace42211 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JacksonJsonObjectMarshallerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JacksonJsonObjectMarshallerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 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,8 +16,8 @@ package org.springframework.batch.item.json; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; /** * @author Mahmoud Ben Hassine @@ -33,7 +33,7 @@ public void testJsonMarshalling() { String foo = jsonObjectMarshaller.marshal(new Foo(1, "foo")); // then - Assert.assertEquals("{\"id\":1,\"name\":\"foo\"}", foo); + Assertions.assertEquals("{\"id\":1,\"name\":\"foo\"}", foo); } public static class Foo { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonFileItemWriterFunctionalTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonFileItemWriterFunctionalTests.java index 06056c25db..0136112206 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonFileItemWriterFunctionalTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonFileItemWriterFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 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. @@ -26,7 +26,7 @@ import java.util.Arrays; import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.batch.item.ExecutionContext; @@ -39,8 +39,8 @@ import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Mahmoud Ben Hassine diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonFileItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonFileItemWriterTests.java index 803279e4fb..cc8d42cec7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonFileItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonFileItemWriterTests.java @@ -20,21 +20,23 @@ import java.nio.file.Files; import java.util.Arrays; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.ExecutionContext; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.WritableResource; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * @author Mahmoud Ben Hassine */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class JsonFileItemWriterTests { private WritableResource resource; @@ -42,20 +44,20 @@ public class JsonFileItemWriterTests { @Mock private JsonObjectMarshaller jsonObjectMarshaller; - @Before + @BeforeEach public void setUp() throws Exception { File file = Files.createTempFile("test", "json").toFile(); this.resource = new FileSystemResource(file); } - @Test(expected = IllegalArgumentException.class) + @Test public void resourceMustNotBeNull() { - new JsonFileItemWriter<>(null, this.jsonObjectMarshaller); + assertThrows(IllegalArgumentException.class, () -> new JsonFileItemWriter<>(null, this.jsonObjectMarshaller)); } - @Test(expected = IllegalArgumentException.class) + @Test public void jsonObjectMarshallerMustNotBeNull() { - new JsonFileItemWriter<>(this.resource, null); + assertThrows(IllegalArgumentException.class, () -> new JsonFileItemWriter<>(this.resource, null)); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonItemReaderFunctionalTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonItemReaderFunctionalTests.java index 857b787a5e..217e67d071 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonItemReaderFunctionalTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonItemReaderFunctionalTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 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,8 +18,8 @@ import java.math.BigDecimal; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; @@ -51,35 +51,35 @@ public void testJsonReading() throws Exception { itemReader.open(new ExecutionContext()); Trade trade = itemReader.read(); - Assert.assertNotNull(trade); - Assert.assertEquals("123", trade.getIsin()); - Assert.assertEquals("foo", trade.getCustomer()); - Assert.assertEquals(new BigDecimal("1.2"), trade.getPrice()); - Assert.assertEquals(1, trade.getQuantity()); + Assertions.assertNotNull(trade); + Assertions.assertEquals("123", trade.getIsin()); + Assertions.assertEquals("foo", trade.getCustomer()); + Assertions.assertEquals(new BigDecimal("1.2"), trade.getPrice()); + Assertions.assertEquals(1, trade.getQuantity()); trade = itemReader.read(); - Assert.assertNotNull(trade); - Assert.assertEquals("456", trade.getIsin()); - Assert.assertEquals("bar", trade.getCustomer()); - Assert.assertEquals(new BigDecimal("1.4"), trade.getPrice()); - Assert.assertEquals(2, trade.getQuantity()); + Assertions.assertNotNull(trade); + Assertions.assertEquals("456", trade.getIsin()); + Assertions.assertEquals("bar", trade.getCustomer()); + Assertions.assertEquals(new BigDecimal("1.4"), trade.getPrice()); + Assertions.assertEquals(2, trade.getQuantity()); trade = itemReader.read(); - Assert.assertNotNull(trade); - Assert.assertEquals("789", trade.getIsin()); - Assert.assertEquals("foobar", trade.getCustomer()); - Assert.assertEquals(new BigDecimal("1.6"), trade.getPrice()); - Assert.assertEquals(3, trade.getQuantity()); + Assertions.assertNotNull(trade); + Assertions.assertEquals("789", trade.getIsin()); + Assertions.assertEquals("foobar", trade.getCustomer()); + Assertions.assertEquals(new BigDecimal("1.6"), trade.getPrice()); + Assertions.assertEquals(3, trade.getQuantity()); trade = itemReader.read(); - Assert.assertNotNull(trade); - Assert.assertEquals("100", trade.getIsin()); - Assert.assertEquals("barfoo", trade.getCustomer()); - Assert.assertEquals(new BigDecimal("1.8"), trade.getPrice()); - Assert.assertEquals(4, trade.getQuantity()); + Assertions.assertNotNull(trade); + Assertions.assertEquals("100", trade.getIsin()); + Assertions.assertEquals("barfoo", trade.getCustomer()); + Assertions.assertEquals(new BigDecimal("1.8"), trade.getPrice()); + Assertions.assertEquals(4, trade.getQuantity()); trade = itemReader.read(); - Assert.assertNull(trade); + Assertions.assertNull(trade); } @Test @@ -90,7 +90,7 @@ public void testEmptyResource() throws Exception { itemReader.open(new ExecutionContext()); Trade trade = itemReader.read(); - Assert.assertNull(trade); + Assertions.assertNull(trade); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonItemReaderTests.java index fae5dfaf12..f747e420a8 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/JsonItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 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,12 +18,12 @@ import java.io.InputStream; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; @@ -31,14 +31,14 @@ import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Mahmoud Ben Hassine */ -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class JsonItemReaderTests { @Mock @@ -71,7 +71,7 @@ public void testNonExistentResource() { this.itemReader = new JsonItemReader<>(new NonExistentResource(), this.jsonObjectReader); // when - final Exception expectedException = Assert.assertThrows(ItemStreamException.class, + final Exception expectedException = Assertions.assertThrows(ItemStreamException.class, () -> this.itemReader.open(new ExecutionContext())); // then @@ -85,7 +85,7 @@ public void testNonReadableResource() { this.itemReader = new JsonItemReader<>(new NonReadableResource(), this.jsonObjectReader); // when - final Exception expectedException = Assert.assertThrows(ItemStreamException.class, + final Exception expectedException = Assertions.assertThrows(ItemStreamException.class, () -> this.itemReader.open(new ExecutionContext())); // then diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonFileItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonFileItemWriterBuilderTests.java index b258452cb4..fddd9061f7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonFileItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonFileItemWriterBuilderTests.java @@ -20,8 +20,8 @@ import java.nio.charset.Charset; import java.nio.file.Files; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.batch.item.file.FlatFileFooterCallback; @@ -32,8 +32,9 @@ import org.springframework.core.io.WritableResource; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Mahmoud Ben Hassine @@ -45,27 +46,30 @@ public class JsonFileItemWriterBuilderTests { private JsonObjectMarshaller jsonObjectMarshaller; - @Before + @BeforeEach public void setUp() throws Exception { File file = Files.createTempFile("test", "json").toFile(); this.resource = new FileSystemResource(file); this.jsonObjectMarshaller = object -> object; } - @Test(expected = IllegalArgumentException.class) + @Test public void testMissingResource() { - new JsonFileItemWriterBuilder().jsonObjectMarshaller(this.jsonObjectMarshaller).build(); + var builder = new JsonFileItemWriterBuilder().jsonObjectMarshaller(this.jsonObjectMarshaller); + assertThrows(IllegalArgumentException.class, builder::build); } - @Test(expected = IllegalArgumentException.class) + @Test public void testMissingJsonObjectMarshaller() { - new JsonFileItemWriterBuilder().resource(this.resource).build(); + var builder = new JsonFileItemWriterBuilder().resource(this.resource); + assertThrows(IllegalArgumentException.class, builder::build); } - @Test(expected = IllegalArgumentException.class) + @Test public void testMandatoryNameWhenSaveStateIsSet() { - new JsonFileItemWriterBuilder().resource(this.resource).jsonObjectMarshaller(this.jsonObjectMarshaller) - .build(); + var builder = new JsonFileItemWriterBuilder().resource(this.resource) + .jsonObjectMarshaller(this.jsonObjectMarshaller); + assertThrows(IllegalArgumentException.class, builder::build); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonItemReaderBuilderTests.java index 12c047a06b..a5166fb84e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/json/builder/JsonItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 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,28 +16,25 @@ package org.springframework.batch.item.json.builder; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.json.JsonItemReader; import org.springframework.batch.item.json.JsonObjectReader; import org.springframework.core.io.Resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.springframework.test.util.ReflectionTestUtils.getField; /** * @author Mahmoud Ben Hassine */ +@ExtendWith(MockitoExtension.class) public class JsonItemReaderBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private Resource resource; @@ -69,14 +66,14 @@ public void testConfiguration() { .resource(this.resource).saveState(true).strict(true).name("jsonItemReader").maxItemCount(100) .currentItemCount(50).build(); - Assert.assertEquals(this.jsonObjectReader, getField(itemReader, "jsonObjectReader")); - Assert.assertEquals(this.resource, getField(itemReader, "resource")); - Assert.assertEquals(100, getField(itemReader, "maxItemCount")); - Assert.assertEquals(50, getField(itemReader, "currentItemCount")); - Assert.assertTrue((Boolean) getField(itemReader, "saveState")); - Assert.assertTrue((Boolean) getField(itemReader, "strict")); + Assertions.assertEquals(this.jsonObjectReader, getField(itemReader, "jsonObjectReader")); + Assertions.assertEquals(this.resource, getField(itemReader, "resource")); + Assertions.assertEquals(100, getField(itemReader, "maxItemCount")); + Assertions.assertEquals(50, getField(itemReader, "currentItemCount")); + Assertions.assertTrue((Boolean) getField(itemReader, "saveState")); + Assertions.assertTrue((Boolean) getField(itemReader, "strict")); Object executionContext = getField(itemReader, "executionContextUserSupport"); - Assert.assertEquals("jsonItemReader", getField(executionContext, "name")); + Assertions.assertEquals("jsonItemReader", getField(executionContext, "name")); } @Test @@ -84,13 +81,13 @@ public void shouldBuildJsonItemReaderWhenResourceIsNotProvided() { JsonItemReader itemReader = new JsonItemReaderBuilder().jsonObjectReader(this.jsonObjectReader) .saveState(true).strict(true).name("jsonItemReader").maxItemCount(100).currentItemCount(50).build(); - Assert.assertEquals(this.jsonObjectReader, getField(itemReader, "jsonObjectReader")); - Assert.assertEquals(100, getField(itemReader, "maxItemCount")); - Assert.assertEquals(50, getField(itemReader, "currentItemCount")); - Assert.assertTrue((Boolean) getField(itemReader, "saveState")); - Assert.assertTrue((Boolean) getField(itemReader, "strict")); + Assertions.assertEquals(this.jsonObjectReader, getField(itemReader, "jsonObjectReader")); + Assertions.assertEquals(100, getField(itemReader, "maxItemCount")); + Assertions.assertEquals(50, getField(itemReader, "currentItemCount")); + Assertions.assertTrue((Boolean) getField(itemReader, "saveState")); + Assertions.assertTrue((Boolean) getField(itemReader, "strict")); Object executionContext = getField(itemReader, "executionContextUserSupport"); - Assert.assertEquals("jsonItemReader", getField(executionContext, "name")); + Assertions.assertEquals("jsonItemReader", getField(executionContext, "name")); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemReaderTests.java index d847fb4ba3..ef2a528805 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 the original author or authors. + * Copyright 2019-2022 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. @@ -29,35 +29,40 @@ import org.apache.kafka.clients.consumer.OffsetAndMetadata; import org.apache.kafka.common.TopicPartition; import org.apache.kafka.common.serialization.StringDeserializer; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.batch.item.ExecutionContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.kafka.core.DefaultKafkaProducerFactory; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.core.ProducerFactory; import org.springframework.kafka.support.SendResult; -import org.springframework.kafka.test.rule.EmbeddedKafkaRule; +import org.springframework.kafka.test.EmbeddedKafkaBroker; +import org.springframework.kafka.test.context.EmbeddedKafka; import org.springframework.kafka.test.utils.KafkaTestUtils; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.util.concurrent.ListenableFuture; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Mathieu Ouellet * @author Mahmoud Ben Hassine */ +@EmbeddedKafka +@ExtendWith(SpringExtension.class) public class KafkaItemReaderTests { - @ClassRule - public static EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule(1); + @Autowired + private EmbeddedKafkaBroker embeddedKafka; private KafkaItemReader reader; @@ -65,23 +70,22 @@ public class KafkaItemReaderTests { private Properties consumerProperties; - @BeforeClass - public static void setUpTopics() { - embeddedKafka.getEmbeddedKafka().addTopics(new NewTopic("topic1", 1, (short) 1), - new NewTopic("topic2", 2, (short) 1), new NewTopic("topic3", 1, (short) 1), - new NewTopic("topic4", 2, (short) 1), new NewTopic("topic5", 1, (short) 1), - new NewTopic("topic6", 1, (short) 1)); + @BeforeAll + public static void setUpTopics(@Autowired EmbeddedKafkaBroker embeddedKafka) { + embeddedKafka.addTopics(new NewTopic("topic1", 1, (short) 1), new NewTopic("topic2", 2, (short) 1), + new NewTopic("topic3", 1, (short) 1), new NewTopic("topic4", 2, (short) 1), + new NewTopic("topic5", 1, (short) 1), new NewTopic("topic6", 1, (short) 1)); } - @Before + @BeforeEach public void setUp() { - Map producerProperties = KafkaTestUtils.producerProps(embeddedKafka.getEmbeddedKafka()); + Map producerProperties = KafkaTestUtils.producerProps(embeddedKafka); ProducerFactory producerFactory = new DefaultKafkaProducerFactory<>(producerProperties); this.template = new KafkaTemplate<>(producerFactory); this.consumerProperties = new Properties(); this.consumerProperties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, - embeddedKafka.getEmbeddedKafka().getBrokersAsString()); + embeddedKafka.getBrokersAsString()); this.consumerProperties.setProperty(ConsumerConfig.GROUP_ID_CONFIG, "1"); this.consumerProperties.setProperty(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class.getName()); @@ -108,7 +112,7 @@ public void testValidation() { } Properties consumerProperties = new Properties(); - consumerProperties.put("bootstrap.servers", embeddedKafka.getEmbeddedKafka()); + consumerProperties.put("bootstrap.servers", embeddedKafka); try { new KafkaItemReader<>(consumerProperties, "topic", 0); fail("Expected exception was not thrown"); @@ -279,8 +283,8 @@ public void testReadFromSinglePartitionFromTheOffsetStoredInKafka() throws Excep this.reader.close(); // The offset stored in Kafka should be equal to 2 at this point - OffsetAndMetadata currentOffset = KafkaTestUtils - .getCurrentOffset(embeddedKafka.getEmbeddedKafka().getBrokersAsString(), "1", "topic6", 0); + OffsetAndMetadata currentOffset = KafkaTestUtils.getCurrentOffset(embeddedKafka.getBrokersAsString(), "1", + "topic6", 0); assertEquals(2, currentOffset.offset()); // second run (with same consumer group ID): new messages arrived since the last diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java index 374b4f2e07..80f2d9e51e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/KafkaItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 the original author or authors. + * Copyright 2019-2022 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,29 +19,27 @@ import java.util.List; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.convert.converter.Converter; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.kafka.support.SendResult; import org.springframework.util.concurrent.ListenableFuture; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.Mockito.times; +@ExtendWith(MockitoExtension.class) public class KafkaItemWriterTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private KafkaTemplate kafkaTemplate; @@ -52,10 +50,10 @@ public class KafkaItemWriterTests { private KafkaItemWriter writer; - @Before + @BeforeEach public void setUp() throws Exception { when(this.kafkaTemplate.getDefaultTopic()).thenReturn("defaultTopic"); - when(this.kafkaTemplate.sendDefault(any(), any())).thenReturn(this.future); + lenient().when(this.kafkaTemplate.sendDefault(any(), any())).thenReturn(this.future); this.itemKeyMapper = new KafkaItemKeyMapper(); this.writer = new KafkaItemWriter<>(); this.writer.setKafkaTemplate(this.kafkaTemplate); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemReaderBuilderTests.java index 02cf4a925b..0a50c3a3d3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 the original author or authors. + * Copyright 2019-2022 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. @@ -26,18 +26,18 @@ import org.apache.kafka.clients.consumer.ConsumerConfig; import org.apache.kafka.common.TopicPartition; import org.apache.kafka.common.serialization.StringDeserializer; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.kafka.KafkaItemReader; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Mathieu Ouellet @@ -47,7 +47,7 @@ public class KafkaItemReaderBuilderTests { private Properties consumerProperties; - @Before + @BeforeEach public void setUp() throws Exception { this.consumerProperties = new Properties(); this.consumerProperties.setProperty(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092"); @@ -65,7 +65,7 @@ public void testNullConsumerProperties() { .consumerProperties(null); // when - final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, builder::build); + final Exception expectedException = Assertions.assertThrows(IllegalArgumentException.class, builder::build); // then assertThat(expectedException).hasMessage("Consumer properties must not be null"); @@ -126,7 +126,7 @@ public void testNullTopicName() { .consumerProperties(this.consumerProperties).topic(null); // when - final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, builder::build); + final Exception expectedException = Assertions.assertThrows(IllegalArgumentException.class, builder::build); // then assertThat(expectedException).hasMessage("Topic name must not be null or empty"); @@ -139,7 +139,7 @@ public void testEmptyTopicName() { .consumerProperties(this.consumerProperties).topic(""); // when - final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, builder::build); + final Exception expectedException = Assertions.assertThrows(IllegalArgumentException.class, builder::build); // then assertThat(expectedException).hasMessage("Topic name must not be null or empty"); @@ -152,7 +152,7 @@ public void testNullPollTimeout() { .consumerProperties(this.consumerProperties).topic("test").pollTimeout(null); // when - final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, builder::build); + final Exception expectedException = Assertions.assertThrows(IllegalArgumentException.class, builder::build); // then assertThat(expectedException).hasMessage("pollTimeout must not be null"); @@ -165,7 +165,7 @@ public void testNegativePollTimeout() { .consumerProperties(this.consumerProperties).topic("test").pollTimeout(Duration.ofSeconds(-1)); // when - final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, builder::build); + final Exception expectedException = Assertions.assertThrows(IllegalArgumentException.class, builder::build); // then assertThat(expectedException).hasMessage("pollTimeout must not be negative"); @@ -178,7 +178,7 @@ public void testZeroPollTimeout() { .consumerProperties(this.consumerProperties).topic("test").pollTimeout(Duration.ZERO); // when - final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, builder::build); + final Exception expectedException = Assertions.assertThrows(IllegalArgumentException.class, builder::build); // then assertThat(expectedException).hasMessage("pollTimeout must not be zero"); @@ -191,7 +191,7 @@ public void testEmptyPartitions() { .consumerProperties(this.consumerProperties).topic("test").pollTimeout(Duration.ofSeconds(10)); // when - final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, builder::build); + final Exception expectedException = Assertions.assertThrows(IllegalArgumentException.class, builder::build); // then assertThat(expectedException).hasMessage("At least one partition must be provided"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemWriterBuilderTests.java index d85de7eb68..071f21cb0c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/kafka/builder/KafkaItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2021 the original author or authors. + * Copyright 2019-2022 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,37 +16,34 @@ package org.springframework.batch.item.kafka.builder; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.kafka.KafkaItemWriter; import org.springframework.core.convert.converter.Converter; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.test.util.ReflectionTestUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Mathieu Ouellet * @author Mahmoud Ben Hassine */ +@ExtendWith(MockitoExtension.class) public class KafkaItemWriterBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private KafkaTemplate kafkaTemplate; private KafkaItemKeyMapper itemKeyMapper; - @Before + @BeforeEach public void setUp() { this.itemKeyMapper = new KafkaItemKeyMapper(); } @@ -58,7 +55,7 @@ public void testNullKafkaTemplate() { .itemKeyMapper(this.itemKeyMapper); // when - final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, builder::build); + final Exception expectedException = Assertions.assertThrows(IllegalArgumentException.class, builder::build); // then assertThat(expectedException).hasMessage("kafkaTemplate is required."); @@ -71,7 +68,7 @@ public void testNullItemKeyMapper() { .kafkaTemplate(this.kafkaTemplate); // when - final Exception expectedException = Assert.assertThrows(IllegalArgumentException.class, builder::build); + final Exception expectedException = Assertions.assertThrows(IllegalArgumentException.class, builder::build); // then assertThat(expectedException).hasMessage("itemKeyMapper is required."); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/DefaultMailErrorHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/DefaultMailErrorHandlerTests.java index d00d99599d..d117b832ef 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/DefaultMailErrorHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/DefaultMailErrorHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,11 +15,11 @@ */ package org.springframework.batch.item.mail; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; import jakarta.mail.MessagingException; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.mail.MailException; import org.springframework.mail.MailMessage; import org.springframework.mail.MailSendException; @@ -48,16 +48,16 @@ public void testSetMaxMessageLength() { } catch (MailException e) { String msg = e.getMessage(); - assertTrue("Wrong message: " + msg, msg.matches(".*SimpleMailMessage: f;.*")); + assertTrue(msg.matches(".*SimpleMailMessage: f;.*"), "Wrong message: " + msg); } } /** * Test method for {@link DefaultMailErrorHandler#handle(MailMessage, Exception)}. */ - @Test(expected = MailSendException.class) + @Test public void testHandle() { - handler.handle(new SimpleMailMessage(), new MessagingException()); + assertThrows(MailSendException.class, () -> handler.handle(new SimpleMailMessage(), new MessagingException())); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/SimpleMailMessageItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/SimpleMailMessageItemWriterTests.java index 92b30545ad..415189cc4d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/SimpleMailMessageItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/SimpleMailMessageItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,7 +15,8 @@ */ package org.springframework.batch.item.mail; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -23,12 +24,13 @@ import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; import jakarta.mail.MessagingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.mail.MailException; import org.springframework.mail.MailMessage; @@ -50,7 +52,7 @@ public class SimpleMailMessageItemWriterTests { private MailSender mailSender = mock(MailSender.class); - @Before + @BeforeEach public void setUp() { writer.setMailSender(mailSender); } @@ -73,7 +75,7 @@ public void testSend() throws Exception { } } - @Test(expected = MailSendException.class) + @Test public void testDefaultErrorHandler() throws Exception { SimpleMailMessage foo = new SimpleMailMessage(); @@ -91,7 +93,7 @@ public void testDefaultErrorHandler() throws Exception { when(mailSender).thenThrow(new MailSendException( Collections.singletonMap((Object) foo, (Exception) new MessagingException("FOO")))); - writer.write(Arrays.asList(items)); + assertThrows(MailSendException.class, () -> writer.write(List.of(items))); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/builder/SimpleMailMessageItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/builder/SimpleMailMessageItemWriterBuilderTests.java index 3830fb6d96..50a36b2565 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/builder/SimpleMailMessageItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/builder/SimpleMailMessageItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,12 +18,13 @@ import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicReference; import jakarta.mail.MessagingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.mail.MailErrorHandler; import org.springframework.batch.item.mail.SimpleMailMessageItemWriter; @@ -33,8 +34,9 @@ import org.springframework.mail.MailSender; import org.springframework.mail.SimpleMailMessage; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -53,7 +55,7 @@ public class SimpleMailMessageItemWriterBuilderTests { private SimpleMailMessage[] items; - @Before + @BeforeEach public void setup() { mailSender = mock(MailSender.class); this.foo = new SimpleMailMessage(); @@ -81,15 +83,15 @@ public void testMailSenderNotSet() throws Exception { } } - @Test(expected = MailSendException.class) - public void testErrorHandler() throws Exception { + @Test + public void testErrorHandler() { SimpleMailMessageItemWriter writer = new SimpleMailMessageItemWriterBuilder().mailSender(this.mailSender) .build(); this.mailSender.send(this.foo, this.bar); when(this.mailSender) .thenThrow(new MailSendException(Collections.singletonMap(this.foo, new MessagingException("FOO")))); - writer.write(Arrays.asList(this.items)); + assertThrows(MailSendException.class, () -> writer.write(List.of(this.items))); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/javamail/MimeMessageItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/javamail/MimeMessageItemWriterTests.java index 7221a70abc..f70358bf44 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/javamail/MimeMessageItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/mail/javamail/MimeMessageItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,13 +15,15 @@ */ package org.springframework.batch.item.mail.javamail; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.mockito.AdditionalMatchers.aryEq; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Properties; import java.util.concurrent.atomic.AtomicReference; @@ -29,8 +31,8 @@ import jakarta.mail.Session; import jakarta.mail.internet.MimeMessage; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.mail.MailErrorHandler; import org.springframework.mail.MailException; import org.springframework.mail.MailMessage; @@ -54,7 +56,7 @@ public class MimeMessageItemWriterTests { private Session session = Session.getDefaultInstance(new Properties()); - @Before + @BeforeEach public void setUp() { writer.setJavaMailSender(mailSender); } @@ -72,8 +74,8 @@ public void testSend() throws Exception { } - @Test(expected = MailSendException.class) - public void testDefaultErrorHandler() throws Exception { + @Test + public void testDefaultErrorHandler() { MimeMessage foo = new MimeMessage(session); MimeMessage bar = new MimeMessage(session); @@ -90,7 +92,7 @@ public void testDefaultErrorHandler() throws Exception { when(mailSender).thenThrow(new MailSendException( Collections.singletonMap((Object) foo, (Exception) new MessagingException("FOO")))); - writer.write(Arrays.asList(items)); + assertThrows(MailSendException.class, () -> writer.write(List.of(items))); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/AbstractSynchronizedItemStreamWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/AbstractSynchronizedItemStreamWriterTests.java index 42534d6119..80c56029aa 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/AbstractSynchronizedItemStreamWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/AbstractSynchronizedItemStreamWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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,12 +21,11 @@ import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamWriter; @@ -37,11 +36,9 @@ * @author Dimitrios Liapis * */ +@ExtendWith(MockitoExtension.class) public abstract class AbstractSynchronizedItemStreamWriterTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock protected ItemStreamWriter delegate; @@ -53,7 +50,7 @@ public abstract class AbstractSynchronizedItemStreamWriterTests { abstract protected SynchronizedItemStreamWriter createNewSynchronizedItemStreamWriter(); - @Before + @BeforeEach public void init() { synchronizedItemStreamWriter = createNewSynchronizedItemStreamWriter(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemProcessorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemProcessorTests.java index e6a5067b53..1acc858f40 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemProcessorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2022 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,12 +15,12 @@ */ package org.springframework.batch.item.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemProcessor; import org.springframework.classify.PatternMatchingClassifier; import org.springframework.classify.SubclassClassifier; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemWriterTests.java index 403e45087c..da4af1d9ef 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ClassifierCompositeItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,13 +21,13 @@ import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemWriter; import org.springframework.classify.PatternMatchingClassifier; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Dave Syer @@ -73,8 +73,8 @@ public void testSetNullClassifier() throws Exception { fail("A classifier is required."); } catch (IllegalArgumentException iae) { - assertEquals("Message returned from exception did not match expected result.", "A classifier is required.", - iae.getMessage()); + assertEquals("A classifier is required.", iae.getMessage(), + "Message returned from exception did not match expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemProcessorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemProcessorTests.java index 66e519fa66..00c7d03bbf 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemProcessorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 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,18 +15,18 @@ */ package org.springframework.batch.item.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.Arrays; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemProcessor; /** @@ -44,7 +44,7 @@ public class CompositeItemProcessorTests { private ItemProcessor processor2; @SuppressWarnings("unchecked") - @Before + @BeforeEach public void setUp() throws Exception { processor1 = mock(ItemProcessor.class); processor2 = mock(ItemProcessor.class); @@ -128,7 +128,7 @@ public void testFilteredItemInFirstProcessor() throws Exception { Object item = new Object(); when(processor1.process(item)).thenReturn(null); - Assert.assertEquals(null, composite.process(item)); + Assertions.assertEquals(null, composite.process(item)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemStreamTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemStreamTests.java index 582cac2d96..4fb1365be4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemStreamTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemStreamTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,23 +18,24 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStream; import org.springframework.batch.item.ItemStreamSupport; -import org.springframework.batch.item.support.CompositeItemStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Dave Syer * */ -public class CompositeItemStreamTests extends TestCase { +public class CompositeItemStreamTests { private CompositeItemStream manager = new CompositeItemStream(); private List list = new ArrayList<>(); + @Test public void testRegisterAndOpen() { ItemStreamSupport stream = new ItemStreamSupport() { @Override @@ -48,6 +49,7 @@ public void open(ExecutionContext executionContext) { assertEquals(1, list.size()); } + @Test public void testRegisterTwice() { ItemStreamSupport stream = new ItemStreamSupport() { @Override @@ -62,6 +64,7 @@ public void open(ExecutionContext executionContext) { assertEquals(1, list.size()); } + @Test public void testMark() { manager.register(new ItemStreamSupport() { @Override @@ -74,6 +77,7 @@ public void update(ExecutionContext executionContext) { assertEquals(1, list.size()); } + @Test public void testClose() { manager.register(new ItemStreamSupport() { @Override @@ -86,6 +90,7 @@ public void close() { assertEquals(1, list.size()); } + @Test public void testCloseDoesNotUnregister() { manager.setStreams(new ItemStream[] { new ItemStreamSupport() { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemWriterTests.java index e7df95b272..a34e29699d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/CompositeItemWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 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,7 +20,7 @@ import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamWriter; import org.springframework.batch.item.ItemWriter; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ItemCountingItemStreamItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ItemCountingItemStreamItemReaderTests.java index 0324316468..035ecefcd2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ItemCountingItemStreamItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ItemCountingItemStreamItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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,16 +15,16 @@ */ package org.springframework.batch.item.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.Iterator; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.lang.Nullable; @@ -36,7 +36,7 @@ public class ItemCountingItemStreamItemReaderTests { private ItemCountingItemStreamItemReader reader = new ItemCountingItemStreamItemReader(); - @Before + @BeforeEach public void setUp() { reader.setName("foo"); } @@ -62,11 +62,10 @@ public void testClose() { assertTrue(reader.closeCalled); } - @Test(expected = IllegalArgumentException.class) + @Test public void testOpenWithoutName() { reader = new ItemCountingItemStreamItemReader(); - reader.open(new ExecutionContext()); - assertFalse(reader.openCalled); + assertThrows(IllegalArgumentException.class, () -> reader.open(new ExecutionContext())); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/IteratorItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/IteratorItemReaderTests.java index 908e74d9c7..b7755a5c7f 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/IteratorItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/IteratorItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,13 @@ import java.util.Arrays; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public class IteratorItemReaderTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +public class IteratorItemReaderTests { + + @Test public void testIterable() throws Exception { IteratorItemReader reader = new IteratorItemReader<>(Arrays.asList(new String[] { "a", "b", "c" })); assertEquals("a", reader.read()); @@ -30,6 +33,7 @@ public void testIterable() throws Exception { assertEquals(null, reader.read()); } + @Test public void testIterator() throws Exception { IteratorItemReader reader = new IteratorItemReader<>( Arrays.asList(new String[] { "a", "b", "c" }).iterator()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ListItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ListItemReaderTests.java index ee5e633570..1adde09794 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ListItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ListItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,14 +20,15 @@ import java.util.Arrays; import java.util.List; -import org.springframework.batch.item.support.ListItemReader; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; -public class ListItemReaderTests extends TestCase { +public class ListItemReaderTests { ListItemReader reader = new ListItemReader<>(Arrays.asList(new String[] { "a", "b", "c" })); + @Test public void testNext() throws Exception { assertEquals("a", reader.read()); assertEquals("b", reader.read()); @@ -35,6 +36,7 @@ public void testNext() throws Exception { assertEquals(null, reader.read()); } + @Test public void testChangeList() throws Exception { List list = new ArrayList<>(Arrays.asList(new String[] { "a", "b", "c" })); reader = new ListItemReader<>(list); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ScriptItemProcessorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ScriptItemProcessorTests.java index 2beaaadae7..db2d1a46da 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ScriptItemProcessorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/ScriptItemProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2022 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,8 +15,8 @@ */ package org.springframework.batch.item.support; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.scripting.bsh.BshScriptEvaluator; @@ -28,8 +28,9 @@ import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** *

@@ -43,7 +44,7 @@ public class ScriptItemProcessorTests { private static List availableLanguages = new ArrayList<>(); - @BeforeClass + @BeforeAll public static void populateAvailableEngines() { List scriptEngineFactories = new ScriptEngineManager().getEngineFactories(); @@ -60,7 +61,7 @@ public void testJavascriptScriptSourceSimple() throws Exception { scriptItemProcessor.setScriptSource("item.toUpperCase();", "javascript"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -72,7 +73,7 @@ public void testJavascriptScriptSourceFunction() throws Exception { "javascript"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -83,7 +84,7 @@ public void testJRubyScriptSourceSimple() throws Exception { scriptItemProcessor.setScriptSource("$item.upcase", "jruby"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -94,7 +95,7 @@ public void testJRubyScriptSourceMethod() throws Exception { scriptItemProcessor.setScriptSource("def process(item) $item.upcase end \n process($item)", "jruby"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -105,7 +106,7 @@ public void testBeanShellScriptSourceSimple() throws Exception { scriptItemProcessor.setScriptSource("item.toUpperCase();", "bsh"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -117,7 +118,7 @@ public void testBeanShellScriptSourceFunction() throws Exception { "bsh"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -128,7 +129,7 @@ public void testGroovyScriptSourceSimple() throws Exception { scriptItemProcessor.setScriptSource("item.toUpperCase();", "groovy"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -140,7 +141,7 @@ public void testGroovyScriptSourceMethod() throws Exception { "groovy"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -153,7 +154,7 @@ public void testJavascriptScriptSimple() throws Exception { scriptItemProcessor.setScript(resource); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -166,35 +167,34 @@ public void testItemBinding() throws Exception { scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", true, scriptItemProcessor.process("Hello World")); + assertEquals(true, scriptItemProcessor.process("Hello World"), "Incorrect transformed value"); } - @Test(expected = IllegalStateException.class) - public void testNoScriptSet() throws Exception { + @Test + public void testNoScriptSet() { ScriptItemProcessor scriptItemProcessor = new ScriptItemProcessor<>(); - scriptItemProcessor.afterPropertiesSet(); + assertThrows(IllegalStateException.class, scriptItemProcessor::afterPropertiesSet); } - @Test(expected = IllegalStateException.class) - public void testScriptSourceAndScriptResourceSet() throws Exception { + @Test + public void testScriptSourceAndScriptResourceSet() { ScriptItemProcessor scriptItemProcessor = new ScriptItemProcessor<>(); scriptItemProcessor.setScriptSource("blah", "blah"); scriptItemProcessor.setScript(new ClassPathResource("blah")); - scriptItemProcessor.afterPropertiesSet(); + assertThrows(IllegalStateException.class, scriptItemProcessor::afterPropertiesSet); } - @Test(expected = IllegalStateException.class) - public void testNoScriptSetWithoutInitBean() throws Exception { + @Test + public void testNoScriptSetWithoutInitBean() { ScriptItemProcessor scriptItemProcessor = new ScriptItemProcessor<>(); - scriptItemProcessor.process("blah"); + assertThrows(IllegalStateException.class, () -> scriptItemProcessor.process("blah")); } - @Test(expected = IllegalArgumentException.class) - public void testScriptSourceWithNoLanguage() throws Exception { + @Test + public void testScriptSourceWithNoLanguage() { ScriptItemProcessor scriptItemProcessor = new ScriptItemProcessor<>(); - scriptItemProcessor.setScriptSource("function process(item) { return item.toUpperCase(); } process(item);", - null); - scriptItemProcessor.afterPropertiesSet(); + assertThrows(IllegalArgumentException.class, () -> scriptItemProcessor + .setScriptSource("function process(item) { return item.toUpperCase(); } process(item);", null)); } @Test @@ -207,7 +207,7 @@ public void testItemBindingNameChange() throws Exception { "function process(param) { return param.toUpperCase(); } process(someOtherVarName);", "javascript"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -220,7 +220,7 @@ public void testBshScriptEvaluator() throws Exception { "bsh"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } @Test @@ -233,7 +233,7 @@ public void testGroovyScriptEvaluator() throws Exception { "groovy"); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "SS", scriptItemProcessor.process("ss")); + assertEquals("SS", scriptItemProcessor.process("ss"), "Incorrect transformed value"); } private boolean languageExists(String engineName) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SingleItemPeekableItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SingleItemPeekableItemReaderTests.java index 138a00445d..152514d1a0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SingleItemPeekableItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SingleItemPeekableItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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,12 +15,12 @@ */ package org.springframework.batch.item.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.util.Arrays; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.lang.Nullable; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamReaderTests.java index 788d242583..986d9aadbf 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015-2019 the original author or authors. + * Copyright 2015-2022 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,14 +15,14 @@ */ package org.springframework.batch.item.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamReader; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamWriterTests.java index 2f355ae76c..86bf945643 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/SynchronizedItemStreamWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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,7 +15,7 @@ */ package org.springframework.batch.item.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.InitializingBean; import static org.junit.jupiter.api.Assertions.assertEquals; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/TransactionAwareListItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/TransactionAwareListItemReaderTests.java index 4a11f7da33..abe95f77f9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/TransactionAwareListItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/TransactionAwareListItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,9 +20,9 @@ import java.util.Arrays; import java.util.List; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.batch.support.transaction.TransactionAwareProxyFactory; import org.springframework.transaction.PlatformTransactionManager; @@ -30,17 +30,22 @@ import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -public class TransactionAwareListItemReaderTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +public class TransactionAwareListItemReaderTests { private ListItemReader reader; - @Override + @BeforeEach protected void setUp() throws Exception { - super.setUp(); reader = new ListItemReader<>( TransactionAwareProxyFactory.createTransactionalList(Arrays.asList("a", "b", "c"))); } + @Test public void testNext() throws Exception { assertEquals("a", reader.read()); assertEquals("b", reader.read()); @@ -48,6 +53,7 @@ public void testNext() throws Exception { assertEquals(null, reader.read()); } + @Test public void testCommit() throws Exception { PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); final List taken = new ArrayList<>(); @@ -76,6 +82,7 @@ public Void doInTransaction(TransactionStatus status) { assertFalse(taken.contains("a")); } + @Test public void testTransactionalExhausted() throws Exception { PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); final List taken = new ArrayList<>(); @@ -94,6 +101,7 @@ public Void doInTransaction(TransactionStatus status) { assertEquals("a", taken.get(0)); } + @Test public void testRollback() throws Exception { PlatformTransactionManager transactionManager = new ResourcelessTransactionManager(); final List taken = new ArrayList<>(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ClassifierCompositeItemProcessorBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ClassifierCompositeItemProcessorBuilderTests.java index 3e766836af..69db9756f4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ClassifierCompositeItemProcessorBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ClassifierCompositeItemProcessorBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2022 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,14 +19,14 @@ import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.support.ClassifierCompositeItemProcessor; import org.springframework.classify.PatternMatchingClassifier; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Glenn Renfro @@ -57,8 +57,8 @@ public void testNullClassifier() { fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", - "A classifier is required.", iae.getMessage()); + assertEquals("A classifier is required.", iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ClassifierCompositeItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ClassifierCompositeItemWriterBuilderTests.java index c585bbc341..2cae1f391a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ClassifierCompositeItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ClassifierCompositeItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2022 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,14 +22,14 @@ import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.support.ClassifierCompositeItemWriter; import org.springframework.classify.PatternMatchingClassifier; -import static junit.framework.TestCase.fail; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Glenn Renfro @@ -62,8 +62,8 @@ public void testSetNullClassifier() throws Exception { fail("A classifier is required."); } catch (IllegalArgumentException iae) { - assertEquals("Message returned from exception did not match expected result.", "A classifier is required.", - iae.getMessage()); + assertEquals("A classifier is required.", iae.getMessage(), + "Message returned from exception did not match expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemProcessorBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemProcessorBuilderTests.java index 0bd654f121..5f4ddf6339 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemProcessorBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemProcessorBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,29 +19,26 @@ import java.util.ArrayList; import java.util.List; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.ItemProcessor; import org.springframework.batch.item.support.CompositeItemProcessor; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.when; /** * @author Glenn Renfro * @author Drummond Dawson */ +@ExtendWith(MockitoExtension.class) public class CompositeItemProcessorBuilderTests { - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private ItemProcessor processor1; @@ -50,7 +47,7 @@ public class CompositeItemProcessorBuilderTests { private List> processors; - @Before + @BeforeEach public void setup() { this.processors = new ArrayList<>(); this.processors.add(processor1); @@ -100,8 +97,8 @@ private void validateExceptionMessage(CompositeItemProcessorBuilder builde fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", message, - iae.getMessage()); + assertEquals(message, iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemWriterBuilderTests.java index 19f9e74035..7f53bd78b5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/CompositeItemWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2018 the original author or authors. + * Copyright 2017-2022 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,7 +20,7 @@ import java.util.Collections; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamWriter; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ScriptItemProcessorBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ScriptItemProcessorBuilderTests.java index be8fac2199..3b10145c48 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ScriptItemProcessorBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/ScriptItemProcessorBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2022 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,17 +22,17 @@ import javax.script.ScriptEngineFactory; import javax.script.ScriptEngineManager; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.support.ScriptItemProcessor; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.junit.Assume.assumeTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; +import static org.junit.jupiter.api.Assumptions.assumeTrue; /** * @author Glenn Renfro @@ -41,7 +41,7 @@ public class ScriptItemProcessorBuilderTests { private static List availableLanguages = new ArrayList<>(); - @BeforeClass + @BeforeAll public static void populateAvailableEngines() { List scriptEngineFactories = new ScriptEngineManager().getEngineFactories(); @@ -50,7 +50,7 @@ public static void populateAvailableEngines() { } } - @Before + @BeforeEach public void setup() { assumeTrue(availableLanguages.contains("javascript")); } @@ -61,7 +61,7 @@ public void testScriptSource() throws Exception { .scriptSource("item.toUpperCase();").language("javascript").build(); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "AA", scriptItemProcessor.process("aa")); + assertEquals("AA", scriptItemProcessor.process("aa"), "Incorrect transformed value"); } @Test @@ -70,7 +70,7 @@ public void testItemBinding() throws Exception { .scriptSource("foo.contains('World');").language("javascript").itemBindingVariableName("foo").build(); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", true, scriptItemProcessor.process("Hello World")); + assertEquals(true, scriptItemProcessor.process("Hello World"), "Incorrect transformed value"); } @Test @@ -80,7 +80,7 @@ public void testScriptResource() throws Exception { .scriptResource(resource).build(); scriptItemProcessor.afterPropertiesSet(); - assertEquals("Incorrect transformed value", "BB", scriptItemProcessor.process("bb")); + assertEquals("BB", scriptItemProcessor.process("bb"), "Incorrect transformed value"); } @Test @@ -102,8 +102,8 @@ private void validateExceptionMessage(ScriptItemProcessorBuilder fail("IllegalArgumentException should have been thrown"); } catch (IllegalArgumentException iae) { - assertEquals("IllegalArgumentException message did not match the expected result.", message, - iae.getMessage()); + assertEquals(message, iae.getMessage(), + "IllegalArgumentException message did not match the expected result."); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SingleItemPeekableItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SingleItemPeekableItemReaderBuilderTests.java index 30e753ed30..e806a545d9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SingleItemPeekableItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SingleItemPeekableItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 the original author or authors. + * Copyright 2017-2022 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,14 +18,14 @@ import java.util.Arrays; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.sample.Foo; import org.springframework.batch.item.support.ListItemReader; import org.springframework.batch.item.support.SingleItemPeekableItemReader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * @author Glenn Renfro diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamReaderBuilderTests.java index 8a9ad8a06e..6931cff584 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2019 the original author or authors. + * Copyright 2017-2022 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,7 +19,7 @@ import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamReader; @@ -29,9 +29,9 @@ import org.springframework.batch.item.support.SynchronizedItemStreamReader; import org.springframework.lang.Nullable; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Glenn Renfro diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamWriterBuilderTests.java index ee0a3925fc..868614ab41 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/support/builder/SynchronizedItemStreamWriterBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2020-2021 the original author or authors. + * Copyright 2020-2022 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,7 +15,7 @@ */ package org.springframework.batch.item.support.builder; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.support.AbstractSynchronizedItemStreamWriterTests; import org.springframework.batch.item.support.SynchronizedItemStreamWriter; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/ExecutionContextUserSupportTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/ExecutionContextUserSupportTests.java index f3daeed678..2939f1e84c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/ExecutionContextUserSupportTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/ExecutionContextUserSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008 the original author or authors. + * Copyright 2008-2022 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,22 @@ */ package org.springframework.batch.item.util; -import org.springframework.batch.item.util.ExecutionContextUserSupport; +import org.junit.jupiter.api.Test; -import junit.framework.TestCase; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for {@link ExecutionContextUserSupport}. */ -public class ExecutionContextUserSupportTests extends TestCase { +public class ExecutionContextUserSupportTests { ExecutionContextUserSupport tested = new ExecutionContextUserSupport(); /** * Regular usage scenario - prepends the name (supposed to be unique) to argument. */ + @Test public void testGetKey() { tested.setName("uniqueName"); assertEquals("uniqueName.key", tested.getKey("key")); @@ -37,6 +39,7 @@ public void testGetKey() { /** * Exception scenario - name must not be empty. */ + @Test public void testGetKeyWithNoNameSet() { tested.setName(""); try { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/FileUtilsTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/FileUtilsTests.java index 73f5101318..fa8dbd5e26 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/FileUtilsTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/util/FileUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 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,16 +20,16 @@ import java.io.FileWriter; import java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemStreamException; import org.springframework.util.Assert; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for {@link FileUtils} @@ -191,20 +191,20 @@ public boolean exists() { } catch (ItemStreamException ex) { String message = ex.getMessage(); - assertTrue("Wrong message: " + message, message.startsWith("Output file was not created")); + assertTrue(message.startsWith("Output file was not created"), "Wrong message: " + message); } finally { file.delete(); } } - @Before + @BeforeEach public void setUp() throws Exception { file.delete(); Assert.state(!file.exists(), "File delete failed"); } - @After + @AfterEach public void tearDown() throws Exception { file.delete(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/BeanValidatingItemProcessorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/BeanValidatingItemProcessorTests.java index 69b55590e9..f1447e435a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/BeanValidatingItemProcessorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/BeanValidatingItemProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2018-2021 the original author or authors. + * Copyright 2018-2022 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,8 +18,10 @@ import jakarta.validation.constraints.NotEmpty; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertThrows; /** * @author Mahmoud Ben Hassine @@ -37,10 +39,10 @@ public void testValidObjectValidation() throws Exception { Foo processed = validatingItemProcessor.process(foo); // then - Assert.assertNotNull(processed); + Assertions.assertNotNull(processed); } - @Test(expected = ValidationException.class) + @Test public void testInvalidObjectValidation() throws Exception { // given BeanValidatingItemProcessor validatingItemProcessor = new BeanValidatingItemProcessor<>(); @@ -48,7 +50,7 @@ public void testInvalidObjectValidation() throws Exception { Foo foo = new Foo(""); // when - validatingItemProcessor.process(foo); + assertThrows(ValidationException.class, () -> validatingItemProcessor.process(foo)); // then // expected exception diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java index f2dcbcb0a4..bc0892e640 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/SpringValidatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,12 @@ package org.springframework.batch.item.validator; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.validation.BindException; import org.springframework.validation.Errors; import org.springframework.validation.Validator; @@ -34,7 +35,7 @@ public class SpringValidatorTests { private Validator mockValidator; - @Before + @BeforeEach public void setUp() throws Exception { mockValidator = new MockSpringValidator(); validator.setValidator(mockValidator); @@ -43,18 +44,19 @@ public void setUp() throws Exception { /** * Validator property is not set */ - @Test(expected = IllegalArgumentException.class) - public void testNullValidator() throws Exception { + @Test + public void testNullValidator() { validator.setValidator(null); - validator.afterPropertiesSet(); + assertThrows(IllegalArgumentException.class, validator::afterPropertiesSet); } /** * Validator does not know how to validate object of the given class */ - @Test(expected = ValidationException.class) + @Test public void testValidateUnsupportedType() { - validator.validate(Integer.valueOf(1)); // only strings are supported + assertThrows(ValidationException.class, () -> validator.validate(1)); + // only strings are supported } /** @@ -68,22 +70,19 @@ public void testValidateSuccessfully() { /** * Typical failed validation - {@link ValidationException} is thrown */ - @Test(expected = ValidationException.class) + @Test public void testValidateFailure() { - validator.validate(MockSpringValidator.REJECT_VALUE); + assertThrows(ValidationException.class, () -> validator.validate(MockSpringValidator.REJECT_VALUE)); } /** * Typical failed validation - {@link ValidationException} is thrown */ - @Test(expected = BindException.class) - public void testValidateFailureWithErrors() throws Exception { - try { - validator.validate(MockSpringValidator.REJECT_VALUE); - } - catch (ValidationException e) { - throw (BindException) e.getCause(); - } + @Test + public void testValidateFailureWithErrors() { + ValidationException e = assertThrows(ValidationException.class, + () -> validator.validate(MockSpringValidator.REJECT_VALUE)); + assertTrue(e.getCause() instanceof BindException); } /** @@ -96,10 +95,10 @@ public void testValidateFailureWithFields() { fail("exception should have been thrown on invalid value"); } catch (ValidationException expected) { - assertTrue("message should contain the item#toString() value", - expected.getMessage().contains("TestBeanToString")); - assertTrue("message should contain names of the invalid fields", expected.getMessage().contains("foo")); - assertTrue("message should contain names of the invalid fields", expected.getMessage().contains("bar")); + assertTrue(expected.getMessage().contains("TestBeanToString"), + "message should contain the item#toString() value"); + assertTrue(expected.getMessage().contains("foo"), "message should contain names of the invalid fields"); + assertTrue(expected.getMessage().contains("bar"), "message should contain names of the invalid fields"); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/ValidatingItemProcessorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/ValidatingItemProcessorTests.java index c7b17c7885..1804b64742 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/ValidatingItemProcessorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/validator/ValidatingItemProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2013 the original author or authors. + * Copyright 2008-2022 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,12 +15,13 @@ */ package org.springframework.batch.item.validator; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Tests for {@link ValidatingItemProcessor}. @@ -42,12 +43,12 @@ public void testSuccessfulValidation() throws Exception { assertSame(ITEM, tested.process(ITEM)); } - @Test(expected = ValidationException.class) - public void testFailedValidation() throws Exception { + @Test + public void testFailedValidation() { ValidatingItemProcessor tested = new ValidatingItemProcessor<>(validator); - processFailedValidation(tested); + assertThrows(ValidationException.class, () -> processFailedValidation(tested)); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java index c82b9a602e..5f3b805ae9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventReaderItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2022 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,16 +15,16 @@ */ package org.springframework.batch.item.xml; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.math.BigDecimal; import java.util.ArrayList; import java.util.List; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.xml.domain.Trade; import org.springframework.core.io.ClassPathResource; @@ -35,7 +35,7 @@ public abstract class AbstractStaxEventReaderItemReaderTests { protected StaxEventItemReader reader = new StaxEventItemReader<>(); - @Before + @BeforeEach public void setUp() throws Exception { reader.setFragmentRootElementName("trade"); reader.setUnmarshaller(getUnmarshaller()); @@ -79,25 +79,25 @@ protected void checkResults(List results) { assertEquals(3, results.size()); Trade trade1 = results.get(0); - Assert.assertEquals("XYZ0001", trade1.getIsin()); - Assert.assertEquals(5, trade1.getQuantity()); - Assert.assertEquals(new BigDecimal("11.39"), trade1.getPrice()); - Assert.assertEquals("Customer1", trade1.getCustomer()); + Assertions.assertEquals("XYZ0001", trade1.getIsin()); + Assertions.assertEquals(5, trade1.getQuantity()); + Assertions.assertEquals(new BigDecimal("11.39"), trade1.getPrice()); + Assertions.assertEquals("Customer1", trade1.getCustomer()); Trade trade2 = results.get(1); - Assert.assertEquals("XYZ0002", trade2.getIsin()); - Assert.assertEquals(2, trade2.getQuantity()); - Assert.assertEquals(new BigDecimal("72.99"), trade2.getPrice()); - Assert.assertEquals("Customer2", trade2.getCustomer()); + Assertions.assertEquals("XYZ0002", trade2.getIsin()); + Assertions.assertEquals(2, trade2.getQuantity()); + Assertions.assertEquals(new BigDecimal("72.99"), trade2.getPrice()); + Assertions.assertEquals("Customer2", trade2.getCustomer()); Trade trade3 = results.get(2); - Assert.assertEquals("XYZ0003", trade3.getIsin()); - Assert.assertEquals(9, trade3.getQuantity()); - Assert.assertEquals(new BigDecimal("99.99"), trade3.getPrice()); - Assert.assertEquals("Customer3", trade3.getCustomer()); + Assertions.assertEquals("XYZ0003", trade3.getIsin()); + Assertions.assertEquals(9, trade3.getQuantity()); + Assertions.assertEquals(new BigDecimal("99.99"), trade3.getPrice()); + Assertions.assertEquals("Customer3", trade3.getCustomer()); } - @After + @AfterEach public void tearDown() throws Exception { reader.close(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventWriterItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventWriterItemWriterTests.java index e769b4464a..85edc3ea62 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventWriterItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/AbstractStaxEventWriterItemWriterTests.java @@ -22,9 +22,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.xmlunit.builder.Input; import org.xmlunit.diff.DefaultNodeMatcher; import org.xmlunit.diff.ElementSelectors; @@ -102,7 +102,7 @@ public Void doInTransaction(TransactionStatus status) { .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))); } - @Before + @BeforeEach public void setUp() throws Exception { File directory = new File("target/data"); @@ -118,7 +118,7 @@ public void setUp() throws Exception { } - @After + @AfterEach public void tearDown() throws Exception { outputFile.delete(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2MarshallingTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2MarshallingTests.java index f7ec7d81c3..33f39cb631 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2MarshallingTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2MarshallingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 the original author or authors. + * Copyright 2010-2022 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,7 +15,7 @@ */ package org.springframework.batch.item.xml; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.StringWriter; import java.math.BigDecimal; @@ -43,7 +43,7 @@ protected Marshaller getMarshaller() throws Exception { StringWriter string = new StringWriter(); marshaller.marshal(new Trade("FOO", 100, BigDecimal.valueOf(10.), "bar"), new StreamResult(string)); String content = string.toString(); - assertTrue("Wrong content: " + content, content.contains("bar")); + assertTrue(content.contains("bar"), "Wrong content: " + content); return marshaller; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceMarshallingTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceMarshallingTests.java index 7c3fd1da7a..a990ecb439 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceMarshallingTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceMarshallingTests.java @@ -24,9 +24,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.xmlunit.builder.Input; import org.xmlunit.matchers.CompareMatcher; @@ -46,7 +46,7 @@ import org.springframework.util.StopWatch; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class Jaxb2NamespaceMarshallingTests { @@ -104,7 +104,7 @@ public Void doInTransaction(TransactionStatus status) { CompareMatcher.isSimilarTo(Input.from(resource.getFile())).normalizeWhitespace()); } - @Before + @BeforeEach public void setUp() throws Exception { File directory = new File("target/data"); @@ -123,7 +123,7 @@ public void setUp() throws Exception { } - @After + @AfterEach public void tearDown() throws Exception { outputFile.delete(); } @@ -137,7 +137,7 @@ protected Marshaller getMarshaller() throws Exception { StringWriter string = new StringWriter(); marshaller.marshal(new QualifiedTrade("FOO", 100, BigDecimal.valueOf(10.), "bar"), new StreamResult(string)); String content = string.toString(); - assertTrue("Wrong content: " + content, content.contains("bar")); + assertTrue(content.contains("bar"), "Wrong content: " + content); return marshaller; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java index e73b65a745..e22996cd82 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/Jaxb2NamespaceUnmarshallingTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2011 the original author or authors. + * Copyright 2010-2022 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,7 +15,7 @@ */ package org.springframework.batch.item.xml; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.StringReader; import java.math.BigDecimal; @@ -24,12 +24,11 @@ import javax.xml.transform.stream.StreamSource; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; -import org.springframework.batch.item.xml.StaxEventItemReader; import org.springframework.batch.item.xml.domain.QualifiedTrade; import org.springframework.batch.item.xml.domain.Trade; import org.springframework.core.io.ClassPathResource; @@ -45,7 +44,7 @@ public class Jaxb2NamespaceUnmarshallingTests { private Resource resource = new ClassPathResource( ClassUtils.addResourcePathToPackagePath(getClass(), "domain/trades.xml")); - @Before + @BeforeEach public void setUp() throws Exception { reader.setResource(resource); reader.setFragmentRootElementName("{urn:org.springframework.batch.io.oxm.domain}trade"); @@ -58,10 +57,10 @@ public void setUp() throws Exception { public void testUnmarshal() throws Exception { QualifiedTrade trade = (QualifiedTrade) getUnmarshaller() .unmarshal(new StreamSource(new StringReader(TRADE_XML))); - Assert.assertEquals("XYZ0001", trade.getIsin()); - Assert.assertEquals(5, trade.getQuantity()); - Assert.assertEquals(new BigDecimal("11.39"), trade.getPrice()); - Assert.assertEquals("Customer1", trade.getCustomer()); + Assertions.assertEquals("XYZ0001", trade.getIsin()); + Assertions.assertEquals(5, trade.getQuantity()); + Assertions.assertEquals(new BigDecimal("11.39"), trade.getPrice()); + Assertions.assertEquals("Customer1", trade.getCustomer()); } @Test @@ -92,25 +91,25 @@ protected void checkResults(List results) { assertEquals(3, results.size()); QualifiedTrade trade1 = results.get(0); - Assert.assertEquals("XYZ0001", trade1.getIsin()); - Assert.assertEquals(5, trade1.getQuantity()); - Assert.assertEquals(new BigDecimal("11.39"), trade1.getPrice()); - Assert.assertEquals("Customer1", trade1.getCustomer()); + Assertions.assertEquals("XYZ0001", trade1.getIsin()); + Assertions.assertEquals(5, trade1.getQuantity()); + Assertions.assertEquals(new BigDecimal("11.39"), trade1.getPrice()); + Assertions.assertEquals("Customer1", trade1.getCustomer()); QualifiedTrade trade2 = results.get(1); - Assert.assertEquals("XYZ0002", trade2.getIsin()); - Assert.assertEquals(2, trade2.getQuantity()); - Assert.assertEquals(new BigDecimal("72.99"), trade2.getPrice()); - Assert.assertEquals("Customer2", trade2.getCustomer()); + Assertions.assertEquals("XYZ0002", trade2.getIsin()); + Assertions.assertEquals(2, trade2.getQuantity()); + Assertions.assertEquals(new BigDecimal("72.99"), trade2.getPrice()); + Assertions.assertEquals("Customer2", trade2.getCustomer()); QualifiedTrade trade3 = results.get(2); - Assert.assertEquals("XYZ0003", trade3.getIsin()); - Assert.assertEquals(9, trade3.getQuantity()); - Assert.assertEquals(new BigDecimal("99.99"), trade3.getPrice()); - Assert.assertEquals("Customer3", trade3.getCustomer()); + Assertions.assertEquals("XYZ0003", trade3.getIsin()); + Assertions.assertEquals(9, trade3.getQuantity()); + Assertions.assertEquals(new BigDecimal("99.99"), trade3.getPrice()); + Assertions.assertEquals("Customer3", trade3.getCustomer()); } - @After + @AfterEach public void tearDown() throws Exception { reader.close(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderCommonTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderCommonTests.java index 06f4d54ee6..6b7d55709e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderCommonTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderCommonTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2014 the original author or authors. + * Copyright 2008-2022 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. @@ -29,7 +29,7 @@ import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.XmlMappingException; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; public class StaxEventItemReaderCommonTests extends AbstractItemStreamItemReaderTests { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java index 435955fac1..560d04727b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2021 the original author or authors. + * Copyright 2008-2022 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,8 +17,8 @@ import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemCountAware; import org.springframework.batch.item.ItemStreamException; @@ -51,12 +51,13 @@ import java.util.Arrays; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * Tests for {@link StaxEventItemReader}. @@ -99,7 +100,7 @@ public class StaxEventItemReaderTests { private ExecutionContext executionContext; - @Before + @BeforeEach public void setUp() throws Exception { this.executionContext = new ExecutionContext(); source = createNewInputSource(); @@ -569,14 +570,14 @@ public void testRuntimeFileCreation() throws Exception { source.read(); } - @Test(expected = ItemStreamException.class) + @Test public void testStrictness() throws Exception { source.setResource(new NonExistentResource()); source.setStrict(true); source.afterPropertiesSet(); - source.open(executionContext); + assertThrows(ItemStreamException.class, () -> source.open(executionContext)); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java index 09dd1b09cf..6c59fdbb9d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/StaxEventItemWriterTests.java @@ -26,8 +26,8 @@ import javax.xml.transform.Result; import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.UnexpectedInputException; @@ -46,10 +46,11 @@ import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -109,7 +110,7 @@ public String toString() { private Jaxb2Marshaller jaxbMarshaller; - @Before + @BeforeEach public void setUp() throws Exception { File directory = new File("target/data"); directory.mkdirs(); @@ -130,15 +131,15 @@ public void testSetName() throws Exception { writer.write(items); writer.update(executionContext); writer.close(); - assertTrue("execution context keys should be prefixed with writer name", - executionContext.containsKey("test.position")); + assertTrue(executionContext.containsKey("test.position"), + "execution context keys should be prefixed with writer name"); } - @Test(expected = WriterNotOpenException.class) - public void testAssertWriterIsInitialized() throws Exception { + @Test + public void testAssertWriterIsInitialized() { StaxEventItemWriter writer = new StaxEventItemWriter<>(); - writer.write(Collections.singletonList("foo")); + assertThrows(WriterNotOpenException.class, () -> writer.write(List.of("foo"))); } @Test @@ -179,7 +180,7 @@ public void testWriteAndFlush() throws Exception { writer.write(items); writer.close(); String content = getOutputFileContent(); - assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); + assertTrue(content.contains(TEST_STRING), "Wrong content: " + content); } @Test @@ -189,7 +190,7 @@ public void testWriteAndForceFlush() throws Exception { writer.write(items); writer.close(); String content = getOutputFileContent(); - assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); + assertTrue(content.contains(TEST_STRING), "Wrong content: " + content); } /** @@ -407,8 +408,8 @@ public void write(XMLEventWriter writer) throws IOException { writer.open(executionContext); writer.write(items); String content = getOutputFileContent(); - assertTrue("Wrong content: " + content, content.contains(("
"))); - assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); + assertTrue(content.contains(("
")), "Wrong content: " + content); + assertTrue(content.contains(TEST_STRING), "Wrong content: " + content); } /** @@ -506,7 +507,7 @@ public void testDeleteIfEmptyRecordsWritten() throws Exception { writer.write(items); writer.close(); String content = getOutputFileContent(); - assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); + assertTrue(content.contains(TEST_STRING), "Wrong content: " + content); } /** @@ -518,7 +519,7 @@ public void testDeleteIfEmptyNoRecordsWritten() throws Exception { writer.setShouldDeleteIfEmpty(true); writer.open(executionContext); writer.close(); - assertFalse("file should be deleted" + resource, resource.getFile().exists()); + assertFalse(resource.getFile().exists(), "file should be deleted" + resource); } /** @@ -562,7 +563,7 @@ public void write(XMLEventWriter writer) throws IOException { }); writer.open(executionContext); writer.close(); - assertFalse("file should be deleted" + resource, resource.getFile().exists()); + assertFalse(resource.getFile().exists(), "file should be deleted" + resource); } /** @@ -582,7 +583,7 @@ public void testDeleteIfEmptyRecordsWrittenRestart() throws Exception { writer.open(executionContext); writer.close(); String content = getOutputFileContent(); - assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); + assertTrue(content.contains(TEST_STRING), "Wrong content: " + content); } /** @@ -602,7 +603,7 @@ public void testDeleteIfEmptyRestartAfterDelete() throws Exception { writer.update(executionContext); writer.close(); String content = getOutputFileContent(); - assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); + assertTrue(content.contains(TEST_STRING), "Wrong content: " + content); } /** @@ -647,13 +648,13 @@ public void write(XMLEventWriter writer) throws IOException { writer.open(executionContext); writer.update(executionContext); writer.close(); - assertFalse("file should be deleted" + resource, resource.getFile().exists()); + assertFalse(resource.getFile().exists(), "file should be deleted" + resource); writer.open(executionContext); writer.write(items); writer.update(executionContext); writer.close(); String content = getOutputFileContent(); - assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); + assertTrue(content.contains(TEST_STRING), "Wrong content: " + content); } /** @@ -667,10 +668,10 @@ public void testWriteRootTagWithNamespace() throws Exception { writer.write(items); writer.close(); String content = getOutputFileContent(); - assertTrue("Wrong content: " + content, - content.contains((""))); - assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); - assertTrue("Wrong content: " + content, content.contains((""))); + assertTrue(content.contains(("")), + "Wrong content: " + content); + assertTrue(content.contains(TEST_STRING), "Wrong content: " + content); + assertTrue(content.contains(("")), "Wrong content: " + content); } /** @@ -686,11 +687,11 @@ public void testWriteRootTagWithNamespaceAndPrefix() throws Exception { writer.write(items); writer.close(); String content = getOutputFileContent(); - assertTrue("Wrong content: " + content, - content.contains((""))); - assertTrue("Wrong content: " + content, content.contains(NS_TEST_STRING)); - assertTrue("Wrong content: " + content, content.contains((""))); - assertTrue("Wrong content: " + content, content.contains(("")), + "Wrong content: " + content); + assertTrue(content.contains(NS_TEST_STRING), "Wrong content: " + content); + assertTrue(content.contains(("")), "Wrong content: " + content); + assertTrue(content.contains((""))); - assertTrue("Wrong content: " + content, content.contains(FOO_TEST_STRING)); - assertTrue("Wrong content: " + content, content.contains((""))); - assertTrue("Wrong content: " + content, content.contains(("")), + "Wrong content: " + content); + assertTrue(content.contains(FOO_TEST_STRING), "Wrong content: " + content); + assertTrue(content.contains(("")), "Wrong content: " + content); + assertTrue(content.contains(("", content); + assertEquals("", content, + "Wrong content: " + content); } /** @@ -764,8 +766,8 @@ public void testRootTagWithNamespaceAndPrefixRestart() throws Exception { writer.close(); String content = getOutputFileContent(); - assertEquals("Wrong content: " + content, - "", content); + assertEquals("", + content, "Wrong content: " + content); } /** @@ -793,9 +795,9 @@ public void testRootTagWithAdditionalNamespaceRestart() throws Exception { writer.close(); String content = getOutputFileContent(); - assertEquals("Wrong content: " + content, + assertEquals( "", - content); + content, "Wrong content: " + content); } /** @@ -836,9 +838,9 @@ public void testOpenAndCloseTagsInCallbacks() throws Exception { writer.close(); String content = getOutputFileContent(); - assertEquals("Wrong content: " + content, + assertEquals( "", - content); + content, "Wrong content: " + content); } /** @@ -859,9 +861,9 @@ public void testOpenAndCloseTagsInCallbacksRestart() throws Exception { writer.close(); String content = getOutputFileContent(); - assertEquals("Wrong content: " + content, "" + assertEquals("" + "", - content); + content, "Wrong content: " + content); } /** @@ -882,13 +884,11 @@ public void testOpenAndCloseTagsInComplexCallbacksRestart() throws Exception { writer.close(); String content = getOutputFileContent(); - assertEquals("Wrong content: " + content, - "" - + "PRE-HEADERPOST-HEADER" - + "" - + "PRE-FOOTERPOST-FOOTER" - + "", - content); + assertEquals("" + + "PRE-HEADERPOST-HEADER" + + "" + + "PRE-FOOTERPOST-FOOTER" + + "", content, "Wrong content: " + content); } private void initWriterForSimpleCallbackTests() throws Exception { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/TransactionalStaxEventItemWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/TransactionalStaxEventItemWriterTests.java index 65160582f5..b221d4fd94 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/TransactionalStaxEventItemWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/TransactionalStaxEventItemWriterTests.java @@ -15,9 +15,9 @@ */ package org.springframework.batch.item.xml; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.io.File; import java.io.IOException; @@ -30,8 +30,8 @@ import javax.xml.transform.Result; import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.support.transaction.ResourcelessTransactionManager; import org.springframework.core.io.FileSystemResource; @@ -73,7 +73,7 @@ public String toString() { private static final String TEST_STRING = ""; - @Before + @BeforeEach public void setUp() throws Exception { resource = new FileSystemResource(File.createTempFile("StaxEventWriterOutputSourceTests", ".xml")); writer = createItemWriter(); @@ -100,7 +100,7 @@ public Void doInTransaction(TransactionStatus status) { }); writer.close(); String content = outputFileContent(); - assertTrue("Wrong content: " + content, content.contains(TEST_STRING)); + assertTrue(content.contains(TEST_STRING), "Wrong content: " + content); } /** @@ -159,8 +159,8 @@ public Void doInTransaction(TransactionStatus status) { }); writer.close(); String content = outputFileContent(); - assertEquals("Wrong content: " + content, 1, StringUtils.countOccurrencesOf(content, ("
"))); - assertEquals("Wrong content: " + content, 1, StringUtils.countOccurrencesOf(content, TEST_STRING)); + assertEquals(1, StringUtils.countOccurrencesOf(content, ("
")), "Wrong content: " + content); + assertEquals(1, StringUtils.countOccurrencesOf(content, TEST_STRING), "Wrong content: " + content); } /** @@ -220,8 +220,8 @@ public Void doInTransaction(TransactionStatus status) { } writer.close(); String content = outputFileContent(); - assertEquals("Wrong content: " + content, 1, StringUtils.countOccurrencesOf(content, ("
"))); - assertEquals("Wrong content: " + content, 1, StringUtils.countOccurrencesOf(content, TEST_STRING)); + assertEquals(1, StringUtils.countOccurrencesOf(content, ("
")), "Wrong content: " + content); + assertEquals(1, StringUtils.countOccurrencesOf(content, TEST_STRING), "Wrong content: " + content); } /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilderTests.java index 56190d722c..5f644cc238 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemReaderBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2017-2021 the original author or authors. + * Copyright 2017-2022 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,10 @@ import jakarta.xml.bind.annotation.XmlRootElement; import javax.xml.stream.XMLInputFactory; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnit; -import org.mockito.junit.MockitoRule; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; import org.springframework.batch.item.xml.StaxEventItemReader; @@ -33,10 +32,11 @@ import org.springframework.core.io.Resource; import org.springframework.oxm.jaxb.Jaxb2Marshaller; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import static org.springframework.test.util.ReflectionTestUtils.getField; /** @@ -44,6 +44,7 @@ * @author Mahmoud Ben Hassine * @author Parikshit Dutta */ +@ExtendWith(MockitoExtension.class) public class StaxEventItemReaderBuilderTests { private static final String SIMPLE_XML = "1" @@ -51,9 +52,6 @@ public class StaxEventItemReaderBuilderTests { + "fivesix7" + "eightnine"; - @Rule - public MockitoRule rule = MockitoJUnit.rule().silent(); - @Mock private Resource resource; @@ -141,7 +139,7 @@ public void testCustomEncoding() throws Exception { assertEquals(2, executionContext.size()); } - @Test(expected = ItemStreamException.class) + @Test public void testStrict() throws Exception { Jaxb2Marshaller unmarshaller = new Jaxb2Marshaller(); unmarshaller.setClassesToBeBound(Foo.class); @@ -152,7 +150,7 @@ public void testStrict() throws Exception { reader.afterPropertiesSet(); ExecutionContext executionContext = new ExecutionContext(); - reader.open(executionContext); + assertThrows(ItemStreamException.class, () -> reader.open(executionContext)); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemWriterBuilderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemWriterBuilderTests.java index b517b09165..13a21b6519 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemWriterBuilderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/builder/StaxEventItemWriterBuilderTests.java @@ -27,8 +27,8 @@ import javax.xml.stream.XMLStreamException; import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemStreamException; @@ -40,9 +40,10 @@ import org.springframework.oxm.jaxb.Jaxb2Marshaller; import org.springframework.test.util.ReflectionTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Michael Minella @@ -65,7 +66,7 @@ public class StaxEventItemWriterBuilderTests { + "7" + "eightnine\uFEFF\uFEFF" + ""; - @Before + @BeforeEach public void setUp() throws IOException { File directory = new File("target/data"); directory.mkdirs(); @@ -81,27 +82,12 @@ public void setUp() throws IOException { ((Jaxb2Marshaller) marshaller).setClassesToBeBound(Foo.class); } - @Test(expected = ItemStreamException.class) + @Test public void testOverwriteOutput() throws Exception { StaxEventItemWriter staxEventItemWriter = new StaxEventItemWriterBuilder().name("fooWriter") .marshaller(marshaller).resource(this.resource).overwriteOutput(false).build(); - staxEventItemWriter.afterPropertiesSet(); - - ExecutionContext executionContext = new ExecutionContext(); - staxEventItemWriter.open(executionContext); - - staxEventItemWriter.write(this.items); - - staxEventItemWriter.update(executionContext); - staxEventItemWriter.close(); - - File output = this.resource.getFile(); - - assertTrue(output.exists()); - - executionContext = new ExecutionContext(); - staxEventItemWriter.open(executionContext); + assertThrows(ItemStreamException.class, () -> staxEventItemWriter.open(new ExecutionContext())); } @Test @@ -178,14 +164,16 @@ public void testConfiguration() throws Exception { assertEquals(0, executionContext.size()); } - @Test(expected = IllegalArgumentException.class) + @Test public void testMissingMarshallerValidation() { - new StaxEventItemWriterBuilder().name("fooWriter").build(); + var builder = new StaxEventItemWriterBuilder().name("fooWriter"); + assertThrows(IllegalArgumentException.class, builder::build); } - @Test(expected = IllegalArgumentException.class) + @Test public void testMissingNameValidation() { - new StaxEventItemWriterBuilder().marshaller(new Jaxb2Marshaller()).build(); + var builder = new StaxEventItemWriterBuilder().marshaller(new Jaxb2Marshaller()); + assertThrows(IllegalArgumentException.class, builder::build); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/AbstractEventReaderWrapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/AbstractEventReaderWrapperTests.java index af84ee7109..62111b0af8 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/AbstractEventReaderWrapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/AbstractEventReaderWrapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,6 +15,8 @@ */ package org.springframework.batch.item.xml.stax; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -22,31 +24,32 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Lucas Ward * @author Will Schipp */ -public class AbstractEventReaderWrapperTests extends TestCase { +public class AbstractEventReaderWrapperTests { AbstractEventReaderWrapper eventReaderWrapper; XMLEventReader xmlEventReader; - @Override + @BeforeEach protected void setUp() throws Exception { - super.setUp(); - xmlEventReader = mock(XMLEventReader.class); eventReaderWrapper = new StubEventReader(xmlEventReader); } + @Test public void testClose() throws XMLStreamException { xmlEventReader.close(); eventReaderWrapper.close(); } + @Test public void testGetElementText() throws XMLStreamException { String text = "text"; @@ -54,6 +57,7 @@ public void testGetElementText() throws XMLStreamException { assertEquals(eventReaderWrapper.getElementText(), text); } + @Test public void testGetProperty() throws IllegalArgumentException { String text = "text"; @@ -61,12 +65,14 @@ public void testGetProperty() throws IllegalArgumentException { assertEquals(eventReaderWrapper.getProperty("name"), text); } + @Test public void testHasNext() { when(xmlEventReader.hasNext()).thenReturn(true); assertTrue(eventReaderWrapper.hasNext()); } + @Test public void testNext() { String text = "text"; @@ -74,6 +80,7 @@ public void testNext() { assertEquals(eventReaderWrapper.next(), text); } + @Test public void testNextEvent() throws XMLStreamException { XMLEvent event = mock(XMLEvent.class); @@ -81,6 +88,7 @@ public void testNextEvent() throws XMLStreamException { assertEquals(eventReaderWrapper.nextEvent(), event); } + @Test public void testNextTag() throws XMLStreamException { XMLEvent event = mock(XMLEvent.class); @@ -88,6 +96,7 @@ public void testNextTag() throws XMLStreamException { assertEquals(eventReaderWrapper.nextTag(), event); } + @Test public void testPeek() throws XMLStreamException { XMLEvent event = mock(XMLEvent.class); @@ -95,6 +104,7 @@ public void testPeek() throws XMLStreamException { assertEquals(eventReaderWrapper.peek(), event); } + @Test public void testRemove() { xmlEventReader.remove(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/AbstractEventWriterWrapperTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/AbstractEventWriterWrapperTests.java index 21c1b06c90..c1d1e182ee 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/AbstractEventWriterWrapperTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/AbstractEventWriterWrapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,6 +15,7 @@ */ package org.springframework.batch.item.xml.stax; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -24,27 +25,27 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Lucas Ward * @author Will Schipp * */ -public class AbstractEventWriterWrapperTests extends TestCase { +public class AbstractEventWriterWrapperTests { AbstractEventWriterWrapper eventWriterWrapper; XMLEventWriter xmlEventWriter; - @Override + @BeforeEach protected void setUp() throws Exception { - super.setUp(); - xmlEventWriter = mock(XMLEventWriter.class); eventWriterWrapper = new StubEventWriter(xmlEventWriter); } + @Test public void testAdd() throws XMLStreamException { XMLEvent event = mock(XMLEvent.class); @@ -53,6 +54,7 @@ public void testAdd() throws XMLStreamException { } + @Test public void testAddReader() throws XMLStreamException { XMLEventReader reader = mock(XMLEventReader.class); @@ -60,34 +62,40 @@ public void testAddReader() throws XMLStreamException { eventWriterWrapper.add(reader); } + @Test public void testClose() throws XMLStreamException { xmlEventWriter.close(); eventWriterWrapper.close(); } + @Test public void testFlush() throws XMLStreamException { xmlEventWriter.flush(); eventWriterWrapper.flush(); } + @Test public void testGetNamespaceContext() { NamespaceContext context = mock(NamespaceContext.class); when(xmlEventWriter.getNamespaceContext()).thenReturn(context); assertEquals(eventWriterWrapper.getNamespaceContext(), context); } + @Test public void testGetPrefix() throws XMLStreamException { String uri = "uri"; when(xmlEventWriter.getPrefix(uri)).thenReturn(uri); assertEquals(eventWriterWrapper.getPrefix(uri), uri); } + @Test public void testSetDefaultNamespace() throws XMLStreamException { String uri = "uri"; xmlEventWriter.setDefaultNamespace(uri); eventWriterWrapper.setDefaultNamespace(uri); } + @Test public void testSetNamespaceContext() throws XMLStreamException { NamespaceContext context = mock(NamespaceContext.class); @@ -95,6 +103,7 @@ public void testSetNamespaceContext() throws XMLStreamException { eventWriterWrapper.setNamespaceContext(context); } + @Test public void testSetPrefix() throws XMLStreamException { String uri = "uri"; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReaderTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReaderTests.java index c49b0f0afb..247e232479 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReaderTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/DefaultFragmentEventReaderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2020 the original author or authors. + * Copyright 2008-2022 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,24 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.XMLEvent; -import junit.framework.TestCase; - +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.xml.EventHelper; import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; import org.springframework.util.xml.StaxUtils; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + /** * Tests for {@link DefaultFragmentEventReader}. * * @author Robert Kasanicky * @author Mahmoud Ben Hassine */ -public class DefaultFragmentEventReaderTests extends TestCase { +public class DefaultFragmentEventReaderTests { // object under test private FragmentEventReader fragmentReader; @@ -48,7 +52,7 @@ public class DefaultFragmentEventReaderTests extends TestCase { /** * Setup the fragmentReader to read the test input. */ - @Override + @BeforeEach protected void setUp() throws Exception { Resource input = new ByteArrayResource(xml.getBytes()); eventReader = StaxUtils.createDefensiveInputFactory().createXMLEventReader(input.getInputStream()); @@ -60,6 +64,7 @@ protected void setUp() throws Exception { * uses redundant peek() calls before nextEvent() in important moments to assure * peek() has no side effects on the inner state of reader. */ + @Test public void testFragmentWrapping() throws XMLStreamException { assertTrue(fragmentReader.hasNext()); @@ -104,6 +109,7 @@ public void testFragmentWrapping() throws XMLStreamException { * When fragment is marked as processed the cursor is moved after the end of the * fragment. */ + @Test public void testMarkFragmentProcessed() throws XMLStreamException { moveCursorBeforeFragmentStart(); @@ -124,6 +130,7 @@ public void testMarkFragmentProcessed() throws XMLStreamException { * Cursor is moved to the end of the fragment as usually even if nothing was read from * the event reader after beginning of fragment was marked. */ + @Test public void testMarkFragmentProcessedImmediatelyAfterMarkFragmentStart() throws Exception { moveCursorBeforeFragmentStart(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/NoStartEndDocumentWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/NoStartEndDocumentWriterTests.java index 8824855f83..c53c7a0c0c 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/NoStartEndDocumentWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/NoStartEndDocumentWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2013 the original author or authors. + * Copyright 2008-2022 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,7 +19,8 @@ import javax.xml.stream.XMLEventWriter; import javax.xml.stream.events.XMLEvent; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -32,7 +33,7 @@ * @author Robert Kasanicky * @author Will Schipp */ -public class NoStartEndDocumentWriterTests extends TestCase { +public class NoStartEndDocumentWriterTests { // object under test private NoStartEndDocumentStreamWriter writer; @@ -41,7 +42,7 @@ public class NoStartEndDocumentWriterTests extends TestCase { private XMLEventFactory eventFactory = XMLEventFactory.newInstance(); - @Override + @BeforeEach protected void setUp() throws Exception { wrappedWriter = mock(XMLEventWriter.class); writer = new NoStartEndDocumentStreamWriter(wrappedWriter); @@ -50,6 +51,7 @@ protected void setUp() throws Exception { /** * StartDocument and EndDocument events are not passed to the wrapped writer. */ + @Test public void testNoStartEnd() throws Exception { XMLEvent event = eventFactory.createComment("testEvent"); @@ -66,6 +68,7 @@ public void testNoStartEnd() throws Exception { * Close is not delegated to the wrapped writer. Instead, the wrapped writer is * flushed. */ + @Test public void testClose() throws Exception { writer.close(); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnclosedElementCollectingEventWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnclosedElementCollectingEventWriterTests.java index 2d683961f2..d454bb7a41 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnclosedElementCollectingEventWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnclosedElementCollectingEventWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2022 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,7 +15,7 @@ */ package org.springframework.batch.item.xml.stax; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -24,8 +24,8 @@ import javax.xml.stream.XMLEventWriter; import javax.xml.stream.events.XMLEvent; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; /** @@ -47,7 +47,7 @@ public class UnclosedElementCollectingEventWriterTests { private QName elementC = new QName("elementC"); - @Before + @BeforeEach public void setUp() throws Exception { wrappedWriter = mock(XMLEventWriter.class); writer = new UnclosedElementCollectingEventWriter(wrappedWriter); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriterTests.java index 39e5bfd1fb..9ed3e817b3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/item/xml/stax/UnopenedElementClosingEventWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2022 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,7 +15,8 @@ */ package org.springframework.batch.item.xml.stax; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -31,8 +32,8 @@ import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.dao.DataAccessResourceFailureException; @@ -59,7 +60,7 @@ public class UnopenedElementClosingEventWriterTests { private QName other = new QName("http://test", "other", "t"); - @Before + @BeforeEach public void setUp() throws Exception { wrappedWriter = mock(XMLEventWriter.class); ioWriter = mock(Writer.class); @@ -122,11 +123,11 @@ public void testOtherEvent() throws Exception { verify(wrappedWriter).add(event); } - @Test(expected = DataAccessResourceFailureException.class) + @Test public void testIOException() throws Exception { EndElement endElementB = eventFactory.createEndElement(unopenedB, null); Mockito.doThrow(new IOException("Simulated IOException")).when(ioWriter).write(""); - writer.add(endElementB); + assertThrows(DataAccessResourceFailureException.class, () -> writer.add(endElementB)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java index 049ef90cf0..15dd7fcd91 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/jms/ExternalRetryInBatchTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,10 +16,9 @@ package org.springframework.batch.jms; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemReader; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; @@ -37,8 +36,7 @@ import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.retry.support.DefaultRetryState; import org.springframework.retry.support.RetryTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; @@ -49,10 +47,9 @@ import java.util.Collections; import java.util.List; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") +@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml") public class ExternalRetryInBatchTests { @Autowired @@ -71,7 +68,7 @@ public class ExternalRetryInBatchTests { @Autowired private PlatformTransactionManager transactionManager; - @Before + @BeforeEach public void onSetUp() throws Exception { getMessages(); // drain queue JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS"); @@ -89,7 +86,7 @@ public String read() { retryTemplate = new RetryTemplate(); } - @After + @AfterEach public void onTearDown() throws Exception { getMessages(); // drain queue JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/poller/DirectPollerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/poller/DirectPollerTests.java index ce9e696304..75cde13914 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/poller/DirectPollerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/poller/DirectPollerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2010 the original author or authors. + * Copyright 2006-2022 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,8 +15,8 @@ */ package org.springframework.batch.poller; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import java.util.HashSet; import java.util.Set; @@ -25,7 +25,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Dave Syer diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/AbstractExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/AbstractExceptionTests.java index a9629568b7..03d5810692 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/AbstractExceptionTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/AbstractExceptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,15 +16,19 @@ package org.springframework.batch.repeat; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public abstract class AbstractExceptionTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +public abstract class AbstractExceptionTests { + + @Test public void testExceptionString() throws Exception { Exception exception = getException("foo"); assertEquals("foo", exception.getMessage()); } + @Test public void testExceptionStringThrowable() throws Exception { Exception exception = getException("foo", new IllegalStateException()); assertEquals("foo", exception.getMessage().substring(0, 3)); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/callback/NestedRepeatCallbackTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/callback/NestedRepeatCallbackTests.java index 2b9a3ced6e..587d79b55d 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/callback/NestedRepeatCallbackTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/callback/NestedRepeatCallbackTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,17 +16,20 @@ package org.springframework.batch.repeat.callback; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.support.RepeatTemplate; -public class NestedRepeatCallbackTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class NestedRepeatCallbackTests { int count = 0; + @Test public void testExecute() throws Exception { NestedRepeatCallback callback = new NestedRepeatCallback(new RepeatTemplate(), new RepeatCallback() { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/RepeatContextCounterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/RepeatContextCounterTests.java index 016d31b34a..86e10958b3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/RepeatContextCounterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/RepeatContextCounterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,26 +16,32 @@ package org.springframework.batch.repeat.context; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatContext; -public class RepeatContextCounterTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class RepeatContextCounterTests { RepeatContext parent = new RepeatContextSupport(null); RepeatContext context = new RepeatContextSupport(parent); + @Test public void testAttributeCreated() { new RepeatContextCounter(context, "FOO"); assertTrue(context.hasAttribute("FOO")); } + @Test public void testAttributeCreatedWithNullParent() { new RepeatContextCounter(parent, "FOO", true); assertTrue(parent.hasAttribute("FOO")); } + @Test public void testVanillaIncrement() throws Exception { RepeatContextCounter counter = new RepeatContextCounter(context, "FOO"); assertEquals(0, counter.getCount()); @@ -45,12 +51,14 @@ public void testVanillaIncrement() throws Exception { assertEquals(3, counter.getCount()); } + @Test public void testAttributeCreatedInParent() throws Exception { new RepeatContextCounter(context, "FOO", true); assertFalse(context.hasAttribute("FOO")); assertTrue(parent.hasAttribute("FOO")); } + @Test public void testParentIncrement() throws Exception { RepeatContextCounter counter = new RepeatContextCounter(context, "FOO", true); assertEquals(0, counter.getCount()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/RepeatContextSupportTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/RepeatContextSupportTests.java index fac3853a56..c33495feda 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/RepeatContextSupportTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/RepeatContextSupportTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,13 +18,17 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; /** * @author dsyer * */ -public class RepeatContextSupportTests extends TestCase { +public class RepeatContextSupportTests { private List list = new ArrayList<>(); @@ -32,6 +36,7 @@ public class RepeatContextSupportTests extends TestCase { * Test method for * {@link org.springframework.batch.repeat.context.RepeatContextSupport#registerDestructionCallback(java.lang.String, java.lang.Runnable)}. */ + @Test public void testDestructionCallbackSunnyDay() throws Exception { RepeatContextSupport context = new RepeatContextSupport(null); context.setAttribute("foo", "FOO"); @@ -50,6 +55,7 @@ public void run() { * Test method for * {@link org.springframework.batch.repeat.context.RepeatContextSupport#registerDestructionCallback(java.lang.String, java.lang.Runnable)}. */ + @Test public void testDestructionCallbackMissingAttribute() throws Exception { RepeatContextSupport context = new RepeatContextSupport(null); context.registerDestructionCallback("foo", new Runnable() { @@ -67,6 +73,7 @@ public void run() { * Test method for * {@link org.springframework.batch.repeat.context.RepeatContextSupport#registerDestructionCallback(java.lang.String, java.lang.Runnable)}. */ + @Test public void testDestructionCallbackWithException() throws Exception { RepeatContextSupport context = new RepeatContextSupport(null); context.setAttribute("foo", "FOO"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/SynchronizedAttributeAccessorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/SynchronizedAttributeAccessorTests.java index c081a1eda6..5ffb99ba79 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/SynchronizedAttributeAccessorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/context/SynchronizedAttributeAccessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,32 +21,40 @@ import java.util.List; import java.util.Map; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.core.AttributeAccessorSupport; -public class SynchronizedAttributeAccessorTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SynchronizedAttributeAccessorTests { SynchronizedAttributeAccessor accessor = new SynchronizedAttributeAccessor(); + @Test public void testHashCode() { SynchronizedAttributeAccessor another = new SynchronizedAttributeAccessor(); accessor.setAttribute("foo", "bar"); another.setAttribute("foo", "bar"); assertEquals(accessor, another); - assertEquals("Object.hashCode() contract broken", accessor.hashCode(), another.hashCode()); + assertEquals(accessor.hashCode(), another.hashCode(), "Object.hashCode() contract broken"); } + @Test public void testToStringWithNoAttributes() throws Exception { assertNotNull(accessor.toString()); } + @Test public void testToStringWithAttributes() throws Exception { accessor.setAttribute("foo", "bar"); accessor.setAttribute("spam", "bucket"); assertNotNull(accessor.toString()); } + @Test public void testAttributeNames() { accessor.setAttribute("foo", "bar"); accessor.setAttribute("spam", "bucket"); @@ -55,6 +63,7 @@ public void testAttributeNames() { assertTrue(list.contains("foo")); } + @Test public void testEqualsSameType() { SynchronizedAttributeAccessor another = new SynchronizedAttributeAccessor(); accessor.setAttribute("foo", "bar"); @@ -62,11 +71,13 @@ public void testEqualsSameType() { assertEquals(accessor, another); } + @Test public void testEqualsSelf() { accessor.setAttribute("foo", "bar"); assertEquals(accessor, accessor); } + @Test public void testEqualsWrongType() { accessor.setAttribute("foo", "bar"); Map another = Collections.singletonMap("foo", "bar"); @@ -75,6 +86,7 @@ public void testEqualsWrongType() { assertFalse(accessor.equals(another)); } + @Test public void testEqualsSupport() { @SuppressWarnings("serial") AttributeAccessorSupport another = new AttributeAccessorSupport() { @@ -84,26 +96,31 @@ public void testEqualsSupport() { assertEquals(accessor, another); } + @Test public void testGetAttribute() { accessor.setAttribute("foo", "bar"); assertEquals("bar", accessor.getAttribute("foo")); } + @Test public void testSetAttributeIfAbsentWhenAlreadyPresent() { accessor.setAttribute("foo", "bar"); assertEquals("bar", accessor.setAttributeIfAbsent("foo", "spam")); } + @Test public void testSetAttributeIfAbsentWhenNotAlreadyPresent() { assertEquals(null, accessor.setAttributeIfAbsent("foo", "bar")); assertEquals("bar", accessor.getAttribute("foo")); } + @Test public void testHasAttribute() { accessor.setAttribute("foo", "bar"); assertEquals(true, accessor.hasAttribute("foo")); } + @Test public void testRemoveAttribute() { accessor.setAttribute("foo", "bar"); assertEquals("bar", accessor.getAttribute("foo")); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/CompositeExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/CompositeExceptionHandlerTests.java index 31c45d7064..7a807716a6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/CompositeExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/CompositeExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,16 +19,17 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatContext; -import org.springframework.batch.repeat.exception.CompositeExceptionHandler; -import org.springframework.batch.repeat.exception.ExceptionHandler; -public class CompositeExceptionHandlerTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +public class CompositeExceptionHandlerTests { private CompositeExceptionHandler handler = new CompositeExceptionHandler(); + @Test public void testNewHandler() throws Throwable { try { handler.handleException(null, new RuntimeException()); @@ -38,6 +39,7 @@ public void testNewHandler() throws Throwable { } } + @Test public void testDelegation() throws Throwable { final List list = new ArrayList<>(); handler.setHandlers(new ExceptionHandler[] { new ExceptionHandler() { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/DefaultExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/DefaultExceptionHandlerTests.java index fa2e58fb7b..c2145baebf 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/DefaultExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/DefaultExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,16 +16,19 @@ package org.springframework.batch.repeat.exception; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatContext; -public class DefaultExceptionHandlerTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +public class DefaultExceptionHandlerTests { private DefaultExceptionHandler handler = new DefaultExceptionHandler(); private RepeatContext context = null; + @Test public void testRuntimeException() throws Throwable { try { handler.handleException(context, new RuntimeException("Foo")); @@ -36,6 +39,7 @@ public void testRuntimeException() throws Throwable { } } + @Test public void testError() throws Throwable { try { handler.handleException(context, new Error("Foo")); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java index fee8cd6e80..aa0c8e67e0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/LogOrRethrowExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,8 +18,6 @@ import java.io.StringWriter; -import junit.framework.TestCase; - import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.core.Appender; import org.apache.logging.log4j.core.LoggerContext; @@ -27,6 +25,8 @@ import org.apache.logging.log4j.core.config.Configuration; import org.apache.logging.log4j.core.config.LoggerConfig; import org.apache.logging.log4j.core.layout.PatternLayout; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +34,11 @@ import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.exception.LogOrRethrowExceptionHandler.Level; -public class LogOrRethrowExceptionHandlerTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; + +public class LogOrRethrowExceptionHandlerTests { private LogOrRethrowExceptionHandler handler = new LogOrRethrowExceptionHandler(); @@ -42,9 +46,8 @@ public class LogOrRethrowExceptionHandlerTests extends TestCase { private RepeatContext context = null; - @Override + @BeforeEach protected void setUp() throws Exception { - super.setUp(); Logger logger = LoggerFactory.getLogger(LogOrRethrowExceptionHandler.class); writer = new StringWriter(); LoggerContext loggerContext = (LoggerContext) LogManager.getContext(); @@ -59,6 +62,7 @@ protected void setUp() throws Exception { rootLoggerConfig.addAppender(appender, org.apache.logging.log4j.Level.DEBUG, null); } + @Test public void testRuntimeException() throws Throwable { try { handler.handleException(context, new RuntimeException("Foo")); @@ -69,6 +73,7 @@ public void testRuntimeException() throws Throwable { } } + @Test public void testError() throws Throwable { try { handler.handleException(context, new Error("Foo")); @@ -79,7 +84,7 @@ public void testError() throws Throwable { } } - @SuppressWarnings("serial") + @Test public void testNotRethrownErrorLevel() throws Throwable { handler.setExceptionClassifier(new ClassifierSupport(Level.RETHROW) { @Override @@ -92,7 +97,7 @@ public Level classify(Throwable throwable) { assertNotNull(writer.toString()); } - @SuppressWarnings("serial") + @Test public void testNotRethrownWarnLevel() throws Throwable { handler.setExceptionClassifier(new ClassifierSupport(Level.RETHROW) { @Override @@ -105,7 +110,7 @@ public Level classify(Throwable throwable) { assertNotNull(writer.toString()); } - @SuppressWarnings("serial") + @Test public void testNotRethrownDebugLevel() throws Throwable { handler.setExceptionClassifier(new ClassifierSupport(Level.RETHROW) { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandlerTests.java index 1b318f2f01..f28be0cbb3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/RethrowOnThresholdExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,14 +16,14 @@ package org.springframework.batch.repeat.exception; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Collections; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextSupport; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java index f5cc984e47..48241eab6b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/exception/SimpleLimitExceptionHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,17 +16,17 @@ package org.springframework.batch.repeat.exception; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.context.RepeatContextSupport; /** @@ -40,7 +40,7 @@ public class SimpleLimitExceptionHandlerTests { // object under test private SimpleLimitExceptionHandler handler = new SimpleLimitExceptionHandler(); - @Before + @BeforeEach public void initializeHandler() throws Exception { handler.afterPropertiesSet(); } @@ -74,7 +74,7 @@ public void testDefaultBehaviour() throws Throwable { fail("Exception was swallowed."); } catch (RuntimeException expected) { - assertTrue("Exception is rethrown, ignoring the exception limit", true); + assertTrue(true, "Exception is rethrown, ignoring the exception limit"); assertSame(expected, throwable); } } @@ -98,7 +98,7 @@ public void testNormalExceptionThrown() throws Throwable { fail("Exception was swallowed."); } catch (RuntimeException expected) { - assertTrue("Exception is rethrown, ignoring the exception limit", true); + assertTrue(true, "Exception is rethrown, ignoring the exception limit"); assertSame(expected, throwable); } } @@ -202,7 +202,7 @@ public void testExceptionNotThrownBelowLimit() throws Throwable { for (Throwable throwable : throwables) { handler.handleException(context, throwable); - assertTrue("exceptions up to limit are swallowed", true); + assertTrue(true, "exceptions up to limit are swallowed"); } } @@ -240,7 +240,7 @@ public void testExceptionThrownAboveLimit() throws Throwable { for (Throwable throwable : throwables) { handler.handleException(context, throwable); - assertTrue("exceptions up to limit are swallowed", true); + assertTrue(true, "exceptions up to limit are swallowed"); } } @@ -251,7 +251,7 @@ public void testExceptionThrownAboveLimit() throws Throwable { // after reaching the limit, behaviour should be idempotent try { handler.handleException(context, new RuntimeException("foo")); - assertTrue("exceptions up to limit are swallowed", true); + assertTrue(true, "exceptions up to limit are swallowed"); } catch (RuntimeException expected) { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java index 7472ddb40e..61e67acf8b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/interceptor/RepeatOperationsInterceptorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,10 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.aop.framework.Advised; import org.springframework.aop.framework.ProxyFactory; import org.springframework.batch.repeat.RepeatStatus; @@ -34,7 +34,12 @@ import org.springframework.batch.repeat.policy.SimpleCompletionPolicy; import org.springframework.batch.repeat.support.RepeatTemplate; -public class RepeatOperationsInterceptorTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +public class RepeatOperationsInterceptorTests { private RepeatOperationsInterceptor interceptor; @@ -42,9 +47,8 @@ public class RepeatOperationsInterceptorTests extends TestCase { private ServiceImpl target; - @Override + @BeforeEach protected void setUp() throws Exception { - super.setUp(); interceptor = new RepeatOperationsInterceptor(); target = new ServiceImpl(); ProxyFactory factory = new ProxyFactory(RepeatOperations.class.getClassLoader()); @@ -53,12 +57,14 @@ protected void setUp() throws Exception { service = (Service) factory.getProxy(); } + @Test public void testDefaultInterceptorSunnyDay() throws Exception { ((Advised) service).addAdvice(interceptor); service.service(); assertEquals(3, target.count); } + @Test public void testCompleteOnFirstInvocation() throws Exception { ((Advised) service).addAdvice(interceptor); target.setMaxService(0); @@ -66,6 +72,7 @@ public void testCompleteOnFirstInvocation() throws Exception { assertEquals(1, target.count); } + @Test public void testSetTemplate() throws Exception { final List calls = new ArrayList<>(); interceptor.setRepeatOperations(new RepeatOperations() { @@ -86,6 +93,7 @@ public RepeatStatus iterate(RepeatCallback callback) { assertEquals(1, calls.size()); } + @Test public void testCallbackNotExecuted() throws Exception { final List calls = new ArrayList<>(); interceptor.setRepeatOperations(new RepeatOperations() { @@ -102,11 +110,12 @@ public RepeatStatus iterate(RepeatCallback callback) { } catch (IllegalStateException e) { String message = e.getMessage(); - assertTrue("Wrong exception message: " + message, message.toLowerCase().contains("no result available")); + assertTrue(message.toLowerCase().contains("no result available"), "Wrong exception message: " + message); } assertEquals(1, calls.size()); } + @Test public void testVoidServiceSunnyDay() throws Exception { ((Advised) service).addAdvice(interceptor); RepeatTemplate template = new RepeatTemplate(); @@ -118,6 +127,7 @@ public void testVoidServiceSunnyDay() throws Exception { assertEquals(2, target.count); } + @Test public void testCallbackWithException() throws Exception { ((Advised) service).addAdvice(interceptor); try { @@ -129,6 +139,7 @@ public void testCallbackWithException() throws Exception { } } + @Test public void testCallbackWithThrowable() throws Exception { ((Advised) service).addAdvice(interceptor); try { @@ -140,6 +151,7 @@ public void testCallbackWithThrowable() throws Exception { } } + @Test public void testCallbackWithBoolean() throws Exception { RepeatTemplate template = new RepeatTemplate(); // N.B. the default completion policy results in an infinite loop, so we @@ -151,6 +163,7 @@ public void testCallbackWithBoolean() throws Exception { assertEquals(2, target.count); } + @Test public void testCallbackWithBooleanReturningFalseFirstTime() throws Exception { target.setComplete(true); ((Advised) service).addAdvice(interceptor); @@ -159,6 +172,7 @@ public void testCallbackWithBooleanReturningFalseFirstTime() throws Exception { assertEquals(1, target.count); } + @Test public void testInterceptorChainWithRetry() throws Exception { ((Advised) service).addAdvice(interceptor); final List list = new ArrayList<>(); @@ -177,6 +191,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable { assertEquals(2, list.size()); } + @Test public void testIllegalMethodInvocationType() throws Throwable { try { interceptor.invoke(new MethodInvocation() { @@ -213,8 +228,8 @@ public Object proceed() throws Throwable { fail("IllegalStateException expected"); } catch (IllegalStateException e) { - assertTrue("Exception message should contain MethodInvocation: " + e.getMessage(), - e.getMessage().indexOf("MethodInvocation") >= 0); + assertTrue(e.getMessage().contains("MethodInvocation"), + "Exception message should contain MethodInvocation: " + e.getMessage()); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java index 034de3f0bd..f6ba3de561 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/jms/AsynchronousTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,10 +23,9 @@ import jakarta.jms.Session; import jakarta.jms.TextMessage; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.container.jms.BatchMessageListenerContainer; import org.springframework.beans.factory.annotation.Autowired; @@ -34,16 +33,14 @@ import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.listener.SessionAwareMessageListener; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") +@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml") @DirtiesContext public class AsynchronousTests { @@ -56,7 +53,7 @@ public class AsynchronousTests { @Autowired private JdbcTemplate jdbcTemplate; - @Before + @BeforeEach public void onSetUp() throws Exception { String foo = ""; int count = 0; @@ -75,7 +72,7 @@ public void onSetUp() throws Exception { } - @After + @AfterEach public void onTearDown() throws Exception { container.stop(); // Need to give the container time to shutdown @@ -173,7 +170,7 @@ public void onMessage(Message message, Session session) throws JMSException { int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS"); assertEquals(0, count); - assertTrue("Foo not on queue", msgs.contains("foo")); + assertTrue(msgs.contains("foo"), "Foo not on queue"); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java index 5918dfd487..a2b585f81a 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/jms/SynchronousTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,8 +16,8 @@ package org.springframework.batch.repeat.jms; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; @@ -26,8 +26,7 @@ import jakarta.jms.JMSException; import jakarta.jms.Session; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; @@ -42,8 +41,7 @@ import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.SessionCallback; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.PlatformTransactionManager; @@ -51,8 +49,7 @@ import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") +@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml") @DirtiesContext public class SynchronousTests implements ApplicationContextAware { @@ -161,7 +158,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { // ... and so did the message session. The rollback should have restored // the queue, so this should now be non-null - assertTrue("Foo not on queue", msgs.contains("foo")); + assertTrue(msgs.contains("foo"), "Foo not on queue"); } @Transactional @@ -198,7 +195,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { @Override public Void doInJms(Session session) throws JMSException { try { - assertTrue("Not a SessionProxy - wrong spring version?", session instanceof SessionProxy); + assertTrue(session instanceof SessionProxy, "Not a SessionProxy - wrong spring version?"); ((SessionProxy) session).getTargetSession().rollback(); } catch (JMSException e) { @@ -228,8 +225,8 @@ public Void doInJms(Session session) throws JMSException { assertEquals(2, count); // ...but the JMS session rolled back, so the message is still there - assertTrue("Foo not on queue", msgs.contains("foo")); - assertTrue("Bar not on queue", msgs.contains("bar")); + assertTrue(msgs.contains("foo"), "Foo not on queue"); + assertTrue(msgs.contains("bar"), "Bar not on queue"); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/CompositeRepeatListenerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/CompositeRepeatListenerTests.java index 9145386a4b..0e541e02c5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/CompositeRepeatListenerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/CompositeRepeatListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,18 +18,19 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatListener; import org.springframework.batch.repeat.context.RepeatContextSupport; +import static org.junit.jupiter.api.Assertions.assertEquals; + /** * @author Dave Syer * @author Mahmoud Ben Hassine * */ -public class CompositeRepeatListenerTests extends TestCase { +public class CompositeRepeatListenerTests { private CompositeRepeatListener listener = new CompositeRepeatListener(); @@ -40,6 +41,7 @@ public class CompositeRepeatListenerTests extends TestCase { /** * Test method for {@link CompositeRepeatListener#setListeners(RepeatListener[])}. */ + @Test public void testSetListeners() { listener.setListeners(new RepeatListener[] { new RepeatListener() { @Override @@ -59,6 +61,7 @@ public void open(RepeatContext context) { /** * Test method for {@link CompositeRepeatListener#register(RepeatListener)}. */ + @Test public void testSetListener() { listener.register(new RepeatListener() { @Override @@ -70,6 +73,7 @@ public void before(RepeatContext context) { assertEquals(1, list.size()); } + @Test public void testClose() { listener.register(new RepeatListener() { @Override @@ -81,6 +85,7 @@ public void close(RepeatContext context) { assertEquals(1, list.size()); } + @Test public void testOnError() { listener.register(new RepeatListener() { @Override diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java index ee239d2e20..f6073ca8e4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/listener/RepeatListenerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,8 +19,7 @@ import java.util.ArrayList; import java.util.List; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; @@ -29,10 +28,15 @@ import org.springframework.batch.repeat.support.TaskExecutorRepeatTemplate; import org.springframework.core.task.SimpleAsyncTaskExecutor; -public class RepeatListenerTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; + +public class RepeatListenerTests { int count = 0; + @Test public void testBeforeInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); @@ -62,6 +66,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals("[1, 2, 1, 2]", calls.toString()); } + @Test public void testBeforeInterceptorCanVeto() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); @@ -84,6 +89,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals("[1]", calls.toString()); } + @Test public void testAfterInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); @@ -111,6 +117,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals("[2, 1]", calls.toString()); } + @Test public void testOpenInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); @@ -137,6 +144,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals("[1, 2]", calls.toString()); } + @Test public void testSingleOpenInterceptor() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); @@ -158,6 +166,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals("[1]", calls.toString()); } + @Test public void testCloseInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); @@ -185,6 +194,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals("[2, 1]", calls.toString()); } + @Test public void testOnErrorInterceptors() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); @@ -215,6 +225,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals("[2, 1]", calls.toString()); } + @Test public void testOnErrorInterceptorsPrecedence() throws Exception { RepeatTemplate template = new RepeatTemplate(); final List calls = new ArrayList<>(); @@ -246,6 +257,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals("[2]", calls.toString()); } + @Test public void testAsynchronousOnErrorInterceptorsPrecedence() throws Exception { TaskExecutorRepeatTemplate template = new TaskExecutorRepeatTemplate(); template.setTaskExecutor(new SimpleAsyncTaskExecutor()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicyTests.java index 23c37edc32..cc5edc1691 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CompositeCompletionPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,14 +16,19 @@ package org.springframework.batch.repeat.policy; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.CompletionPolicy; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; -public class CompositeCompletionPolicyTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CompositeCompletionPolicyTests { + @Test public void testEmptyPolicies() throws Exception { CompositeCompletionPolicy policy = new CompositeCompletionPolicy(); RepeatContext context = policy.start(null); @@ -31,6 +36,7 @@ public void testEmptyPolicies() throws Exception { assertFalse(policy.isComplete(context)); } + @Test public void testTrivialPolicies() throws Exception { CompositeCompletionPolicy policy = new CompositeCompletionPolicy(); policy.setPolicies( @@ -43,6 +49,7 @@ public void testTrivialPolicies() throws Exception { assertEquals(1, context.getStartedCount()); } + @Test public void testNonTrivialPolicies() throws Exception { CompositeCompletionPolicy policy = new CompositeCompletionPolicy(); policy.setPolicies( @@ -56,6 +63,7 @@ public boolean isComplete(RepeatContext context) { assertTrue(policy.isComplete(context)); } + @Test public void testNonTrivialPoliciesWithResult() throws Exception { CompositeCompletionPolicy policy = new CompositeCompletionPolicy(); policy.setPolicies( diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CountingCompletionPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CountingCompletionPolicyTests.java index 59bee4b241..b33640cab2 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CountingCompletionPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/CountingCompletionPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,14 +16,17 @@ package org.springframework.batch.repeat.policy; -import junit.framework.TestCase; - +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextSupport; -public class CountingCompletionPolicyTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class CountingCompletionPolicyTests { + @Test public void testDefaultBehaviour() throws Exception { CountingCompletionPolicy policy = new CountingCompletionPolicy() { @Override @@ -35,6 +38,7 @@ protected int getCount(RepeatContext context) { assertTrue(policy.isComplete(context)); } + @Test public void testNullResult() throws Exception { CountingCompletionPolicy policy = new CountingCompletionPolicy() { @Override @@ -47,6 +51,7 @@ protected int getCount(RepeatContext context) { assertTrue(policy.isComplete(context, null)); } + @Test public void testFinishedResult() throws Exception { CountingCompletionPolicy policy = new CountingCompletionPolicy() { @Override @@ -59,6 +64,7 @@ protected int getCount(RepeatContext context) { assertTrue(policy.isComplete(context, RepeatStatus.FINISHED)); } + @Test public void testDefaultBehaviourWithUpdate() throws Exception { CountingCompletionPolicy policy = new CountingCompletionPolicy() { int count = 0; @@ -82,6 +88,7 @@ protected int doUpdate(RepeatContext context) { assertTrue(policy.isComplete(context)); } + @Test public void testUpdateNotSavedAcrossSession() throws Exception { CountingCompletionPolicy policy = new CountingCompletionPolicy() { int count = 0; @@ -114,6 +121,7 @@ public RepeatContext start(RepeatContext context) { assertFalse(policy.isComplete(context)); } + @Test public void testUpdateSavedAcrossSession() throws Exception { CountingCompletionPolicy policy = new CountingCompletionPolicy() { int count = 0; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicyTests.java index c79cbbc5d6..3f6f03c979 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/SimpleCompletionPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,12 +16,15 @@ package org.springframework.batch.repeat.policy; -import junit.framework.TestCase; - +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; -public class SimpleCompletionPolicyTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class SimpleCompletionPolicyTests { SimpleCompletionPolicy policy = new SimpleCompletionPolicy(); @@ -29,12 +32,12 @@ public class SimpleCompletionPolicyTests extends TestCase { RepeatStatus dummy = RepeatStatus.CONTINUABLE; - @Override + @BeforeEach protected void setUp() throws Exception { - super.setUp(); context = policy.start(null); } + @Test public void testTerminationAfterDefaultSize() throws Exception { for (int i = 0; i < SimpleCompletionPolicy.DEFAULT_CHUNK_SIZE - 1; i++) { policy.update(context); @@ -44,6 +47,7 @@ public void testTerminationAfterDefaultSize() throws Exception { assertTrue(policy.isComplete(context, dummy)); } + @Test public void testTerminationAfterExplicitChunkSize() throws Exception { int chunkSize = 2; policy.setChunkSize(chunkSize); @@ -55,6 +59,7 @@ public void testTerminationAfterExplicitChunkSize() throws Exception { assertTrue(policy.isComplete(context, dummy)); } + @Test public void testTerminationAfterNullResult() throws Exception { policy.update(context); assertFalse(policy.isComplete(context, dummy)); @@ -62,6 +67,7 @@ public void testTerminationAfterNullResult() throws Exception { assertTrue(policy.isComplete(context, null)); } + @Test public void testReset() throws Exception { policy.setChunkSize(2); policy.update(context); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/TimeoutCompletionPolicyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/TimeoutCompletionPolicyTests.java index 6b77479c79..94c25d7682 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/TimeoutCompletionPolicyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/policy/TimeoutCompletionPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,10 +16,10 @@ package org.springframework.batch.repeat.policy; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatStatus; import org.springframework.batch.repeat.RepeatContext; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/AbstractTradeBatchTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/AbstractTradeBatchTests.java index fabd0dbea2..2c9ec25fdf 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/AbstractTradeBatchTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/AbstractTradeBatchTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,7 +18,7 @@ import java.util.List; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.file.FlatFileItemReader; @@ -45,7 +45,7 @@ public abstract class AbstractTradeBatchTests { protected TradeItemReader provider; - @Before + @BeforeEach public void setUp() throws Exception { provider = new TradeItemReader(resource); provider.open(new ExecutionContext()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java index 7c73662f93..970e0fedce 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ChunkedRepeatTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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,7 +16,7 @@ package org.springframework.batch.repeat.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemReader; import org.springframework.batch.repeat.RepeatCallback; @@ -27,9 +27,9 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.lang.Nullable; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test various approaches to chunking of a batch. Not really a unit test, but it should @@ -104,7 +104,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals(NUMBER_OF_ITEMS, processor.count); assertFalse(result.isContinuable()); - assertTrue("Expected at least 3 chunks but found: " + count, count >= 3); + assertTrue(count >= 3, "Expected at least 3 chunks but found: " + count); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/RepeatSynchronizationManagerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/RepeatSynchronizationManagerTests.java index cb342725b1..85bddd5b59 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/RepeatSynchronizationManagerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/RepeatSynchronizationManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,30 +16,38 @@ package org.springframework.batch.repeat.support; -import junit.framework.TestCase; - +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.context.RepeatContextSupport; -public class RepeatSynchronizationManagerTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class RepeatSynchronizationManagerTests { private RepeatContext context = new RepeatContextSupport(null); - @Override + @BeforeEach protected void setUp() throws Exception { RepeatSynchronizationManager.clear(); } - @Override + @AfterEach protected void tearDown() throws Exception { RepeatSynchronizationManager.clear(); } + @Test public void testGetContext() { RepeatSynchronizationManager.register(context); assertEquals(context, RepeatSynchronizationManager.getContext()); } + @Test public void testSetSessionCompleteOnly() { assertNull(RepeatSynchronizationManager.getContext()); RepeatSynchronizationManager.register(context); @@ -48,6 +56,7 @@ public void testSetSessionCompleteOnly() { assertTrue(RepeatSynchronizationManager.getContext().isCompleteOnly()); } + @Test public void testSetSessionCompleteOnlyWithParent() { assertNull(RepeatSynchronizationManager.getContext()); RepeatContext child = new RepeatContextSupport(context); @@ -58,6 +67,7 @@ public void testSetSessionCompleteOnlyWithParent() { assertTrue(context.isCompleteOnly()); } + @Test public void testClear() { RepeatSynchronizationManager.register(context); assertEquals(context, RepeatSynchronizationManager.getContext()); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ResultHolderResultQueueTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ResultHolderResultQueueTests.java index 2dbb874452..daada407fb 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ResultHolderResultQueueTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ResultHolderResultQueueTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2012 the original author or authors. + * Copyright 2009-2022 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,10 +15,10 @@ */ package org.springframework.batch.repeat.support; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatStatus; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java index 0e60677bcb..a7f10cbe26 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/SimpleRepeatTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,18 +16,18 @@ package org.springframework.batch.repeat.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatException; @@ -99,7 +99,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { } assertEquals(1, count); - assertTrue("Too many attempts: " + count, count <= 10); + assertTrue(count <= 10, "Too many attempts: " + count); } @@ -281,7 +281,7 @@ public void testNestedSession() throws Exception { public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertNotNull(context); - assertNotSame("Nested batch should have new session", context, context.getParent()); + assertNotSame(context, context.getParent(), "Nested batch should have new session"); assertSame(context, RepeatSynchronizationManager.getContext()); return RepeatStatus.FINISHED; } @@ -329,7 +329,7 @@ public void testOuterContextPreserved() throws Exception { public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertNotNull(context); - assertNotSame("Nested batch should have new session", context, context.getParent()); + assertNotSame(context, context.getParent(), "Nested batch should have new session"); assertSame(context, RepeatSynchronizationManager.getContext()); return RepeatStatus.FINISHED; } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateAsynchronousTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateAsynchronousTests.java index 12ad7b2f53..25fc7c5f86 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateAsynchronousTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateAsynchronousTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,12 +16,12 @@ package org.springframework.batch.repeat.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.Collections; @@ -29,7 +29,7 @@ import java.util.List; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; @@ -76,8 +76,8 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { assertEquals("foo!", e.getMessage()); } - assertTrue("Too few attempts: " + count, count >= 1); - assertTrue("Too many attempts: " + count, count <= 10); + assertTrue(count >= 1, "Too few attempts: " + count); + assertTrue(count <= 10, "Too many attempts: " + count); } @@ -103,8 +103,8 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { } }); - assertTrue("Too few attempts: " + count, count >= 1); - assertTrue("Too many attempts: " + count, count <= 10); + assertTrue(count >= 1, "Too few attempts: " + count); + assertTrue(count <= 10, "Too many attempts: " + count); } @@ -119,7 +119,7 @@ public void testNestedSession() throws Exception { public RepeatStatus doInIteration(RepeatContext context) throws Exception { count++; assertNotNull(context); - assertNotSame("Nested batch should have new session", context, context.getParent()); + assertNotSame(context, context.getParent(), "Nested batch should have new session"); assertSame(context, RepeatSynchronizationManager.getContext()); return RepeatStatus.FINISHED; } @@ -133,8 +133,8 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { } }); - assertTrue("Too few attempts: " + count, count >= 1); - assertTrue("Too many attempts: " + count, count <= 10); + assertTrue(count >= 1, "Too few attempts: " + count); + assertTrue(count <= 10, "Too many attempts: " + count); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java index e4184ce3dc..fc366930d1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateBulkAsynchronousTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,9 +16,9 @@ package org.springframework.batch.repeat.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.ArrayList; import java.util.Collections; @@ -28,9 +28,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.repeat.RepeatCallback; import org.springframework.batch.repeat.RepeatContext; import org.springframework.batch.repeat.RepeatStatus; @@ -68,7 +68,7 @@ public class TaskExecutorRepeatTemplateBulkAsynchronousTests { private ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor(); - @Before + @BeforeEach public void setUp() { template = new TaskExecutorRepeatTemplate(); @@ -114,7 +114,7 @@ public RepeatStatus doInIteration(RepeatContext context) throws Exception { } - @After + @AfterEach public void tearDown() { threadPool.destroy(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateTests.java index 12b6a0533d..1ddec0942e 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/TaskExecutorRepeatTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,9 +16,9 @@ package org.springframework.batch.repeat.support; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Dave Syer diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueueTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueueTests.java index b1004b153a..247220df5b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueueTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/repeat/support/ThrottleLimitResultQueueTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,14 +15,14 @@ */ package org.springframework.batch.repeat.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.NoSuchElementException; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Dave Syer @@ -88,8 +88,8 @@ public void run() { long t1 = System.currentTimeMillis(); assertEquals("foo", queue.take()); assertTrue(queue.isExpecting()); - assertTrue("Did not block on expect (throttle limit should have been hit): time taken=" + (t1 - t0), - t1 - t0 > 50); + assertTrue(t1 - t0 > 50, + "Did not block on expect (throttle limit should have been hit): time taken=" + (t1 - t0)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java index aa428679f5..c7003a7ca0 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/jms/ExternalRetryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,9 +16,8 @@ package org.springframework.batch.retry.jms; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; import org.springframework.beans.factory.annotation.Autowired; @@ -30,8 +29,7 @@ import org.springframework.retry.RetryContext; import org.springframework.retry.support.DefaultRetryState; import org.springframework.retry.support.RetryTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; @@ -42,11 +40,10 @@ import java.util.Collections; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") +@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml") public class ExternalRetryTests { @Autowired @@ -62,7 +59,7 @@ public class ExternalRetryTests { @Autowired private PlatformTransactionManager transactionManager; - @Before + @BeforeEach public void onSetUp() throws Exception { getMessages(); // drain queue JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS"); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java index 2d40b1f5f0..bb42ad7113 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/retry/jms/SynchronousTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,9 +16,8 @@ package org.springframework.batch.retry.jms; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.batch.item.jms.JmsItemReader; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; @@ -26,8 +25,7 @@ import org.springframework.retry.RetryCallback; import org.springframework.retry.RetryContext; import org.springframework.retry.support.RetryTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; import org.springframework.test.context.transaction.AfterTransaction; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.test.jdbc.JdbcTestUtils; @@ -40,13 +38,12 @@ import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = "/org/springframework/batch/jms/jms-context.xml") +@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml") public class SynchronousTests { @Autowired @@ -69,7 +66,7 @@ public void onSetUpBeforeTransaction() throws Exception { assertNotNull(text); } - @Before + @BeforeEach public void onSetUpInTransaction() throws Exception { retryTemplate = new RetryTemplate(); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/AbstractExceptionTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/AbstractExceptionTests.java index 7afd46a3fd..376eaded0b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/AbstractExceptionTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/AbstractExceptionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,15 +16,19 @@ package org.springframework.batch.support; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public abstract class AbstractExceptionTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +public abstract class AbstractExceptionTests { + + @Test public void testExceptionString() throws Exception { Exception exception = getException("foo"); assertEquals("foo", exception.getMessage()); } + @Test public void testExceptionStringThrowable() throws Exception { Exception exception = getException("foo", new IllegalStateException()); assertEquals("foo", exception.getMessage().substring(0, 3)); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/AnnotationMethodResolverTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/AnnotationMethodResolverTests.java index 0aec1951bb..762ad1cc09 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/AnnotationMethodResolverTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/AnnotationMethodResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2022 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,8 +16,9 @@ package org.springframework.batch.support; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -25,8 +26,7 @@ import java.lang.annotation.Target; import java.lang.reflect.Method; -import org.junit.Test; -import org.springframework.batch.support.AnnotationMethodResolver; +import org.junit.jupiter.api.Test; /** * @author Mark Fisher @@ -40,10 +40,10 @@ public void singleAnnotation() { assertNotNull(method); } - @Test(expected = IllegalArgumentException.class) + @Test public void multipleAnnotations() { AnnotationMethodResolver resolver = new AnnotationMethodResolver(TestAnnotation.class); - resolver.findMethod(MultipleAnnotationTestBean.class); + assertThrows(IllegalArgumentException.class, () -> resolver.findMethod(MultipleAnnotationTestBean.class)); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DatabaseTypeIntegrationTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DatabaseTypeIntegrationTests.java index 72c6c98060..9095b999f7 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DatabaseTypeIntegrationTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DatabaseTypeIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2018 the original author or authors. + * Copyright 2006-2022 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.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.sql.DataSource; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Dave Syer diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DatabaseTypeTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DatabaseTypeTests.java index 3509aab306..ffcd4f0d04 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DatabaseTypeTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DatabaseTypeTests.java @@ -15,12 +15,13 @@ */ package org.springframework.batch.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.jdbc.support.MetaDataAccessException; import javax.sql.DataSource; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.batch.support.DatabaseType.DB2; import static org.springframework.batch.support.DatabaseType.DB2VSE; import static org.springframework.batch.support.DatabaseType.DB2ZOS; @@ -60,10 +61,9 @@ public void testFromProductName() { assertEquals(HANA, fromProductName("HDB")); } - @Test(expected = IllegalArgumentException.class) + @Test public void testInvalidProductName() { - - fromProductName("bad product name"); + assertThrows(IllegalArgumentException.class, () -> fromProductName("bad product name")); } @Test @@ -150,10 +150,10 @@ public void testFromMetaDataForHana() throws Exception { assertEquals(HANA, DatabaseType.fromMetaData(ds)); } - @Test(expected = MetaDataAccessException.class) + @Test public void testBadMetaData() throws Exception { DataSource ds = DatabaseTypeTestUtils.getMockDataSource(new MetaDataAccessException("Bad!")); - assertEquals(SYBASE, DatabaseType.fromMetaData(ds)); + assertThrows(MetaDataAccessException.class, () -> DatabaseType.fromMetaData(ds)); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DefaultPropertyEditorRegistrarTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DefaultPropertyEditorRegistrarTests.java index 83c1d89b4f..478461b0ce 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DefaultPropertyEditorRegistrarTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/DefaultPropertyEditorRegistrarTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2019 the original author or authors. + * Copyright 2006-2022 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,12 +16,14 @@ package org.springframework.batch.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.Collections; +import java.util.Map; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.propertyeditors.CustomNumberEditor; @@ -43,11 +45,11 @@ public void testIntArray() throws Exception { assertEquals(4, result.numbers[3]); } - @Test(expected = IllegalArgumentException.class) + @Test public void testSetCustomEditorsWithInvalidTypeName() throws Exception { - DefaultPropertyEditorRegistrar mapper = new DefaultPropertyEditorRegistrar(); - mapper.setCustomEditors(Collections.singletonMap("FOO", new CustomNumberEditor(Long.class, true))); + var customEditors = Map.of("FOO", new CustomNumberEditor(Long.class, true)); + assertThrows(IllegalArgumentException.class, () -> mapper.setCustomEditors(customEditors)); } @Test @@ -63,11 +65,11 @@ public void testSetCustomEditorsWithStringTypeName() throws Exception { } - @Test(expected = IllegalArgumentException.class) + @Test public void testSetCustomEditorsWithInvalidType() throws Exception { - DefaultPropertyEditorRegistrar mapper = new DefaultPropertyEditorRegistrar(); - mapper.setCustomEditors(Collections.singletonMap(new Object(), new CustomNumberEditor(Long.class, true))); + var customEditors = Map.of(new Object(), new CustomNumberEditor(Long.class, true)); + assertThrows(IllegalArgumentException.class, () -> mapper.setCustomEditors(customEditors)); } @SuppressWarnings("unused") diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/LastModifiedResourceComparatorTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/LastModifiedResourceComparatorTests.java index 91d15e7f39..801db29aa5 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/LastModifiedResourceComparatorTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/LastModifiedResourceComparatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,14 +15,15 @@ */ package org.springframework.batch.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.io.FileSystemResource; import java.io.File; import java.io.IOException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Dave Syer @@ -35,14 +36,18 @@ public class LastModifiedResourceComparatorTests { private LastModifiedResourceComparator comparator = new LastModifiedResourceComparator(); - @Test(expected = IllegalArgumentException.class) + @Test public void testCompareTwoNonExistent() { - comparator.compare(new FileSystemResource("garbage"), new FileSystemResource("crap")); + FileSystemResource garbage = new FileSystemResource("garbage"); + FileSystemResource crap = new FileSystemResource("crap"); + assertThrows(IllegalArgumentException.class, () -> comparator.compare(garbage, crap)); } - @Test(expected = IllegalArgumentException.class) + @Test public void testCompareOneNonExistent() { - comparator.compare(new FileSystemResource(FILE_PATH), new FileSystemResource("crap")); + FileSystemResource exists = new FileSystemResource(FILE_PATH); + FileSystemResource crap = new FileSystemResource("crap"); + assertThrows(IllegalArgumentException.class, () -> comparator.compare(exists, crap)); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/PatternMatcherTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/PatternMatcherTests.java index b7e31c927d..21cfc098a4 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/PatternMatcherTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/PatternMatcherTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,14 +15,15 @@ */ package org.springframework.batch.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.HashMap; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Dan Garrette @@ -116,9 +117,10 @@ public void testMatchPrefixUnrelated() { assertEquals(4, new PatternMatcher<>(map).match("biggest").intValue()); } - @Test(expected = IllegalStateException.class) + @Test public void testMatchPrefixNoMatch() { - new PatternMatcher<>(map).match("bat"); + PatternMatcher matcher = new PatternMatcher<>(map); + assertThrows(IllegalStateException.class, () -> matcher.match("bat")); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/PropertiesConverterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/PropertiesConverterTests.java index 60967946d9..30d9c3373f 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/PropertiesConverterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/PropertiesConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,13 +16,13 @@ package org.springframework.batch.support; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Properties; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.util.StringUtils; /** @@ -94,8 +94,8 @@ public void testShortConversionWithCommas() { String value = PropertiesConverter.propertiesToString(storedProps); - assertTrue("Wrong value: " + value, value.contains("key1=value1")); - assertTrue("Wrong value: " + value, value.contains("key2=value2")); + assertTrue(value.contains("key1=value1"), "Wrong value: " + value); + assertTrue(value.contains("key2=value2"), "Wrong value: " + value); assertEquals(1, StringUtils.countOccurrencesOf(value, ",")); } @@ -121,7 +121,7 @@ public void testRegularConversionWithCommaAndNewline() { public void testStringToPropertiesNull() { props = PropertiesConverter.stringToProperties(null); assertNotNull(props); - assertEquals("properties are empty", 0, props.size()); + assertEquals(0, props.size(), "properties are empty"); } /** diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/ReflectionUtilsTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/ReflectionUtilsTests.java index 23ac7e605c..5a3449d943 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/ReflectionUtilsTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/ReflectionUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2022 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,7 +15,7 @@ */ package org.springframework.batch.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; @@ -23,8 +23,8 @@ import java.util.Iterator; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Michael Minella diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SimpleMethodInvokerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SimpleMethodInvokerTests.java index 411c902148..668dd51bc9 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SimpleMethodInvokerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SimpleMethodInvokerTests.java @@ -1,21 +1,5 @@ /* - * Copyright 2002-2008 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Copyright 2002-2008 the original author or authors. + * Copyright 2002-2022 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. @@ -33,14 +17,15 @@ import java.lang.reflect.Method; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.util.Assert; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Lucas Ward @@ -52,7 +37,7 @@ public class SimpleMethodInvokerTests { String value = "foo"; - @Before + @BeforeEach public void setUp() { testClass = new TestClass(); } @@ -89,19 +74,18 @@ public void testMethodByNameWithExecution() throws Exception { assertTrue(testClass.beforeCalled); } - @Test(expected = IllegalArgumentException.class) + @Test public void testMethodWithTooManyArguments() throws Exception { Method method = TestClass.class.getMethod("beforeWithTooManyArguments", String.class, int.class); MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, method); - methodInvoker.invokeMethod(value); + assertThrows(IllegalArgumentException.class, () -> methodInvoker.invokeMethod(value)); assertFalse(testClass.beforeCalled); } - @Test(expected = IllegalArgumentException.class) - public void testMethodByNameWithTooManyArguments() throws Exception { - MethodInvoker methodInvoker = new SimpleMethodInvoker(testClass, "beforeWithTooManyArguments", String.class); - methodInvoker.invokeMethod(value); - assertFalse(testClass.beforeCalled); + @Test + public void testMethodByNameWithTooManyArguments() { + assertThrows(IllegalArgumentException.class, + () -> new SimpleMethodInvoker(testClass, "beforeWithTooManyArguments", String.class)); } @Test diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SystemPropertyInitializerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SystemPropertyInitializerTests.java index 29f5c57da6..f31ff6446b 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SystemPropertyInitializerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/SystemPropertyInitializerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,11 +15,12 @@ */ package org.springframework.batch.support; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Dave Syer @@ -31,8 +32,8 @@ public class SystemPropertyInitializerTests { private SystemPropertyInitializer initializer = new SystemPropertyInitializer(); - @Before - @After + @BeforeEach + @AfterEach public void initializeProperty() { System.clearProperty(SystemPropertyInitializer.ENVIRONMENT); System.clearProperty(SIMPLE_NAME); @@ -53,9 +54,9 @@ public void testSetDefaultValue() throws Exception { assertEquals("foo", System.getProperty(SystemPropertyInitializer.ENVIRONMENT)); } - @Test(expected = IllegalStateException.class) - public void testNoDefaultValue() throws Exception { - initializer.afterPropertiesSet(); + @Test + public void testNoDefaultValue() { + assertThrows(IllegalStateException.class, initializer::afterPropertiesSet); } } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ConcurrentTransactionAwareProxyTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ConcurrentTransactionAwareProxyTests.java index 552425cbee..6851514a58 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ConcurrentTransactionAwareProxyTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ConcurrentTransactionAwareProxyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,8 +16,9 @@ package org.springframework.batch.support.transaction; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.util.ArrayList; import java.util.HashMap; @@ -33,10 +34,10 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; @@ -48,7 +49,7 @@ * @author Mahmoud Ben Hassine * */ -@Ignore // FIXME https://github.com/spring-projects/spring-batch/issues/3847 +@Disabled // FIXME https://github.com/spring-projects/spring-batch/issues/3847 public class ConcurrentTransactionAwareProxyTests { private static Log logger = LogFactory.getLog(ConcurrentTransactionAwareProxyTests.class); @@ -63,21 +64,21 @@ public class ConcurrentTransactionAwareProxyTests { private CompletionService> completionService; - @Before + @BeforeEach public void init() { executor = Executors.newFixedThreadPool(outerMax); completionService = new ExecutorCompletionService<>(executor); } - @After + @AfterEach public void close() { executor.shutdown(); } - @Test(expected = Throwable.class) - public void testConcurrentTransactionalSet() throws Exception { + @Test + public void testConcurrentTransactionalSet() { Set set = TransactionAwareProxyFactory.createTransactionalSet(); - testSet(set); + assertThrows(Throwable.class, () -> testSet(set)); } @Test @@ -98,10 +99,10 @@ public void testConcurrentTransactionalAppendOnlyMap() throws Exception { testMap(map); } - @Test(expected = ExecutionException.class) - public void testConcurrentTransactionalMap() throws Exception { + @Test + public void testConcurrentTransactionalMap() { Map> map = TransactionAwareProxyFactory.createTransactionalMap(); - testMap(map); + assertThrows(ExecutionException.class, () -> testMap(map)); } @Test @@ -173,10 +174,10 @@ public List call() throws Exception { for (int i = 0; i < outerMax; i++) { List result = completionService.take().get(); - assertEquals("Wrong number of results in inner task", innerMax, result.size()); + assertEquals(innerMax, result.size(), "Wrong number of results in inner task"); } - assertEquals("Wrong number of results in aggregate", innerMax * outerMax, list.size()); + assertEquals(innerMax * outerMax, list.size(), "Wrong number of results in aggregate"); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ResourcelessTransactionManagerTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ResourcelessTransactionManagerTests.java index 3d41b7c447..16d61f94fa 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ResourcelessTransactionManagerTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/ResourcelessTransactionManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,10 +16,10 @@ package org.springframework.batch.support.transaction; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.transaction.support.TransactionTemplate; diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriterTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriterTests.java index 94786b6db5..3dbd0886d6 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriterTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareBufferedWriterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2021 the original author or authors. + * Copyright 2006-2022 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,16 +19,16 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -49,7 +49,7 @@ public class TransactionAwareBufferedWriterTests { private TransactionAwareBufferedWriter writer; - @Before + @BeforeEach public void init() { fileChannel = mock(FileChannel.class); @@ -266,7 +266,7 @@ public void testWriteWithRollback() throws Exception { catch (RuntimeException e) { // expected String message = e.getMessage(); - assertEquals("Wrong message: " + message, "Planned failure", message); + assertEquals("Planned failure", message, "Wrong message: " + message); } assertEquals(0, writer.getBufferSize()); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareListFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareListFactoryTests.java index a6e685337c..6be68b5222 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareListFactoryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareListFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,16 +16,16 @@ package org.springframework.batch.support.transaction; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; @@ -36,7 +36,7 @@ public class TransactionAwareListFactoryTests { private List list; - @Before + @BeforeEach public void setUp() throws Exception { list = TransactionAwareProxyFactory.createTransactionalList(Arrays.asList("foo", "bar", "spam")); } diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareMapFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareMapFactoryTests.java index 501eb90ae1..abf7fa0ac3 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareMapFactoryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareMapFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,19 +19,24 @@ import java.util.HashMap; import java.util.Map; -import junit.framework.TestCase; - +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; -public class TransactionAwareMapFactoryTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + +public class TransactionAwareMapFactoryTests { TransactionTemplate transactionTemplate = new TransactionTemplate(new ResourcelessTransactionManager()); Map map; - @Override + @BeforeEach protected void setUp() throws Exception { Map seed = new HashMap<>(); seed.put("foo", "oof"); @@ -40,24 +45,28 @@ protected void setUp() throws Exception { map = TransactionAwareProxyFactory.createTransactionalMap(seed); } + @Test public void testAdd() { assertEquals(3, map.size()); map.put("bucket", "crap"); assertTrue(map.keySet().contains("bucket")); } + @Test public void testEmpty() { assertEquals(3, map.size()); map.put("bucket", "crap"); assertFalse(map.isEmpty()); } + @Test public void testValues() { assertEquals(3, map.size()); map.put("bucket", "crap"); assertEquals(4, map.keySet().size()); } + @Test public void testRemove() { assertEquals(3, map.size()); assertTrue(map.keySet().contains("spam")); @@ -65,12 +74,14 @@ public void testRemove() { assertFalse(map.keySet().contains("spam")); } + @Test public void testClear() { assertEquals(3, map.size()); map.clear(); assertEquals(0, map.size()); } + @Test public void testTransactionalAdd() throws Exception { transactionTemplate.execute(new TransactionCallback() { @Override @@ -82,6 +93,7 @@ public Void doInTransaction(TransactionStatus status) { assertEquals(4, map.size()); } + @Test public void testTransactionalEmpty() throws Exception { transactionTemplate.execute(new TransactionCallback() { @Override @@ -93,6 +105,7 @@ public Void doInTransaction(TransactionStatus status) { assertEquals(4, map.size()); } + @Test public void testTransactionalValues() throws Exception { transactionTemplate.execute(new TransactionCallback() { @Override @@ -104,6 +117,7 @@ public Void doInTransaction(TransactionStatus status) { assertEquals(4, map.size()); } + @Test public void testTransactionalRemove() throws Exception { transactionTemplate.execute(new TransactionCallback() { @Override @@ -115,6 +129,7 @@ public Void doInTransaction(TransactionStatus status) { assertEquals(2, map.size()); } + @Test public void testTransactionalClear() throws Exception { transactionTemplate.execute(new TransactionCallback() { @Override @@ -126,6 +141,7 @@ public Void doInTransaction(TransactionStatus status) { assertEquals(0, map.size()); } + @Test public void testTransactionalAddWithRollback() throws Exception { try { transactionTemplate.execute(new TransactionCallback() { @@ -143,6 +159,7 @@ public Void doInTransaction(TransactionStatus status) { assertEquals(3, map.size()); } + @Test public void testTransactionalRemoveWithRollback() throws Exception { try { transactionTemplate.execute(new TransactionCallback() { @@ -160,6 +177,7 @@ public Void doInTransaction(TransactionStatus status) { assertEquals(3, map.size()); } + @Test public void testTransactionalClearWithRollback() throws Exception { try { transactionTemplate.execute(new TransactionCallback() { diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactoryTests.java index a87f3a047d..2d937247d1 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactoryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareProxyFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,38 +21,46 @@ import java.util.Map; import java.util.Set; -import junit.framework.TestCase; +import org.junit.jupiter.api.Test; -public class TransactionAwareProxyFactoryTests extends TestCase { +import static org.junit.jupiter.api.Assertions.assertEquals; +public class TransactionAwareProxyFactoryTests { + + @Test public void testCreateList() throws Exception { List list = TransactionAwareProxyFactory.createTransactionalList(); list.add("foo"); assertEquals(1, list.size()); } + @Test public void testCreateListWithValues() throws Exception { List list = TransactionAwareProxyFactory.createTransactionalList(Collections.singletonList("foo")); assertEquals(1, list.size()); } + @Test public void testCreateSet() throws Exception { Set set = TransactionAwareProxyFactory.createTransactionalSet(); set.add("foo"); assertEquals(1, set.size()); } + @Test public void testCreateSetWithValues() throws Exception { Set list = TransactionAwareProxyFactory.createTransactionalSet(Collections.singleton("foo")); assertEquals(1, list.size()); } + @Test public void testCreateMap() throws Exception { Map map = TransactionAwareProxyFactory.createTransactionalMap(); map.put("foo", "bar"); assertEquals(1, map.size()); } + @Test public void testCreateMapWithValues() throws Exception { Map map = TransactionAwareProxyFactory .createTransactionalMap(Collections.singletonMap("foo", "bar")); diff --git a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareSetFactoryTests.java b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareSetFactoryTests.java index 1b70b66c6c..cec06ff711 100644 --- a/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareSetFactoryTests.java +++ b/spring-batch-infrastructure/src/test/java/org/springframework/batch/support/transaction/TransactionAwareSetFactoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2007 the original author or authors. + * Copyright 2006-2022 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,17 +16,17 @@ package org.springframework.batch.support.transaction; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; @@ -37,7 +37,7 @@ public class TransactionAwareSetFactoryTests { private Set set; - @Before + @BeforeEach public void setUp() throws Exception { set = TransactionAwareProxyFactory.createTransactionalSet(new HashSet<>(Arrays.asList("foo", "bar", "spam"))); }