Skip to content

Commit

Permalink
Use consistent exception messages in Assert calls
Browse files Browse the repository at this point in the history
Update `Assert` calls to consistently use messages of the form
"'item' must [not] ...".

Closes gh-43780
  • Loading branch information
philwebb committed Jan 12, 2025
1 parent f08188d commit a49719d
Show file tree
Hide file tree
Showing 559 changed files with 2,001 additions and 2,003 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -48,7 +48,7 @@ class AvailabilityProbesHealthEndpointGroups implements HealthEndpointGroups {
private static final String READINESS = "readiness";

AvailabilityProbesHealthEndpointGroups(HealthEndpointGroups groups, boolean addAdditionalPaths) {
Assert.notNull(groups, "Groups must not be null");
Assert.notNull(groups, "'groups' must not be null");
this.groups = groups;
this.probeGroups = createProbeGroups(addAdditionalPaths);
Set<String> names = new LinkedHashSet<>(groups.getNames());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -37,7 +37,7 @@ class DelegatingAvailabilityProbesHealthEndpointGroup implements HealthEndpointG

DelegatingAvailabilityProbesHealthEndpointGroup(HealthEndpointGroup delegate,
AdditionalHealthEndpointPath additionalPath) {
Assert.notNull(delegate, "Delegate must not be null");
Assert.notNull(delegate, "'delegate' must not be null");
this.delegate = delegate;
this.additionalPath = additionalPath;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -56,8 +56,8 @@ class ReactiveCloudFoundrySecurityService {

ReactiveCloudFoundrySecurityService(WebClient.Builder webClientBuilder, String cloudControllerUrl,
boolean skipSslValidation) {
Assert.notNull(webClientBuilder, "WebClient must not be null");
Assert.notNull(cloudControllerUrl, "CloudControllerUrl must not be null");
Assert.notNull(webClientBuilder, "'webClientBuilder' must not be null");
Assert.notNull(cloudControllerUrl, "'cloudControllerUrl' must not be null");
if (skipSslValidation) {
webClientBuilder.clientConnector(buildTrustAllSslConnector());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -49,8 +49,8 @@ class CloudFoundrySecurityService {

CloudFoundrySecurityService(RestTemplateBuilder restTemplateBuilder, String cloudControllerUrl,
boolean skipSslValidation) {
Assert.notNull(restTemplateBuilder, "RestTemplateBuilder must not be null");
Assert.notNull(cloudControllerUrl, "CloudControllerUrl must not be null");
Assert.notNull(restTemplateBuilder, "'restTemplateBuilder' must not be null");
Assert.notNull(cloudControllerUrl, "'cloudControllerUrl' must not be null");
if (skipSslValidation) {
restTemplateBuilder = restTemplateBuilder.requestFactory(SkipSslVerificationHttpRequestFactory.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -80,10 +80,10 @@ public IncludeExcludeEndpointFilter(Class<E> endpointType, Collection<String> in

private IncludeExcludeEndpointFilter(Class<E> endpointType, Environment environment, String prefix,
EndpointPatterns defaultIncludes) {
Assert.notNull(endpointType, "EndpointType must not be null");
Assert.notNull(environment, "Environment must not be null");
Assert.hasText(prefix, "Prefix must not be empty");
Assert.notNull(defaultIncludes, "DefaultIncludes must not be null");
Assert.notNull(endpointType, "'endpointType' must not be null");
Assert.notNull(environment, "'environment' must not be null");
Assert.hasText(prefix, "'prefix' must not be empty");
Assert.notNull(defaultIncludes, "'defaultIncludes' must not be null");
Binder binder = Binder.get(environment);
this.endpointType = endpointType;
this.include = new EndpointPatterns(bind(binder, prefix + ".include"));
Expand All @@ -93,8 +93,8 @@ private IncludeExcludeEndpointFilter(Class<E> endpointType, Environment environm

private IncludeExcludeEndpointFilter(Class<E> endpointType, Collection<String> include, Collection<String> exclude,
EndpointPatterns defaultIncludes) {
Assert.notNull(endpointType, "EndpointType Type must not be null");
Assert.notNull(defaultIncludes, "DefaultIncludes must not be null");
Assert.notNull(endpointType, "'endpointType' Type must not be null");
Assert.notNull(defaultIncludes, "'defaultIncludes' must not be null");
this.endpointType = endpointType;
this.include = new EndpointPatterns(include);
this.defaultIncludes = defaultIncludes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -62,7 +62,7 @@ public String getBasePath() {
}

public void setBasePath(String basePath) {
Assert.isTrue(basePath.isEmpty() || basePath.startsWith("/"), "Base path must start with '/' or be empty");
Assert.isTrue(basePath.isEmpty() || basePath.startsWith("/"), "'basePath' must start with '/' or be empty");
this.basePath = cleanBasePath(basePath);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -47,7 +47,7 @@ protected AbstractCompositeHealthContributorConfiguration(Function<B, I> indicat
}

protected final C createContributor(Map<String, B> beans) {
Assert.notEmpty(beans, "Beans must not be empty");
Assert.notEmpty(beans, "'beans' must not be empty");
if (beans.size() == 1) {
return createIndicator(beans.values().iterator().next());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -97,7 +97,7 @@ public HealthContributor dbHealthContributor(Map<String, DataSource> dataSources
}

private HealthContributor createContributor(Map<String, DataSource> beans) {
Assert.notEmpty(beans, "Beans must not be empty");
Assert.notEmpty(beans, "'beans' must not be empty");
if (beans.size() == 1) {
return createContributor(beans.values().iterator().next());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -43,7 +43,7 @@ public final class OnlyOnceLoggingDenyMeterFilter implements MeterFilter {
private final Supplier<String> message;

public OnlyOnceLoggingDenyMeterFilter(Supplier<String> message) {
Assert.notNull(message, "Message must not be null");
Assert.notNull(message, "'message' must not be null");
this.message = message;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -51,7 +51,7 @@ public class PropertiesMeterFilter implements MeterFilter {
private final MeterFilter mapFilter;

public PropertiesMeterFilter(MetricsProperties properties) {
Assert.notNull(properties, "Properties must not be null");
Assert.notNull(properties, "'properties' must not be null");
this.properties = properties;
this.mapFilter = createMapFilter(properties.getTags());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -38,7 +38,7 @@ public class PropertiesConfigAdapter<T> {
* @param properties the source properties
*/
public PropertiesConfigAdapter(T properties) {
Assert.notNull(properties, "Properties must not be null");
Assert.notNull(properties, "'properties' must not be null");
this.properties = properties;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -56,7 +56,7 @@ public DataSize getThreshold() {
}

public void setThreshold(DataSize threshold) {
Assert.isTrue(!threshold.isNegative(), "threshold must be greater than or equal to 0");
Assert.isTrue(!threshold.isNegative(), "'threshold' must be greater than or equal to 0");
this.threshold = threshold;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -37,7 +37,7 @@ class LocalBaggageFields {
private final List<String> fields;

LocalBaggageFields(List<String> fields) {
Assert.notNull(fields, "fields must not be null");
Assert.notNull(fields, "'fields' must not be null");
this.fields = fields;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -68,7 +68,7 @@ static SpanExporters of(SpanExporter... spanExporters) {
* @return the constructed {@link SpanExporters} instance
*/
static SpanExporters of(Collection<? extends SpanExporter> spanExporters) {
Assert.notNull(spanExporters, "SpanExporters must not be null");
Assert.notNull(spanExporters, "'spanExporters' must not be null");
List<SpanExporter> copy = List.copyOf(spanExporters);
return () -> copy;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -68,7 +68,7 @@ static SpanProcessors of(SpanProcessor... spanProcessors) {
* @return the constructed {@link SpanProcessors} instance
*/
static SpanProcessors of(Collection<? extends SpanProcessor> spanProcessors) {
Assert.notNull(spanProcessors, "SpanProcessors must not be null");
Assert.notNull(spanProcessors, "'spanProcessors' must not be null");
List<SpanProcessor> copy = List.copyOf(spanProcessors);
return () -> copy;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2024 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -47,8 +47,8 @@ public class ManagementErrorEndpoint {
private final ErrorProperties errorProperties;

public ManagementErrorEndpoint(ErrorAttributes errorAttributes, ErrorProperties errorProperties) {
Assert.notNull(errorAttributes, "ErrorAttributes must not be null");
Assert.notNull(errorProperties, "ErrorProperties must not be null");
Assert.notNull(errorAttributes, "'errorAttributes' must not be null");
Assert.notNull(errorProperties, "'errorProperties' must not be null");
this.errorAttributes = errorAttributes;
this.errorProperties = errorProperties;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -52,7 +52,7 @@ void setup() {
@Test
void createWhenGroupsIsNullThrowsException() {
assertThatIllegalArgumentException().isThrownBy(() -> new AvailabilityProbesHealthEndpointGroups(null, false))
.withMessage("Groups must not be null");
.withMessage("'groups' must not be null");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -45,28 +45,28 @@ class IncludeExcludeEndpointFilterTests {
void createWhenEndpointTypeIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new IncludeExcludeEndpointFilter<>(null, new MockEnvironment(), "foo"))
.withMessageContaining("EndpointType must not be null");
.withMessageContaining("'endpointType' must not be null");
}

@Test
void createWhenEnvironmentIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new IncludeExcludeEndpointFilter<>(ExposableEndpoint.class, null, "foo"))
.withMessageContaining("Environment must not be null");
.withMessageContaining("'environment' must not be null");
}

@Test
void createWhenPrefixIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new IncludeExcludeEndpointFilter<>(ExposableEndpoint.class, new MockEnvironment(), null))
.withMessageContaining("Prefix must not be empty");
.withMessageContaining("'prefix' must not be empty");
}

@Test
void createWhenPrefixIsEmptyShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new IncludeExcludeEndpointFilter<>(ExposableEndpoint.class, new MockEnvironment(), ""))
.withMessageContaining("Prefix must not be empty");
.withMessageContaining("'prefix' must not be empty");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -47,7 +47,7 @@ void basePathShouldBeCleaned() {
void basePathMustStartWithSlash() {
WebEndpointProperties properties = new WebEndpointProperties();
assertThatIllegalArgumentException().isThrownBy(() -> properties.setBasePath("admin"))
.withMessageContaining("Base path must start with '/' or be empty");
.withMessageContaining("'basePath' must start with '/' or be empty");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -49,7 +49,7 @@ abstract class AbstractCompositeHealthContributorConfigurationTests<C, I extends
void createContributorWhenBeansIsEmptyThrowsException() {
Map<String, TestBean> beans = Collections.emptyMap();
assertThatIllegalArgumentException().isThrownBy(() -> newComposite().createContributor(beans))
.withMessage("Beans must not be empty");
.withMessage("'beans' must not be empty");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -48,7 +48,7 @@ class PropertiesMeterFilterTests {
@Test
void createWhenPropertiesIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new PropertiesMeterFilter(null))
.withMessageContaining("Properties must not be null");
.withMessageContaining("'properties' must not be null");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2025 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.
Expand Down Expand Up @@ -49,7 +49,7 @@ void thresholdMustBePositive() {
.run((context) -> assertThat(context).hasFailed()
.getFailure()
.rootCause()
.hasMessage("threshold must be greater than or equal to 0"));
.hasMessage("'threshold' must be greater than or equal to 0"));
}

@Test
Expand Down
Loading

0 comments on commit a49719d

Please sign in to comment.