Skip to content

Commit d782647

Browse files
committed
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 spring-projectsgh-34947 See spring-projectsgh-34948
1 parent d0efc22 commit d782647

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

spring-context/src/test/java/org/springframework/mock/env/MockEnvironment.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
* @author Chris Beams
2828
* @author Sam Brannen
2929
* @since 3.2
30-
* @see org.springframework.core.testfixture.env.MockPropertySource
30+
* @see MockPropertySource
3131
*/
3232
public class MockEnvironment extends AbstractEnvironment {
3333

@@ -44,19 +44,23 @@ public MockEnvironment() {
4444

4545
/**
4646
* Set a property on the underlying {@link MockPropertySource} for this environment.
47+
* @since 6.2.8
48+
* @see MockPropertySource#setProperty(String, Object)
4749
*/
48-
public void setProperty(String key, String value) {
49-
this.propertySource.setProperty(key, value);
50+
public void setProperty(String name, Object value) {
51+
this.propertySource.setProperty(name, value);
5052
}
5153

5254
/**
53-
* Convenient synonym for {@link #setProperty} that returns the current instance.
54-
* Useful for method chaining and fluent-style use.
55+
* Convenient synonym for {@link #setProperty(String, Object)} that returns
56+
* the current instance.
57+
* <p>Useful for method chaining and fluent-style use.
5558
* @return this {@link MockEnvironment} instance
56-
* @see MockPropertySource#withProperty
59+
* @since 6.2.8
60+
* @see MockPropertySource#withProperty(String, Object)
5761
*/
58-
public MockEnvironment withProperty(String key, String value) {
59-
setProperty(key, value);
62+
public MockEnvironment withProperty(String name, Object value) {
63+
setProperty(name, value);
6064
return this;
6165
}
6266

0 commit comments

Comments
 (0)