DATACMNS-1755 - Use specialized assertThat*Exception.
When possible replace `assertThatExceptionOfType` calls with the equivalent specialized variant. Original pull request: #448.
This commit is contained in:
committed by
Mark Paluch
parent
86bda64daa
commit
5734cfe878
@@ -96,7 +96,7 @@ class DefaultAuditableBeanWrapperFactoryUnitTests {
|
||||
|
||||
assertThat(wrapper).isNotEmpty();
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> wrapper.ifPresent(it -> it.setLastModifiedDate(zonedDateTime)));
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ class AuditingBeanDefinitionRegistrarSupportUnitTests {
|
||||
|
||||
AuditingBeanDefinitionRegistrarSupport registrar = new DummyAuditingBeanDefinitionRegistrarSupport();
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> registrar.registerBeanDefinitions(null, registry));
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class AuditingBeanDefinitionRegistrarSupportUnitTests {
|
||||
AuditingBeanDefinitionRegistrarSupport registrar = new DummyAuditingBeanDefinitionRegistrarSupport();
|
||||
AnnotationMetadata metadata = new StandardAnnotationMetadata(SampleConfig.class);
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> registrar.registerBeanDefinitions(metadata, null));
|
||||
}
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ class AbstractAggregateRootUnitTests {
|
||||
@SuppressWarnings("null")
|
||||
void rejectsNullEvent() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new SampleAggregate().andEvent(null));
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ class AbstractAggregateRootUnitTests {
|
||||
@SuppressWarnings("null")
|
||||
void rejectsNullEventForRegistration() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new SampleAggregate().registerEvent(null));
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class AbstractAggregateRootUnitTests {
|
||||
@SuppressWarnings("null")
|
||||
void rejectsNullAggregate() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new SampleAggregate().andEventsFrom(null));
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class PageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
@Test // DATACMNS-1581
|
||||
void rejectsNullSort() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> PageRequest.of(0, 10, null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ class SortUnitTests {
|
||||
@SuppressWarnings("null")
|
||||
void preventsNullDirection() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)//
|
||||
assertThatIllegalArgumentException()//
|
||||
.isThrownBy(() -> Sort.by((Direction) null, "foo"))//
|
||||
.withMessageContaining("Direction");
|
||||
}
|
||||
|
||||
@@ -46,10 +46,10 @@ class AnnotationRevisionMetadataUnitTests {
|
||||
|
||||
assertThat(metadata.getRevisionNumber()).isEmpty();
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class) //
|
||||
assertThatIllegalStateException() //
|
||||
.isThrownBy(metadata::getRequiredRevisionNumber);
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class) //
|
||||
assertThatIllegalStateException() //
|
||||
.isThrownBy(metadata::getRequiredRevisionInstant);
|
||||
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ public class PersistentPropertyAccessorUnitTests {
|
||||
|
||||
setUp(new Order(null), "");
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> accessor.setProperty(path, "Oliver August"));
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class PersistentPropertyAccessorUnitTests {
|
||||
|
||||
TraversalContext traversal = new TraversalContext();
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> traversal.registerHandler(property, Map.class, Function.identity()));
|
||||
}
|
||||
|
||||
|
||||
@@ -374,7 +374,7 @@ public class PropertyPathUnitTests {
|
||||
|
||||
final String path = source;
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> PropertyPath.from(path, Left.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class TargetAwareIdentifierAccessorUnitTests {
|
||||
}
|
||||
};
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class)//
|
||||
assertThatIllegalStateException()//
|
||||
.isThrownBy(accessor::getRequiredIdentifier)//
|
||||
.withMessageContaining(sample.toString());
|
||||
}
|
||||
|
||||
@@ -95,7 +95,7 @@ class DefaultEntityCallbacksUnitTests {
|
||||
DefaultEntityCallbacks callbacks = new DefaultEntityCallbacks();
|
||||
callbacks.addEntityCallback(new InvalidEntityCallback() {});
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class)
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> callbacks.callback(InvalidEntityCallback.class, new PersonDocument(null, "Walter", null),
|
||||
"agr0", Float.POSITIVE_INFINITY));
|
||||
}
|
||||
@@ -126,7 +126,7 @@ class DefaultEntityCallbacksUnitTests {
|
||||
DefaultEntityCallbacks callbacks = new DefaultEntityCallbacks();
|
||||
callbacks.addEntityCallback(new CapturingEntityCallback());
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> callbacks.callback(CapturingEntityCallback.class, null));
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ class DefaultEntityCallbacksUnitTests {
|
||||
|
||||
PersonDocument initial = new PersonDocument(null, "Walter", null);
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> callbacks.callback(CapturingEntityCallback.class, initial));
|
||||
|
||||
assertThat(first.capturedValue()).isSameAs(initial);
|
||||
|
||||
@@ -96,7 +96,7 @@ class DefaultReactiveEntityCallbacksUnitTests {
|
||||
DefaultReactiveEntityCallbacks callbacks = new DefaultReactiveEntityCallbacks();
|
||||
callbacks.addEntityCallback(new CapturingEntityCallback());
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> callbacks.callback(CapturingEntityCallback.class, null));
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ class PersistentEntitiesUnitTests {
|
||||
|
||||
PersistentEntities entities = PersistentEntities.of(context);
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class)//
|
||||
assertThatIllegalStateException()//
|
||||
.isThrownBy(() -> entities.getEntityUltimatelyReferredToBy(property)) //
|
||||
.withMessageContaining(FirstWithLongId.class.getName()) //
|
||||
.withMessageContaining(SecondWithLongId.class.getName()) //
|
||||
|
||||
@@ -254,7 +254,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "field");
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> property.getRequiredGetter()) //
|
||||
.withMessageContaining("field") //
|
||||
.withMessageContaining(Sample.class.getName());
|
||||
@@ -265,7 +265,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "field");
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> property.getRequiredSetter()) //
|
||||
.withMessageContaining("field") //
|
||||
.withMessageContaining(Sample.class.getName());
|
||||
@@ -276,7 +276,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
|
||||
SamplePersistentProperty property = getProperty(Sample.class, "field");
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> property.getRequiredWither()) //
|
||||
.withMessageContaining("field") //
|
||||
.withMessageContaining(Sample.class.getName());
|
||||
@@ -287,7 +287,7 @@ public class AnnotationBasedPersistentPropertyUnitTests<P extends AnnotationBase
|
||||
|
||||
SamplePersistentProperty property = getProperty(NoField.class, "firstname");
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> property.getRequiredField()) //
|
||||
.withMessageContaining("firstname") //
|
||||
.withMessageContaining(NoField.class.getName());
|
||||
|
||||
@@ -255,7 +255,7 @@ class BasicPersistentEntityUnitTests<T extends PersistentProperty<T>> {
|
||||
|
||||
MutablePersistentEntity<Entity, T> entity = createEntity(Entity.class);
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> entity.addAssociation(null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> entity.addAssociation(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1141
|
||||
|
||||
@@ -57,7 +57,7 @@ public class QPageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
@Test // DATACMNS-1581
|
||||
void rejectsNullSort() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> QPageRequest.of(0, 10, (QSort) null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class QuerydslBindingsFactoryUnitTests {
|
||||
@Test // DATACMNS-669
|
||||
void rejectsPredicateResolutionIfDomainTypeCantBeAutoDetected() {
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class)//
|
||||
assertThatIllegalStateException()//
|
||||
.isThrownBy(() -> factory.createBindingsFor(ClassTypeInformation.from(ModelAndView.class)))//
|
||||
.withMessageContaining(QuerydslPredicate.class.getSimpleName())//
|
||||
.withMessageContaining("root");
|
||||
|
||||
@@ -154,7 +154,7 @@ class AnnotationRepositoryConfigurationSourceUnitTests {
|
||||
|
||||
RepositoryConfigurationSource source = getConfigSource(DefaultConfiguration.class);
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> source.getAttribute("fooBar"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> source.getAttribute("fooBar"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1498
|
||||
@@ -163,7 +163,7 @@ class AnnotationRepositoryConfigurationSourceUnitTests {
|
||||
RepositoryConfigurationSource source = getConfigSource(DefaultConfiguration.class);
|
||||
|
||||
assertThat(source.getAttribute("namedQueriesLocation", String.class)).isEmpty();
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> source.getRequiredAttribute("namedQueriesLocation", String.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ class CustomRepositoryImplementationDetectorUnitTests {
|
||||
@Test // DATACMNS-764, DATACMNS-1371
|
||||
void throwsExceptionWhenMultipleImplementationAreFound() {
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
assertThatIllegalStateException().isThrownBy(() -> {
|
||||
|
||||
ImplementationLookupConfiguration lookup = mock(ImplementationLookupConfiguration.class);
|
||||
|
||||
|
||||
@@ -81,7 +81,7 @@ class AbstractEntityInformationUnitTests {
|
||||
CustomEntityInformation<UnsupportedPrimitiveIdEntity, ?> information = new CustomEntityInformation<UnsupportedPrimitiveIdEntity, Boolean>(
|
||||
UnsupportedPrimitiveIdEntity.class);
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)//
|
||||
assertThatIllegalArgumentException()//
|
||||
.isThrownBy(() -> information.isNew(new UnsupportedPrimitiveIdEntity()))//
|
||||
.withMessageContaining(boolean.class.getName());
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class AnnotationRepositoryMetadataUnitTests {
|
||||
@Test // DATACMNS-37, DATACMNS-1375
|
||||
void preventsUnannotatedInterface() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> new AnnotationRepositoryMetadata(UnannotatedRepository.class)) //
|
||||
.withMessageContaining(UnannotatedRepository.class.getName());
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ class RepositoryCompositionUnitTests {
|
||||
RepositoryComposition mixed = RepositoryComposition.of(RepositoryFragment.structural(QueryByExampleExecutor.class),
|
||||
RepositoryFragment.implemented(backingRepo));
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class) //
|
||||
assertThatIllegalStateException() //
|
||||
.isThrownBy(mixed::validateImplementation) //
|
||||
.withMessageContaining(
|
||||
"Fragment org.springframework.data.repository.query.QueryByExampleExecutor has no implementation.");
|
||||
|
||||
@@ -52,7 +52,7 @@ class RepositoryFactoryBeanSupportUnitTests {
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
void initializationFailsWithMissingRepositoryInterface() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class)//
|
||||
assertThatIllegalArgumentException()//
|
||||
.isThrownBy(() -> new DummyRepositoryFactoryBean(null))//
|
||||
.withMessageContaining("Repository interface");
|
||||
}
|
||||
@@ -83,7 +83,7 @@ class RepositoryFactoryBeanSupportUnitTests {
|
||||
|
||||
bean.afterPropertiesSet();
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class) //
|
||||
assertThatIllegalStateException() //
|
||||
.isThrownBy(() -> bean.getPersistentEntity());
|
||||
}
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ class ExtensionAwareEvaluationContextProviderUnitTests {
|
||||
|
||||
provider = createContextProviderWithOverloads();
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class) //
|
||||
assertThatIllegalStateException() //
|
||||
.isThrownBy(() -> evaluateExpression("ambiguousOverloaded(23)")) //
|
||||
.withMessageContaining("ambiguousOverloaded") //
|
||||
.withMessageContaining("(java.lang.Integer)");
|
||||
|
||||
@@ -103,7 +103,7 @@ class QuotationMapUnitTests {
|
||||
|
||||
@Test // DATAJPA-1235
|
||||
void openEndedQuoteThrowsException() {
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new QuotationMap("a'b"));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new QuotationMap("a'b"));
|
||||
}
|
||||
|
||||
private static void isNotQuoted(String query, Object label, int... indexes) {
|
||||
|
||||
@@ -45,7 +45,7 @@ class SpelExtractorUnitTests {
|
||||
|
||||
SpelQueryContext context = SpelQueryContext.of(PARAMETER_NAME_SOURCE, REPLACEMENT_SOURCE);
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> context.parse(null));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> context.parse(null));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1258
|
||||
|
||||
@@ -37,14 +37,14 @@ class SpelQueryContextUnitTests {
|
||||
@Test // DATACMNS-1258
|
||||
void nullParameterNameSourceThrowsException() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> SpelQueryContext.of(null, REPLACEMENT_SOURCE));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-1258
|
||||
void nullReplacementSourceThrowsException() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> SpelQueryContext.of(PARAMETER_NAME_SOURCE, null));
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class SpelQueryContextUnitTests {
|
||||
|
||||
SpelQueryContext context = SpelQueryContext.of(PARAMETER_NAME_SOURCE, REPLACEMENT_SOURCE);
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> context.withEvaluationContextProvider(null));
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ class LazyUnitTests {
|
||||
@Test
|
||||
void rejectsNullValueLookup() {
|
||||
|
||||
assertThatExceptionOfType(IllegalStateException.class) //
|
||||
assertThatIllegalStateException() //
|
||||
.isThrownBy(() -> Lazy.of(() -> null).get());
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ class MethodInvocationRecorderUnitTests {
|
||||
@Test // DATACMNS-1449
|
||||
void rejectsFinalTypes() {
|
||||
|
||||
assertThatExceptionOfType(IllegalArgumentException.class) //
|
||||
assertThatIllegalArgumentException() //
|
||||
.isThrownBy(() -> MethodInvocationRecorder.forProxyOf(FinalType.class));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user