Skip to content

Commit e4056b4

Browse files
hpoettkerfmbenhassine
authored andcommitted
Polish Spring Batch Infrastructure tests
1 parent 1e4a23e commit e4056b4

File tree

280 files changed

+3545
-5438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

280 files changed

+3545
-5438
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.batch.repeat;
17+
package org.springframework.batch.common;
1818

1919
import org.junit.jupiter.api.Test;
2020

@@ -23,19 +23,19 @@
2323
public abstract class AbstractExceptionTests {
2424

2525
@Test
26-
public void testExceptionString() throws Exception {
26+
void testExceptionString() {
2727
Exception exception = getException("foo");
2828
assertEquals("foo", exception.getMessage());
2929
}
3030

3131
@Test
32-
public void testExceptionStringThrowable() throws Exception {
32+
void testExceptionStringThrowable() {
3333
Exception exception = getException("foo", new IllegalStateException());
3434
assertEquals("foo", exception.getMessage().substring(0, 3));
3535
}
3636

37-
public abstract Exception getException(String msg) throws Exception;
37+
protected abstract Exception getException(String msg);
3838

39-
public abstract Exception getException(String msg, Throwable t) throws Exception;
39+
protected abstract Exception getException(String msg, Throwable t);
4040

4141
}

spring-batch-infrastructure/src/test/java/org/springframework/batch/config/DatasourceTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
import org.junit.jupiter.api.Test;
2727

2828
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
29-
public class DatasourceTests {
29+
class DatasourceTests {
3030

3131
@Autowired
3232
private JdbcTemplate jdbcTemplate;
3333

3434
@Transactional
3535
@Test
36-
public void testTemplate() throws Exception {
36+
void testTemplate() {
3737
System.err.println(System.getProperty("java.class.path"));
3838
JdbcTestUtils.deleteFromTables(jdbcTemplate, "T_BARS");
3939
int count = JdbcTestUtils.countRowsInTable(jdbcTemplate, "T_BARS");

spring-batch-infrastructure/src/test/java/org/springframework/batch/config/MessagingTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@
2929
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
3030

3131
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
32-
public class MessagingTests {
32+
class MessagingTests {
3333

3434
@Autowired
3535
private JmsTemplate jmsTemplate;
3636

3737
@BeforeEach
38-
public void onSetUp() throws Exception {
38+
void onSetUp() throws Exception {
3939
Thread.sleep(100L);
4040
getMessages(); // drain queue
4141
jmsTemplate.convertAndSend("queue", "foo");
4242
jmsTemplate.convertAndSend("queue", "bar");
4343
}
4444

4545
@Test
46-
public void testMessaging() throws Exception {
46+
void testMessaging() {
4747
List<String> list = getMessages();
4848
System.err.println(list);
4949
assertEquals(2, list.size());

spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerIntegrationTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,25 @@
4848
/**
4949
* @author Dave Syer
5050
* @author Mahmoud Ben Hassine
51-
*
51+
*
5252
*/
5353
@SpringJUnitConfig(locations = "/org/springframework/batch/jms/jms-context.xml")
5454
@DirtiesContext
55-
public class BatchMessageListenerContainerIntegrationTests {
55+
class BatchMessageListenerContainerIntegrationTests {
5656

5757
@Autowired
5858
private JmsTemplate jmsTemplate;
5959

6060
@Autowired
6161
private BatchMessageListenerContainer container;
6262

63-
private volatile BlockingQueue<String> recovered = new LinkedBlockingQueue<>();
63+
private final BlockingQueue<String> recovered = new LinkedBlockingQueue<>();
6464

65-
private volatile BlockingQueue<String> processed = new LinkedBlockingQueue<>();
65+
private final BlockingQueue<String> processed = new LinkedBlockingQueue<>();
6666

6767
@AfterEach
6868
@BeforeEach
69-
public void drainQueue() throws Exception {
69+
void drainQueue() {
7070
container.stop();
7171
while (jmsTemplate.receiveAndConvert("queue") != null) {
7272
// do nothing
@@ -75,17 +75,17 @@ public void drainQueue() throws Exception {
7575
}
7676

7777
@AfterAll
78-
public static void giveContainerTimeToStop() throws Exception {
78+
static void giveContainerTimeToStop() throws Exception {
7979
Thread.sleep(1000);
8080
}
8181

8282
@Test
83-
public void testConfiguration() throws Exception {
83+
void testConfiguration() {
8484
assertNotNull(container);
8585
}
8686

8787
@Test
88-
public void testSendAndReceive() throws Exception {
88+
void testSendAndReceive() throws Exception {
8989
container.setMessageListener(new MessageListener() {
9090
@Override
9191
public void onMessage(Message msg) {
@@ -109,7 +109,7 @@ public void onMessage(Message msg) {
109109
}
110110

111111
@Test
112-
public void testFailureAndRepresent() throws Exception {
112+
void testFailureAndRepresent() throws Exception {
113113
container.setMessageListener(new MessageListener() {
114114
@Override
115115
public void onMessage(Message msg) {
@@ -131,7 +131,7 @@ public void onMessage(Message msg) {
131131
}
132132

133133
@Test
134-
public void testFailureAndRecovery() throws Exception {
134+
void testFailureAndRecovery() throws Exception {
135135
final RetryTemplate retryTemplate = new RetryTemplate();
136136
retryTemplate.setRetryPolicy(new NeverRetryPolicy());
137137
container.setMessageListener(new MessageListener() {

spring-batch-infrastructure/src/test/java/org/springframework/batch/container/jms/BatchMessageListenerContainerTests.java

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@
3535

3636
import static org.junit.jupiter.api.Assertions.assertEquals;
3737
import static org.junit.jupiter.api.Assertions.assertFalse;
38+
import static org.junit.jupiter.api.Assertions.assertThrows;
3839
import static org.junit.jupiter.api.Assertions.assertTrue;
39-
import static org.junit.jupiter.api.Assertions.fail;
4040
import static org.mockito.Mockito.mock;
4141
import static org.mockito.Mockito.when;
4242

43-
public class BatchMessageListenerContainerTests {
43+
class BatchMessageListenerContainerTests {
4444

4545
BatchMessageListenerContainer container;
4646

4747
@Test
48-
public void testReceiveAndExecuteWithCallback() throws Exception {
48+
void testReceiveAndExecuteWithCallback() throws Exception {
4949
RepeatTemplate template = new RepeatTemplate();
5050
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
5151
container = getContainer(template);
@@ -71,7 +71,7 @@ public void onMessage(Message arg0) {
7171
}
7272

7373
@Test
74-
public void testReceiveAndExecuteWithCallbackReturningNull() throws Exception {
74+
void testReceiveAndExecuteWithCallbackReturningNull() throws Exception {
7575
RepeatTemplate template = new RepeatTemplate();
7676
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
7777
container = getContainer(template);
@@ -91,23 +91,18 @@ public void testReceiveAndExecuteWithCallbackReturningNull() throws Exception {
9191
}
9292

9393
@Test
94-
public void testTransactionalReceiveAndExecuteWithCallbackThrowingException() throws Exception {
94+
void testTransactionalReceiveAndExecuteWithCallbackThrowingException() {
9595
RepeatTemplate template = new RepeatTemplate();
9696
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
9797
container = getContainer(template);
9898
container.setSessionTransacted(true);
99-
try {
100-
boolean received = doTestWithException(new IllegalStateException("No way!"), true, 2);
101-
assertFalse(received, "Message received");
102-
fail("Expected IllegalStateException");
103-
}
104-
catch (IllegalStateException e) {
105-
assertEquals("No way!", e.getMessage());
106-
}
99+
Exception exception = assertThrows(IllegalStateException.class,
100+
() -> doTestWithException(new IllegalStateException("No way!"), true, 2));
101+
assertEquals("No way!", exception.getMessage());
107102
}
108103

109104
@Test
110-
public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingException() throws Exception {
105+
void testNonTransactionalReceiveAndExecuteWithCallbackThrowingException() throws Exception {
111106
RepeatTemplate template = new RepeatTemplate();
112107
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
113108
container = getContainer(template);
@@ -117,19 +112,13 @@ public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingException()
117112
}
118113

119114
@Test
120-
public void testNonTransactionalReceiveAndExecuteWithCallbackThrowingError() throws Exception {
115+
void testNonTransactionalReceiveAndExecuteWithCallbackThrowingError() throws Exception {
121116
RepeatTemplate template = new RepeatTemplate();
122117
template.setCompletionPolicy(new SimpleCompletionPolicy(2));
123118
container = getContainer(template);
124119
container.setSessionTransacted(false);
125-
try {
126-
boolean received = doTestWithException(new RuntimeException("No way!"), false, 2);
127-
assertTrue(received, "Message not received but listener not transactional so this should be true");
128-
}
129-
catch (RuntimeException e) {
130-
assertEquals("No way!", e.getMessage());
131-
fail("Unexpected Error - should be swallowed");
132-
}
120+
boolean received = doTestWithException(new RuntimeException("No way!"), false, 2);
121+
assertTrue(received, "Message not received but listener not transactional so this should be true");
133122
}
134123

135124
private BatchMessageListenerContainer getContainer(RepeatTemplate template) {

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemReaderTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ public abstract class AbstractItemReaderTests {
3636
protected abstract ItemReader<Foo> getItemReader() throws Exception;
3737

3838
@BeforeEach
39-
public void setUp() throws Exception {
39+
protected void setUp() throws Exception {
4040
tested = getItemReader();
4141
}
4242

4343
/**
4444
* Regular scenario - read the input and eventually return null.
4545
*/
4646
@Test
47-
public void testRead() throws Exception {
47+
void testRead() throws Exception {
4848

4949
Foo foo1 = tested.read();
5050
assertEquals(1, foo1.getValue());
@@ -68,7 +68,7 @@ public void testRead() throws Exception {
6868
* Empty input should be handled gracefully - null is returned on first read.
6969
*/
7070
@Test
71-
public void testEmptyInput() throws Exception {
71+
void testEmptyInput() throws Exception {
7272
pointToEmptyInput(tested);
7373
tested.read();
7474
assertNull(tested.read());

spring-batch-infrastructure/src/test/java/org/springframework/batch/item/AbstractItemStreamItemReaderTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ protected ItemStream testedAsStream() {
3939

4040
@Override
4141
@BeforeEach
42-
public void setUp() throws Exception {
42+
protected void setUp() throws Exception {
4343
super.setUp();
4444
testedAsStream().open(executionContext);
4545
}
4646

4747
@AfterEach
48-
public void tearDown() throws Exception {
48+
protected void tearDown() throws Exception {
4949
testedAsStream().close();
5050
}
5151

@@ -55,7 +55,7 @@ public void tearDown() throws Exception {
5555
* finished.
5656
*/
5757
@Test
58-
public void testRestart() throws Exception {
58+
protected void testRestart() throws Exception {
5959

6060
testedAsStream().update(executionContext);
6161

@@ -84,7 +84,7 @@ public void testRestart() throws Exception {
8484
* should continue where the old one finished.
8585
*/
8686
@Test
87-
public void testResetAndRestart() throws Exception {
87+
void testResetAndRestart() throws Exception {
8888

8989
testedAsStream().update(executionContext);
9090

@@ -111,7 +111,7 @@ public void testResetAndRestart() throws Exception {
111111
}
112112

113113
@Test
114-
public void testReopen() throws Exception {
114+
void testReopen() throws Exception {
115115
testedAsStream().update(executionContext);
116116

117117
Foo foo1 = tested.read();

0 commit comments

Comments
 (0)