Use consistent exception messages in Assert calls

Update `Assert` calls to consistently use messages of the form
"'item' must [not] ...".

Closes gh-43780
This commit is contained in:
Phillip Webb
2025-01-09 15:33:44 -08:00
parent f08188d5cf
commit a49719d73e
559 changed files with 2001 additions and 2003 deletions

View File

@@ -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.
@@ -37,13 +37,13 @@ class AnnotatedClassFinderTests {
@Test
void findFromClassWhenSourceIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.finder.findFromClass((Class<?>) null))
.withMessageContaining("Source must not be null");
.withMessageContaining("'source' must not be null");
}
@Test
void findFromPackageWhenSourceIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> this.finder.findFromPackage((String) null))
.withMessageContaining("Source must not be null");
.withMessageContaining("'source' must not be null");
}
@Test

View File

@@ -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.
@@ -64,14 +64,14 @@ class ApplicationContextAssertProviderTests {
void getWhenTypeIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(
() -> ApplicationContextAssertProvider.get(null, ApplicationContext.class, this.mockContextSupplier))
.withMessageContaining("Type must not be null");
.withMessageContaining("'type' must not be null");
}
@Test
void getWhenTypeIsClassShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(
() -> ApplicationContextAssertProvider.get(null, ApplicationContext.class, this.mockContextSupplier))
.withMessageContaining("Type must not be null");
.withMessageContaining("'type' must not be null");
}
@Test
@@ -79,7 +79,7 @@ class ApplicationContextAssertProviderTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContextClass.class,
ApplicationContext.class, this.mockContextSupplier))
.withMessageContaining("Type must be an interface");
.withMessageContaining("'type' must be an interface");
}
@Test
@@ -87,7 +87,7 @@ class ApplicationContextAssertProviderTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class, null,
this.mockContextSupplier))
.withMessageContaining("ContextType must not be null");
.withMessageContaining("'contextType' must not be null");
}
@Test
@@ -95,7 +95,7 @@ class ApplicationContextAssertProviderTests {
assertThatIllegalArgumentException()
.isThrownBy(() -> ApplicationContextAssertProvider.get(TestAssertProviderApplicationContext.class,
StaticApplicationContext.class, this.mockContextSupplier))
.withMessageContaining("ContextType must be an interface");
.withMessageContaining("'contextType' must be an interface");
}
@Test

View File

@@ -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.
@@ -62,7 +62,7 @@ class ApplicationContextAssertTests {
@Test
void createWhenApplicationContextIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new ApplicationContextAssert<>(null, null))
.withMessageContaining("ApplicationContext must not be null");
.withMessageContaining("'applicationContext' must not be null");
}
@Test

View File

@@ -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.
@@ -70,7 +70,7 @@ class ContextConsumerTests {
ContextConsumer<?> consumer = (context) -> {
};
assertThatIllegalArgumentException().isThrownBy(() -> consumer.andThen(null))
.withMessage("After must not be null");
.withMessage("'after' must not be null");
}
}

View File

@@ -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.
@@ -93,13 +93,13 @@ abstract class AbstractJsonMarshalTesterTests {
void createWhenResourceLoadClassIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> createTester(null, ResolvableType.forClass(ExampleObject.class)))
.withMessageContaining("ResourceLoadClass must not be null");
.withMessageContaining("'resourceLoadClass' must not be null");
}
@Test
void createWhenTypeIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> createTester(getClass(), null))
.withMessageContaining("Type must not be null");
.withMessageContaining("'type' must not be null");
}
@Test

View File

@@ -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.
@@ -45,7 +45,7 @@ class BasicJsonTesterTests {
@Test
void createWhenResourceLoadClassIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new BasicJsonTester(null))
.withMessageContaining("ResourceLoadClass must not be null");
.withMessageContaining("'resourceLoadClass' must not be null");
}
@Test

View File

@@ -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.
@@ -37,14 +37,14 @@ class GsonTesterTests extends AbstractJsonMarshalTesterTests {
@Test
void initFieldsWhenTestIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> GsonTester.initFields(null, new GsonBuilder().create()))
.withMessageContaining("TestInstance must not be null");
.withMessageContaining("'testInstance' must not be null");
}
@Test
void initFieldsWhenMarshallerIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> GsonTester.initFields(new InitFieldsTestClass(), (Gson) null))
.withMessageContaining("Marshaller must not be null");
.withMessageContaining("'marshaller' must not be null");
}
@Test

View File

@@ -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.
@@ -36,14 +36,14 @@ class JacksonTesterTests extends AbstractJsonMarshalTesterTests {
@Test
void initFieldsWhenTestIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> JacksonTester.initFields(null, new ObjectMapper()))
.withMessageContaining("TestInstance must not be null");
.withMessageContaining("'testInstance' must not be null");
}
@Test
void initFieldsWhenMarshallerIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> JacksonTester.initFields(new InitFieldsTestClass(), (ObjectMapper) null))
.withMessageContaining("Marshaller must not be null");
.withMessageContaining("'marshaller' must not be null");
}
@Test

View File

@@ -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.
@@ -39,7 +39,7 @@ class JsonContentTests {
void createWhenResourceLoadClassIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new JsonContent<ExampleObject>(null, TYPE, JSON, Configuration.defaultConfiguration()))
.withMessageContaining("ResourceLoadClass must not be null");
.withMessageContaining("'resourceLoadClass' must not be null");
}
@Test
@@ -47,14 +47,14 @@ class JsonContentTests {
assertThatIllegalArgumentException()
.isThrownBy(
() -> new JsonContent<ExampleObject>(getClass(), TYPE, null, Configuration.defaultConfiguration()))
.withMessageContaining("JSON must not be null");
.withMessageContaining("'json' must not be null");
}
@Test
void createWhenConfigurationIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new JsonContent<ExampleObject>(getClass(), TYPE, JSON, null))
.withMessageContaining("Configuration must not be null");
.withMessageContaining("'configuration' must not be null");
}
@Test

View File

@@ -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.
@@ -37,14 +37,14 @@ class JsonbTesterTests extends AbstractJsonMarshalTesterTests {
@Test
void initFieldsWhenTestIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> JsonbTester.initFields(null, JsonbBuilder.create()))
.withMessageContaining("TestInstance must not be null");
.withMessageContaining("'testInstance' must not be null");
}
@Test
void initFieldsWhenMarshallerIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> JsonbTester.initFields(new InitFieldsTestClass(), (Jsonb) null))
.withMessageContaining("Marshaller must not be null");
.withMessageContaining("'marshaller' must not be null");
}
@Test

View File

@@ -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.
@@ -37,7 +37,7 @@ class ObjectContentTests {
@Test
void createWhenObjectIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new ObjectContent<ExampleObject>(TYPE, null))
.withMessageContaining("Object must not be null");
.withMessageContaining("'object' must not be null");
}
@Test

View File

@@ -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.
@@ -45,7 +45,7 @@ class MockDefinitionTests {
void classToMockMustNotBeNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new MockDefinition(null, null, null, null, false, null, null))
.withMessageContaining("TypeToMock must not be null");
.withMessageContaining("'typeToMock' must not be null");
}
@Test

View File

@@ -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.
@@ -45,7 +45,7 @@ class SpyDefinitionTests {
@Test
void classToSpyMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> new SpyDefinition(null, null, null, true, null))
.withMessageContaining("TypeToSpy must not be null");
.withMessageContaining("'typeToSpy' must not be null");
}
@Test
@@ -84,7 +84,7 @@ class SpyDefinitionTests {
void createSpyWhenNullInstanceShouldThrowException() {
SpyDefinition definition = new SpyDefinition("name", REAL_SERVICE_TYPE, MockReset.BEFORE, true, null);
assertThatIllegalArgumentException().isThrownBy(() -> definition.createSpy(null))
.withMessageContaining("Instance must not be null");
.withMessageContaining("'instance' must not be null");
}
@Test

View File

@@ -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.
@@ -43,21 +43,21 @@ class LocalHostUriTemplateHandlerTests {
@Test
void createWhenEnvironmentIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new LocalHostUriTemplateHandler(null))
.withMessageContaining("Environment must not be null");
.withMessageContaining("'environment' must not be null");
}
@Test
void createWhenSchemeIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new LocalHostUriTemplateHandler(new MockEnvironment(), null))
.withMessageContaining("Scheme must not be null");
.withMessageContaining("'scheme' must not be null");
}
@Test
void createWhenHandlerIsNullShouldThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new LocalHostUriTemplateHandler(new MockEnvironment(), "http", null))
.withMessageContaining("Handler must not be null");
.withMessageContaining("'handler' must not be null");
}
@Test

View File

@@ -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.
@@ -59,7 +59,7 @@ class MockServerRestClientCustomizerTests {
void createWhenExpectationManagerClassIsNullShouldThrowException() {
Class<? extends RequestExpectationManager> expectationManager = null;
assertThatIllegalArgumentException().isThrownBy(() -> new MockServerRestClientCustomizer(expectationManager))
.withMessageContaining("ExpectationManager must not be null");
.withMessageContaining("'expectationManager' must not be null");
}
@Test
@@ -67,7 +67,7 @@ class MockServerRestClientCustomizerTests {
Supplier<? extends RequestExpectationManager> expectationManagerSupplier = null;
assertThatIllegalArgumentException()
.isThrownBy(() -> new MockServerRestClientCustomizer(expectationManagerSupplier))
.withMessageContaining("ExpectationManagerSupplier must not be null");
.withMessageContaining("'expectationManagerSupplier' must not be null");
}
@Test

View File

@@ -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.
@@ -62,7 +62,7 @@ class MockServerRestTemplateCustomizerTests {
void createWhenExpectationManagerClassIsNullShouldThrowException() {
Class<? extends RequestExpectationManager> expectationManager = null;
assertThatIllegalArgumentException().isThrownBy(() -> new MockServerRestTemplateCustomizer(expectationManager))
.withMessageContaining("ExpectationManager must not be null");
.withMessageContaining("'expectationManager' must not be null");
}
@Test
@@ -70,7 +70,7 @@ class MockServerRestTemplateCustomizerTests {
Supplier<? extends RequestExpectationManager> expectationManagerSupplier = null;
assertThatIllegalArgumentException()
.isThrownBy(() -> new MockServerRestTemplateCustomizer(expectationManagerSupplier))
.withMessageContaining("ExpectationManagerSupplier must not be null");
.withMessageContaining("'expectationManagerSupplier' must not be null");
}
@Test

View File

@@ -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.
@@ -67,13 +67,13 @@ class RootUriRequestExpectationManagerTests {
@Test
void createWhenRootUriIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new RootUriRequestExpectationManager(null, this.delegate))
.withMessageContaining("RootUri must not be null");
.withMessageContaining("'rootUri' must not be null");
}
@Test
void createWhenExpectationManagerIsNullShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new RootUriRequestExpectationManager(this.uri, null))
.withMessageContaining("ExpectationManager must not be null");
.withMessageContaining("'expectationManager' must not be null");
}
@Test

View File

@@ -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.
@@ -49,7 +49,7 @@ class LocalHostWebClientTests {
@Test
void createWhenEnvironmentIsNullWillThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new LocalHostWebClient(null))
.withMessageContaining("Environment must not be null");
.withMessageContaining("'environment' must not be null");
}
@Test

View File

@@ -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.
@@ -64,20 +64,20 @@ class LocalHostWebConnectionHtmlUnitDriverTests {
@Test
void createWhenEnvironmentIsNullWillThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new LocalHostWebConnectionHtmlUnitDriver(null))
.withMessageContaining("Environment must not be null");
.withMessageContaining("'environment' must not be null");
}
@Test
void createWithJavascriptFlagWhenEnvironmentIsNullWillThrowException() {
assertThatIllegalArgumentException().isThrownBy(() -> new LocalHostWebConnectionHtmlUnitDriver(null, true))
.withMessageContaining("Environment must not be null");
.withMessageContaining("'environment' must not be null");
}
@Test
void createWithBrowserVersionWhenEnvironmentIsNullWillThrowException() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new LocalHostWebConnectionHtmlUnitDriver(null, BrowserVersion.CHROME))
.withMessageContaining("Environment must not be null");
.withMessageContaining("'environment' must not be null");
}
@Test
@@ -87,7 +87,7 @@ class LocalHostWebConnectionHtmlUnitDriverTests {
given(capabilities.getBrowserVersion()).willReturn("chrome");
assertThatIllegalArgumentException()
.isThrownBy(() -> new LocalHostWebConnectionHtmlUnitDriver(null, capabilities))
.withMessageContaining("Environment must not be null");
.withMessageContaining("'environment' must not be null");
}
@Test