63 Star 427 Fork 156

huifer/Code-Analysis

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
docs
beans
core
env
PropertyResolver
PlaceholderResolver
PropertySource
images
Readme.md
Spring-CommandLinePropertySource.md
Spring-ComparisonPropertySource.md
Spring-CompositePropertySource.md
Spring-EnumerablePropertySource.md
Spring-MapPropertySource.md
Spring-MockPropertySource.md
Spring-PropertiesPropertySource.md
Spring-ResourcePropertySource.md
Spring-ServletConfigPropertySource.md
Spring-ServletContextPropertySource.md
Spring-SimpleCommandLineArgsParser.md
Spring-SimpleCommandLinePropertySource.md
Spring-StubPropertySource.md
Spring-SystemEnvironmentPropertySource.md
images
Readme.md
Spring-AbstractPropertyResolver.md
Spring-Environment.md
Spring-PropertyPlaceholderHelper.md
Spring-PropertyResolver.md
Spring-PropertySources.md
Spring-PropertySourcesPropertyResolver.md
environment
other
utils
release
.gitattributes
.gitignore
CHANGELOG.MD
LICENSE
Notice
README.md
_coverpage.md
index.html
summary.md
todo.md
克隆/下载
Spring-MockPropertySource.md 2.71 KB
一键复制 编辑 原始数据 按行查看 历史
huifer 提交于 5年前 . :fire:doc: env + PropertyResolver

Spring MockPropertySource

withProperty

  • 设置属性名称和属性值
public MockPropertySource withProperty(String name, Object value) {
   this.setProperty(name, value);
   return this;
}

setProperty

public void setProperty(String name, Object value) {
   this.source.put(name, value);
}

完整代码

public class MockPropertySource extends PropertiesPropertySource {

   /**
    * {@value} is the default name for {@link MockPropertySource} instances not
    * otherwise given an explicit name.
    * @see #MockPropertySource()
    * @see #MockPropertySource(String)
    */
   public static final String MOCK_PROPERTIES_PROPERTY_SOURCE_NAME = "mockProperties";

   /**
    * Create a new {@code MockPropertySource} named {@value #MOCK_PROPERTIES_PROPERTY_SOURCE_NAME}
    * that will maintain its own internal {@link Properties} instance.
    */
   public MockPropertySource() {
      this(new Properties());
   }

   /**
    * Create a new {@code MockPropertySource} with the given name that will
    * maintain its own internal {@link Properties} instance.
    * @param name the {@linkplain #getName() name} of the property source
    */
   public MockPropertySource(String name) {
      this(name, new Properties());
   }

   /**
    * Create a new {@code MockPropertySource} named {@value #MOCK_PROPERTIES_PROPERTY_SOURCE_NAME}
    * and backed by the given {@link Properties} object.
    * @param properties the properties to use
    */
   public MockPropertySource(Properties properties) {
      this(MOCK_PROPERTIES_PROPERTY_SOURCE_NAME, properties);
   }

   /**
    * Create a new {@code MockPropertySource} with the given name and backed by the given
    * {@link Properties} object.
    * @param name the {@linkplain #getName() name} of the property source
    * @param properties the properties to use
    */
   public MockPropertySource(String name, Properties properties) {
      super(name, properties);
   }

   /**
    * Set the given property on the underlying {@link Properties} object.
    */
   public void setProperty(String name, Object value) {
      // map 操作
      this.source.put(name, value);
   }

   /**
    * Convenient synonym for {@link #setProperty} that returns the current instance.
    * Useful for method chaining and fluent-style use.
    * 设置属性名称和属性值
    * @return this {@link MockPropertySource} instance
    */
      public MockPropertySource withProperty(String name, Object value) {
         this.setProperty(name, value);
         return this;
      }

}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/pychfarm_admin/code-analysis.git
git@gitee.com:pychfarm_admin/code-analysis.git
pychfarm_admin
code-analysis
Code-Analysis
v0.0.15

搜索帮助