From 6a6abac0030e4798d154b6be92a7aa3dacc6ac47 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Mon, 26 May 2025 17:21:31 +0200 Subject: [PATCH 1/3] Polish Javadoc for MockPropertySource --- .../core/testfixture/env/MockPropertySource.java | 6 +++--- .../org/springframework/mock/env/MockPropertySource.java | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java index a4cbd1f22e..f1404079bb 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/env/MockPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-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. @@ -26,7 +26,7 @@ import org.springframework.core.env.PropertySource; * a user-provided {@link Properties} object, or if omitted during construction, * the implementation will initialize its own. * - * The {@link #setProperty} and {@link #withProperty} methods are exposed for + *

The {@link #setProperty} and {@link #withProperty} methods are exposed for * convenience, for example: *

  * {@code
@@ -95,7 +95,7 @@ public class MockPropertySource extends PropertiesPropertySource {
 
 	/**
 	 * Convenient synonym for {@link #setProperty} that returns the current instance.
-	 * Useful for method chaining and fluent-style use.
+	 * 

Useful for method chaining and fluent-style use. * @return this {@link MockPropertySource} instance */ public MockPropertySource withProperty(String name, Object value) { diff --git a/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java b/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java index 3ef180fcf2..8b2c6e1d77 100644 --- a/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java +++ b/spring-test/src/main/java/org/springframework/mock/env/MockPropertySource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-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. @@ -26,7 +26,7 @@ import org.springframework.core.env.PropertySource; * a user-provided {@link Properties} object, or if omitted during construction, * the implementation will initialize its own. * - * The {@link #setProperty} and {@link #withProperty} methods are exposed for + *

The {@link #setProperty} and {@link #withProperty} methods are exposed for * convenience, for example: *

  * {@code
@@ -36,7 +36,7 @@ import org.springframework.core.env.PropertySource;
  *
  * @author Chris Beams
  * @since 3.1
- * @see org.springframework.mock.env.MockEnvironment
+ * @see MockEnvironment
  */
 public class MockPropertySource extends PropertiesPropertySource {
 
@@ -95,7 +95,7 @@ public class MockPropertySource extends PropertiesPropertySource {
 
 	/**
 	 * Convenient synonym for {@link #setProperty} that returns the current instance.
-	 * Useful for method chaining and fluent-style use.
+	 * 

Useful for method chaining and fluent-style use. * @return this {@link MockPropertySource} instance */ public MockPropertySource withProperty(String name, Object value) { From d0efc2230c1244eaae3c9bf9e04afd66f0823484 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Mon, 26 May 2025 17:22:52 +0200 Subject: [PATCH 2/3] Support Object property values in MockEnvironment The setProperty() and withProperty() methods in MockEnvironment were originally introduced with (String, String) signatures; however, they should have always had (String, Object) signatures in order to comply with the MockPropertySource and PropertySource APIs. To address that, this commit introduces variants of these methods that accept Object values for properties. Closes gh-34947 --- .../mock/env/MockEnvironment.java | 44 ++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java b/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java index 88072db943..26d2506409 100644 --- a/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java +++ b/spring-test/src/main/java/org/springframework/mock/env/MockEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-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. @@ -26,7 +26,7 @@ import org.springframework.core.env.ConfigurableEnvironment; * @author Chris Beams * @author Sam Brannen * @since 3.2 - * @see org.springframework.mock.env.MockPropertySource + * @see MockPropertySource */ public class MockEnvironment extends AbstractEnvironment { @@ -43,19 +43,43 @@ public class MockEnvironment extends AbstractEnvironment { /** * Set a property on the underlying {@link MockPropertySource} for this environment. + * @since 6.2.8 + * @see MockPropertySource#setProperty(String, Object) */ - public void setProperty(String key, String value) { - this.propertySource.setProperty(key, value); + public void setProperty(String name, Object value) { + this.propertySource.setProperty(name, value); } /** - * Convenient synonym for {@link #setProperty} that returns the current instance. - * Useful for method chaining and fluent-style use. - * @return this {@link MockEnvironment} instance - * @see MockPropertySource#withProperty + * Set a property on the underlying {@link MockPropertySource} for this environment. + * @see #setProperty(String, Object) */ - public MockEnvironment withProperty(String key, String value) { - setProperty(key, value); + public void setProperty(String name, String value) { + this.propertySource.setProperty(name, value); + } + + /** + * Convenient synonym for {@link #setProperty(String, Object)} that returns + * the current instance. + *

Useful for method chaining and fluent-style use. + * @return this {@link MockEnvironment} instance + * @since 6.2.8 + * @see MockPropertySource#withProperty(String, Object) + */ + public MockEnvironment withProperty(String name, Object value) { + setProperty(name, value); + return this; + } + + /** + * Convenient synonym for {@link #setProperty(String, String)} that returns + * the current instance. + *

Useful for method chaining and fluent-style use. + * @return this {@link MockEnvironment} instance + * @see #withProperty(String, Object) + */ + public MockEnvironment withProperty(String name, String value) { + setProperty(name, value); return this; } From d78264756e3a82ff0cf31a7f4a2f3f97dac52f5d Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Mon, 26 May 2025 17:29:12 +0200 Subject: [PATCH 3/3] Support only Object property values in MockEnvironment test fixture The setProperty() and withProperty() methods in MockEnvironment were originally introduced with (String, String) signatures; however, they should have always had (String, Object) signatures in order to comply with the MockPropertySource and PropertySource APIs. To address that, this commit changes the signatures of these methods so that they only accept Object values for properties. NOTE: this commit only affects the internal MockEnvironment used as a test fixture. This commit does not affect the official, public MockEnvironment implementation in spring-test. See gh-34947 See gh-34948 --- .../mock/env/MockEnvironment.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java b/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java index 9a533f5635..34cde9f634 100644 --- a/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java +++ b/spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-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. @@ -27,7 +27,7 @@ import org.springframework.core.testfixture.env.MockPropertySource; * @author Chris Beams * @author Sam Brannen * @since 3.2 - * @see org.springframework.core.testfixture.env.MockPropertySource + * @see MockPropertySource */ public class MockEnvironment extends AbstractEnvironment { @@ -44,19 +44,23 @@ public class MockEnvironment extends AbstractEnvironment { /** * Set a property on the underlying {@link MockPropertySource} for this environment. + * @since 6.2.8 + * @see MockPropertySource#setProperty(String, Object) */ - public void setProperty(String key, String value) { - this.propertySource.setProperty(key, value); + public void setProperty(String name, Object value) { + this.propertySource.setProperty(name, value); } /** - * Convenient synonym for {@link #setProperty} that returns the current instance. - * Useful for method chaining and fluent-style use. + * Convenient synonym for {@link #setProperty(String, Object)} that returns + * the current instance. + *

Useful for method chaining and fluent-style use. * @return this {@link MockEnvironment} instance - * @see MockPropertySource#withProperty + * @since 6.2.8 + * @see MockPropertySource#withProperty(String, Object) */ - public MockEnvironment withProperty(String key, String value) { - setProperty(key, value); + public MockEnvironment withProperty(String name, Object value) { + setProperty(name, value); return this; }