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
(cherry picked from commit d78264756e
)
This commit is contained in:
parent
30bee4db0f
commit
c0a9da65f4
|
@ -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");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with 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 Chris Beams
|
||||||
* @author Sam Brannen
|
* @author Sam Brannen
|
||||||
* @since 3.2
|
* @since 3.2
|
||||||
* @see org.springframework.core.testfixture.env.MockPropertySource
|
* @see MockPropertySource
|
||||||
*/
|
*/
|
||||||
public class MockEnvironment extends AbstractEnvironment {
|
public class MockEnvironment extends AbstractEnvironment {
|
||||||
|
|
||||||
|
@ -44,19 +44,21 @@ public class MockEnvironment extends AbstractEnvironment {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a property on the underlying {@link MockPropertySource} for this environment.
|
* Set a property on the underlying {@link MockPropertySource} for this environment.
|
||||||
|
* @see MockPropertySource#setProperty(String, Object)
|
||||||
*/
|
*/
|
||||||
public void setProperty(String key, String value) {
|
public void setProperty(String name, Object value) {
|
||||||
this.propertySource.setProperty(key, value);
|
this.propertySource.setProperty(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenient synonym for {@link #setProperty} that returns the current instance.
|
* Convenient synonym for {@link #setProperty(String, Object)} that returns
|
||||||
* Useful for method chaining and fluent-style use.
|
* the current instance.
|
||||||
|
* <p>Useful for method chaining and fluent-style use.
|
||||||
* @return this {@link MockEnvironment} instance
|
* @return this {@link MockEnvironment} instance
|
||||||
* @see MockPropertySource#withProperty
|
* @see MockPropertySource#withProperty(String, Object)
|
||||||
*/
|
*/
|
||||||
public MockEnvironment withProperty(String key, String value) {
|
public MockEnvironment withProperty(String name, Object value) {
|
||||||
setProperty(key, value);
|
setProperty(name, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue