Mark fields as final where appropriate

This commit is contained in:
Mahmoud Ben Hassine
2023-07-04 21:45:20 +02:00
parent 241e37e672
commit 0a1cdb095f
166 changed files with 411 additions and 365 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 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.
@@ -218,7 +218,7 @@ public class JobScopeConfigurationTests {
public static class Wrapper {
private SimpleHolder value;
private final SimpleHolder value;
public Wrapper(SimpleHolder value) {
this.value = value;

View File

@@ -238,7 +238,7 @@ public class StepScopeConfigurationTests {
public static class Wrapper {
private SimpleHolder value;
private final SimpleHolder value;
public Wrapper(SimpleHolder value) {
this.value = value;

View File

@@ -83,7 +83,7 @@ public class PartitionStepParserTests implements ApplicationContextAware {
private ApplicationContext applicationContext;
private List<String> savedStepNames = new ArrayList<>();
private final List<String> savedStepNames = new ArrayList<>();
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2019 the original author or authors.
* Copyright 2006-2023 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.
@@ -44,7 +44,7 @@ import org.springframework.util.ClassUtils;
*/
public class JobSupport implements BeanNameAware, Job, StepLocator {
private Map<String, Step> steps = new HashMap<>();
private final Map<String, Step> steps = new HashMap<>();
private String name;

View File

@@ -537,7 +537,7 @@ class SimpleJobTests {
private Throwable exception;
private JobRepository jobRepository;
private final JobRepository jobRepository;
private ExecutionContext passedInStepContext;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2010-2022 the original author or authors.
* Copyright 2010-2023 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.
@@ -50,7 +50,7 @@ import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
*/
class FlowJobFailureTests {
private FlowJob job = new FlowJob();
private final FlowJob job = new FlowJob();
private JobExecution execution;

View File

@@ -170,7 +170,7 @@ class CommandLineJobRunnerTests {
@Test
void testWithStdinCommandLine() throws Throwable {
System.setIn(new InputStream() {
char[] input = (jobPath + "\n" + jobName + "\nfoo=bar\nspam=bucket").toCharArray();
final char[] input = (jobPath + "\n" + jobName + "\nfoo=bar\nspam=bucket").toCharArray();
int index = 0;
@@ -192,7 +192,7 @@ class CommandLineJobRunnerTests {
@Test
void testWithStdinCommandLineWithEmptyLines() throws Throwable {
System.setIn(new InputStream() {
char[] input = (jobPath + "\n" + jobName + "\nfoo=bar\n\nspam=bucket\n\n").toCharArray();
final char[] input = (jobPath + "\n" + jobName + "\nfoo=bar\n\nspam=bucket\n\n").toCharArray();
int index = 0;
@@ -215,7 +215,7 @@ class CommandLineJobRunnerTests {
void testWithStdinParameters() throws Throwable {
String[] args = new String[] { jobPath, jobName };
System.setIn(new InputStream() {
char[] input = ("foo=bar\nspam=bucket").toCharArray();
final char[] input = ("foo=bar\nspam=bucket").toCharArray();
int index = 0;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2022 the original author or authors.
* Copyright 2022-2023 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.
@@ -39,17 +39,17 @@ import org.springframework.transaction.interceptor.TransactionInterceptor;
*/
class JobOperatorFactoryBeanTests {
private PlatformTransactionManager transactionManager = Mockito.mock(PlatformTransactionManager.class);
private final PlatformTransactionManager transactionManager = Mockito.mock(PlatformTransactionManager.class);
private JobRepository jobRepository = Mockito.mock(JobRepository.class);
private final JobRepository jobRepository = Mockito.mock(JobRepository.class);
private JobLauncher jobLauncher = Mockito.mock(JobLauncher.class);
private final JobLauncher jobLauncher = Mockito.mock(JobLauncher.class);
private JobRegistry jobRegistry = Mockito.mock(JobRegistry.class);
private final JobRegistry jobRegistry = Mockito.mock(JobRegistry.class);
private JobExplorer jobExplorer = Mockito.mock(JobExplorer.class);
private final JobExplorer jobExplorer = Mockito.mock(JobExplorer.class);
private JobParametersConverter jobParametersConverter = Mockito.mock(JobParametersConverter.class);
private final JobParametersConverter jobParametersConverter = Mockito.mock(JobParametersConverter.class);
@Test
public void testJobOperatorCreation() throws Exception {

View File

@@ -229,7 +229,7 @@ class ItemListenerErrorTests {
private boolean goingToFail = false;
private ItemReader<String> delegate = new ListItemReader<>(Collections.singletonList("1"));
private final ItemReader<String> delegate = new ListItemReader<>(Collections.singletonList("1"));
private int count = 0;

View File

@@ -550,7 +550,7 @@ class MulticasterBatchListenerTests {
private static final class AnnotationBasedStepListener {
private IllegalStateException exception = new IllegalStateException("listener error");
private final IllegalStateException exception = new IllegalStateException("listener error");
@BeforeRead
public void beforeRead() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2019 the original author or authors.
* Copyright 2008-2023 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 org.springframework.util.ClassUtils;
*/
public class ExampleItemReader extends AbstractItemStreamItemReader<String> {
private Log logger = LogFactory.getLog(getClass());
private final Log logger = LogFactory.getLog(getClass());
private String[] input = { "Hello", "world!", "Go", "on", "punk", "make", "my", "day!" };
private final String[] input = { "Hello", "world!", "Go", "on", "punk", "make", "my", "day!" };
private int index = 0;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 the original author or authors.
* Copyright 2008-2023 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.
@@ -31,7 +31,7 @@ public class ExampleItemWriter implements ItemWriter<String> {
private static final Log log = LogFactory.getLog(ExampleItemWriter.class);
private static List<String> items = new ArrayList<>();
private static final List<String> items = new ArrayList<>();
public static void clear() {
items.clear();

View File

@@ -44,7 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
*/
class PartitionStepTests {
private PartitionStep step = new PartitionStep();
private final PartitionStep step = new PartitionStep();
private JobRepository jobRepository;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2022 the original author or authors.
* Copyright 2009-2023 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.
@@ -101,7 +101,7 @@ class NonAbstractStepTests {
*/
private class EventTrackingListener implements StepExecutionListener {
private String name;
private final String name;
public EventTrackingListener(String name) {
this.name = name;

View File

@@ -260,7 +260,7 @@ class RegisterMultiListenerTests {
private static class MultiListener
implements StepExecutionListener, ChunkListener, ItemWriteListener<String>, SkipListener<String, String> {
private CallChecker callChecker;
private final CallChecker callChecker;
private MultiListener(CallChecker callChecker) {
super();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2019 the original author or authors.
* Copyright 2006-2023 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,15 +29,16 @@ import org.springframework.lang.Nullable;
/**
* @author Dan Garrette
* @author Mahmoud Ben Hassine
* @since 2.0.2
*/
public class ExceptionThrowingTaskletStub implements Tasklet {
private int maxTries = 4;
private final int maxTries = 4;
protected Log logger = LogFactory.getLog(getClass());
private List<Integer> committed = TransactionAwareProxyFactory.createTransactionalList();
private final List<Integer> committed = TransactionAwareProxyFactory.createTransactionalList();
private Constructor<? extends Exception> exception;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 the original author or authors.
* Copyright 2008-2023 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.
@@ -126,7 +126,7 @@ class FaultTolerantStepFactoryBeanNonBufferingTests {
protected final Log logger = LogFactory.getLog(getClass());
// simulate transactional output
private List<Object> written = TransactionAwareProxyFactory.createTransactionalList();
private final List<Object> written = TransactionAwareProxyFactory.createTransactionalList();
private final Collection<String> failures;

View File

@@ -73,13 +73,13 @@ class FaultTolerantStepFactoryBeanRetryTests {
private FaultTolerantStepFactoryBean<String, String> factory;
private List<Object> recovered = new ArrayList<>();
private final List<Object> recovered = new ArrayList<>();
private List<Object> processed = new ArrayList<>();
private final List<Object> processed = new ArrayList<>();
private List<Object> provided = new ArrayList<>();
private final List<Object> provided = new ArrayList<>();
private List<Object> written = TransactionAwareProxyFactory.createTransactionalList();
private final List<Object> written = TransactionAwareProxyFactory.createTransactionalList();
int count = 0;
@@ -89,7 +89,7 @@ class FaultTolerantStepFactoryBeanRetryTests {
JobExecution jobExecution;
private ItemWriter<String> writer = data -> processed.addAll(data.getItems());
private final ItemWriter<String> writer = data -> processed.addAll(data.getItems());
@SuppressWarnings("unchecked")
@BeforeEach

View File

@@ -278,7 +278,7 @@ class SimpleStepFactoryBeanTests {
int failedCount = 0;
private AssertingWriteListener writeListener;
private final AssertingWriteListener writeListener;
public CountingChunkListener(AssertingWriteListener writeListener) {
super();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2019 the original author or authors.
* Copyright 2006-2023 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.
@@ -24,13 +24,14 @@ import org.springframework.lang.Nullable;
/**
* @author Dan Garrette
* @author Mahmoud Ben Hassine
* @since 2.0.1
*/
public class SkipProcessorStub<T> extends AbstractExceptionThrowingItemHandlerStub<T> implements ItemProcessor<T, T> {
private List<T> processed = new ArrayList<>();
private final List<T> processed = new ArrayList<>();
private List<T> committed = TransactionAwareProxyFactory.createTransactionalList();
private final List<T> committed = TransactionAwareProxyFactory.createTransactionalList();
private boolean filter = false;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2019 the original author or authors.
* Copyright 2006-2023 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,13 +26,14 @@ import org.springframework.util.Assert;
/**
* @author Dan Garrette
* @author Mahmoud Ben Hassine
* @since 2.0.1
*/
public class SkipReaderStub<T> extends AbstractExceptionThrowingItemHandlerStub<T> implements ItemReader<T> {
private T[] items;
private List<T> read = new ArrayList<>();
private final List<T> read = new ArrayList<>();
private int counter = -1;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 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 org.springframework.batch.support.transaction.TransactionAwareProxyFactor
*/
public class SkipWriterStub<T> extends AbstractExceptionThrowingItemHandlerStub<T> implements ItemWriter<T> {
private List<T> written = new ArrayList<>();
private final List<T> written = new ArrayList<>();
private List<T> committed = TransactionAwareProxyFactory.createTransactionalList();
private final List<T> committed = TransactionAwareProxyFactory.createTransactionalList();
public SkipWriterStub() throws Exception {
super();

View File

@@ -934,7 +934,7 @@ class TaskletStepTests {
private boolean getExecutionAttributesCalled = false;
private boolean restoreFromCalled = false;
private final boolean restoreFromCalled = false;
@Nullable
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2019 the original author or authors.
* Copyright 2006-2023 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.
@@ -40,7 +40,7 @@ import org.springframework.util.ClassUtils;
*/
public class JobSupport implements BeanNameAware, Job {
private List<Step> steps = new ArrayList<>();
private final List<Step> steps = new ArrayList<>();
private String name;

View File

@@ -199,11 +199,11 @@ class FaultTolerantStepFactoryBeanIntegrationTests {
private static class SkipWriterStub implements ItemWriter<String> {
private List<String> written = new ArrayList<>();
private final List<String> written = new ArrayList<>();
private Collection<String> failures = Collections.emptySet();
private final Collection<String> failures = Collections.emptySet();
private JdbcTemplate jdbcTemplate;
private final JdbcTemplate jdbcTemplate;
public SkipWriterStub(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
@@ -240,9 +240,9 @@ class FaultTolerantStepFactoryBeanIntegrationTests {
private final Log logger = LogFactory.getLog(getClass());
private List<String> processed = new ArrayList<>();
private final List<String> processed = new ArrayList<>();
private JdbcTemplate jdbcTemplate;
private final JdbcTemplate jdbcTemplate;
/**
* @param dataSource

View File

@@ -221,11 +221,11 @@ class FaultTolerantStepFactoryBeanRollbackIntegrationTests {
private static class SkipWriterStub implements ItemWriter<String> {
private List<String> written = new CopyOnWriteArrayList<>();
private final List<String> written = new CopyOnWriteArrayList<>();
private Collection<String> failures = Collections.emptySet();
private JdbcTemplate jdbcTemplate;
private final JdbcTemplate jdbcTemplate;
public SkipWriterStub(DataSource dataSource) {
jdbcTemplate = new JdbcTemplate(dataSource);
@@ -266,9 +266,9 @@ class FaultTolerantStepFactoryBeanRollbackIntegrationTests {
private final Log logger = LogFactory.getLog(getClass());
private List<String> processed = new CopyOnWriteArrayList<>();
private final List<String> processed = new CopyOnWriteArrayList<>();
private JdbcTemplate jdbcTemplate;
private final JdbcTemplate jdbcTemplate;
/**
* @param dataSource