Skip to content

Commit 3ef199b

Browse files
hpoettkerfmbenhassine
authored andcommitted
Reduce use of deprecated APIs
1 parent 451db9a commit 3ef199b

File tree

13 files changed

+43
-78
lines changed

13 files changed

+43
-78
lines changed

spring-batch-core/src/test/java/org/springframework/batch/core/ExitStatusTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -226,13 +226,10 @@ public void testUnknownIsRunning() throws Exception {
226226
}
227227

228228
@Test
229-
public void testSerializable() throws Exception {
229+
public void testSerializable() {
230230
ExitStatus status = ExitStatus.EXECUTING.replaceExitCode("FOO");
231-
byte[] bytes = SerializationUtils.serialize(status);
232-
Object object = SerializationUtils.deserialize(bytes);
233-
assertTrue(object instanceof ExitStatus);
234-
ExitStatus restored = (ExitStatus) object;
235-
assertEquals(status.getExitCode(), restored.getExitCode());
231+
ExitStatus clone = SerializationUtils.clone(status);
232+
assertEquals(status.getExitCode(), clone.getExitCode());
236233
}
237234

238235
}

spring-batch-core/src/test/java/org/springframework/batch/core/JobExecutionTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -193,13 +193,13 @@ public void testToStringWithNullJob() throws Exception {
193193

194194
@Test
195195
public void testSerialization() {
196-
byte[] serialized = SerializationUtils.serialize(execution);
197-
JobExecution deserialize = (JobExecution) SerializationUtils.deserialize(serialized);
198-
assertEquals(execution, deserialize);
199-
assertNotNull(deserialize.createStepExecution("foo"));
200-
assertNotNull(deserialize.getFailureExceptions());
196+
JobExecution clone = SerializationUtils.clone(execution);
197+
assertEquals(execution, clone);
198+
assertNotNull(clone.createStepExecution("foo"));
199+
assertNotNull(clone.getFailureExceptions());
201200
}
202201

202+
@Test
203203
public void testFailureExceptions() {
204204

205205
RuntimeException exception = new RuntimeException();

spring-batch-core/src/test/java/org/springframework/batch/core/JobInstanceTests.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -59,10 +59,7 @@ public void testCreateWithNulls() {
5959
@Test
6060
public void testSerialization() {
6161
instance = new JobInstance(1L, "jobName");
62-
63-
byte[] serialized = SerializationUtils.serialize(instance);
64-
65-
assertEquals(instance, SerializationUtils.deserialize(serialized));
62+
assertEquals(instance, SerializationUtils.clone(instance));
6663
}
6764

6865
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/JobParametersTests.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2008-2021 the original author or authors.
2+
* Copyright 2008-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@
2020
import static org.junit.Assert.assertNull;
2121
import static org.junit.Assert.assertTrue;
2222

23-
import java.util.Collections;
2423
import java.util.Date;
2524
import java.util.HashMap;
2625
import java.util.Map;
@@ -184,10 +183,7 @@ public void testHashCodeEqualWhenNotEmpty() throws Exception {
184183
@Test
185184
public void testSerialization() {
186185
JobParameters params = getNewParameters();
187-
188-
byte[] serialized = SerializationUtils.serialize(params);
189-
190-
assertEquals(params, SerializationUtils.deserialize(serialized));
186+
assertEquals(params, SerializationUtils.clone(params));
191187
}
192188

193189
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/StepExecutionTests.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,17 @@ public void testHashCodeViaHashSet() throws Exception {
259259
}
260260

261261
@Test
262-
public void testSerialization() throws Exception {
262+
public void testSerialization() {
263263

264264
ExitStatus status = ExitStatus.NOOP;
265265
execution.setExitStatus(status);
266266
execution.setExecutionContext(foobarEc);
267267

268-
byte[] serialized = SerializationUtils.serialize(execution);
269-
StepExecution deserialized = (StepExecution) SerializationUtils.deserialize(serialized);
268+
StepExecution clone = SerializationUtils.clone(execution);
270269

271-
assertEquals(execution, deserialized);
272-
assertEquals(status, deserialized.getExitStatus());
273-
assertNotNull(deserialized.getFailureExceptions());
270+
assertEquals(execution, clone);
271+
assertEquals(status, clone.getExitStatus());
272+
assertNotNull(clone.getFailureExceptions());
274273
}
275274

276275
@Test

spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/Db2JobRepositoryIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 the original author or authors.
2+
* Copyright 2020-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -97,7 +97,7 @@ public DataSource dataSource() throws Exception {
9797
dataSource.setUser(db2.getUsername());
9898
dataSource.setPassword(db2.getPassword());
9999
dataSource.setDriverType(4);
100-
dataSource.setServerName(db2.getContainerIpAddress());
100+
dataSource.setServerName(db2.getHost());
101101
dataSource.setPortNumber(db2.getMappedPort(Db2Container.DB2_PORT));
102102
dataSource.setSslConnection(false);
103103
return dataSource;

spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/HANAJobRepositoryIntegrationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
import org.springframework.core.io.ClassPathResource;
4949
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
5050
import org.springframework.test.context.ContextConfiguration;
51-
import org.springframework.test.context.junit.jupiter.EnabledIf;
5251
import org.springframework.test.context.junit4.SpringRunner;
5352

5453
import org.testcontainers.containers.JdbcDatabaseContainer;
@@ -228,7 +227,7 @@ public String getTestQueryString() {
228227

229228
@Override
230229
public String getJdbcUrl() {
231-
return "jdbc:sap://" + getContainerIpAddress() + ":" + getMappedPort(PORT) + "/";
230+
return "jdbc:sap://" + getHost() + ":" + getMappedPort(PORT) + "/";
232231
}
233232

234233
}

spring-batch-core/src/test/java/org/springframework/batch/core/test/repository/OracleJobRepositoryIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public DataSource dataSource() throws Exception {
103103
oracleDataSource.setUser(oracle.getUsername());
104104
oracleDataSource.setPassword(oracle.getPassword());
105105
oracleDataSource.setDatabaseName(oracle.getDatabaseName());
106-
oracleDataSource.setServerName(oracle.getContainerIpAddress());
106+
oracleDataSource.setServerName(oracle.getHost());
107107
oracleDataSource.setPortNumber(oracle.getOraclePort());
108108
return oracleDataSource;
109109
}

spring-batch-core/src/test/java/org/springframework/batch/core/test/step/StepExecutionSerializationUtilsTests.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717

1818
import static org.junit.Assert.assertEquals;
1919

20-
import java.util.concurrent.Callable;
2120
import java.util.concurrent.CompletionService;
2221
import java.util.concurrent.Executor;
2322
import java.util.concurrent.ExecutorCompletionService;
@@ -40,11 +39,11 @@
4039
public class StepExecutionSerializationUtilsTests {
4140

4241
@Test
43-
public void testCycle() throws Exception {
42+
public void testCycle() {
4443
StepExecution stepExecution = new StepExecution("step",
4544
new JobExecution(new JobInstance(123L, "job"), 321L, new JobParameters()), 11L);
4645
stepExecution.getExecutionContext().put("foo.bar.spam", 123);
47-
StepExecution result = getCopy(stepExecution);
46+
StepExecution result = SerializationUtils.clone(stepExecution);
4847
assertEquals(stepExecution, result);
4948
}
5049

@@ -61,15 +60,12 @@ public void testMultipleCycles() throws Throwable {
6160
for (int i = 0; i < repeats; i++) {
6261
final JobExecution jobExecution = new JobExecution(new JobInstance(123L, "job"), 321L, new JobParameters());
6362
for (int j = 0; j < threads; j++) {
64-
completionService.submit(new Callable<StepExecution>() {
65-
@Override
66-
public StepExecution call() throws Exception {
67-
final StepExecution stepExecution = jobExecution.createStepExecution("step");
68-
stepExecution.getExecutionContext().put("foo.bar.spam", 123);
69-
StepExecution result = getCopy(stepExecution);
70-
assertEquals(stepExecution.getExecutionContext(), result.getExecutionContext());
71-
return result;
72-
}
63+
completionService.submit(() -> {
64+
final StepExecution stepExecution = jobExecution.createStepExecution("step");
65+
stepExecution.getExecutionContext().put("foo.bar.spam", 123);
66+
StepExecution result = SerializationUtils.clone(stepExecution);
67+
assertEquals(stepExecution.getExecutionContext(), result.getExecutionContext());
68+
return result;
7369
});
7470
}
7571
for (int j = 0; j < threads; j++) {
@@ -97,8 +93,4 @@ public StepExecution call() throws Exception {
9793
}
9894
}
9995

100-
private StepExecution getCopy(StepExecution stepExecution) {
101-
return (StepExecution) SerializationUtils.deserialize(SerializationUtils.serialize(stepExecution));
102-
}
103-
10496
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2018 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -153,12 +153,10 @@ public void testSerialization() {
153153
context.put("5", s);
154154
context.putInt("6", 6);
155155

156-
byte[] serialized = SerializationUtils.serialize(context);
156+
ExecutionContext clone = SerializationUtils.clone(context);
157157

158-
ExecutionContext deserialized = (ExecutionContext) SerializationUtils.deserialize(serialized);
159-
160-
assertEquals(context, deserialized);
161-
assertEquals(7, ((TestSerializable) deserialized.get("5")).value);
158+
assertEquals(context, clone);
159+
assertEquals(7, ((TestSerializable) clone.get("5")).value);
162160
}
163161

164162
@Test

spring-batch-infrastructure/src/test/java/test/jdbc/datasource/DataSourceInitializer.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -76,17 +76,6 @@ public static void main(String... args) {
7676
DataSourceInitializer.class.getSimpleName() + "-context.xml"));
7777
}
7878

79-
/**
80-
* @throws Throwable
81-
* @see java.lang.Object#finalize()
82-
*/
83-
@Override
84-
protected void finalize() throws Throwable {
85-
logger.debug("finalize called for " + dataSource);
86-
super.finalize();
87-
initialized = false;
88-
}
89-
9079
@Override
9180
public void destroy() {
9281
logger.info("destroy called for " + dataSource);

spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkRequestTests.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,10 +54,8 @@ public void testToString() {
5454
}
5555

5656
@Test
57-
public void testSerializable() throws Exception {
58-
@SuppressWarnings("unchecked")
59-
ChunkRequest<String> result = (ChunkRequest<String>) SerializationUtils
60-
.deserialize(SerializationUtils.serialize(request));
57+
public void testSerializable() {
58+
ChunkRequest<String> result = SerializationUtils.clone(request);
6159
assertNotNull(result.getStepContribution());
6260
assertEquals(111L, result.getJobId());
6361
assertEquals(2, result.getItems().size());

spring-batch-integration/src/test/java/org/springframework/batch/integration/chunk/ChunkResponseTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2021 the original author or authors.
2+
* Copyright 2006-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,8 +47,8 @@ public void testToString() {
4747
}
4848

4949
@Test
50-
public void testSerializable() throws Exception {
51-
ChunkResponse result = (ChunkResponse) SerializationUtils.deserialize(SerializationUtils.serialize(response));
50+
public void testSerializable() {
51+
ChunkResponse result = SerializationUtils.clone(response);
5252
assertNotNull(result.getStepContribution());
5353
assertEquals(Long.valueOf(111L), result.getJobId());
5454
}

0 commit comments

Comments
 (0)