Throw IllegalStateException from afterPropertiesSet

Consistently use Assert.state in the afterPropertiesSet()
methods to throw IllegalStateException instead of
IllegalArgumentException when some properties are missing
and/or invalid.

Resolves #2244
This commit is contained in:
Danilo Piazzalunga
2022-02-07 08:17:38 +01:00
committed by Mahmoud Ben Hassine
parent b9d6e26d61
commit fc0ec01ff8
96 changed files with 188 additions and 178 deletions

View File

@@ -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.
@@ -39,7 +39,7 @@ public class StagingItemListener extends StepListenerSupport<Long, Long> impleme
@Override
public final void afterPropertiesSet() throws Exception {
Assert.notNull(jdbcTemplate, "You must provide a DataSource.");
Assert.state(jdbcTemplate != null, "You must provide a DataSource.");
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 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.
@@ -49,7 +49,7 @@ public class StagingItemProcessor<T> implements ItemProcessor<ProcessIndicatorIt
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(jdbcTemplate, "Either jdbcTemplate or dataSource must be set");
Assert.state(jdbcTemplate != null, "Either jdbcTemplate or dataSource must be set");
}
/**

View File

@@ -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.
@@ -72,7 +72,7 @@ public class StagingItemReader<T>
@Override
public final void afterPropertiesSet() throws Exception {
Assert.notNull(jdbcTemplate, "You must provide a DataSource.");
Assert.state(jdbcTemplate != null, "You must provide a DataSource.");
}
private List<Long> retrieveKeys() {

View File

@@ -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.
@@ -68,7 +68,7 @@ public class AggregateItemFieldSetMapper<T> implements FieldSetMapper<AggregateI
*/
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(delegate, "A FieldSetMapper delegate must be provided.");
Assert.state(delegate != null, "A FieldSetMapper delegate must be provided.");
}
/**

View File

@@ -68,7 +68,7 @@ public class HibernateAwareCustomerCreditItemWriter implements ItemWriter<Custom
@Override
public void afterPropertiesSet() throws Exception {
Assert.state(sessionFactory != null, "Hibernate SessionFactory is required");
Assert.notNull(dao, "Delegate DAO must be set");
Assert.state(dao != null, "Delegate DAO must be set");
}
}

View File

@@ -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.
@@ -47,7 +47,7 @@ public class GeneratingTradeResettingListener implements StepExecutionListener,
@Override
public void afterPropertiesSet() throws Exception {
Assert.notNull(this.reader, "The 'reader' must be set.");
Assert.state(this.reader != null, "The 'reader' must be set.");
}
}

View File

@@ -52,7 +52,7 @@ class AggregateItemFieldSetMapperTests {
@Test
void testMandatoryProperties() {
assertThrows(IllegalArgumentException.class, mapper::afterPropertiesSet);
assertThrows(IllegalStateException.class, mapper::afterPropertiesSet);
}
@Test