prepared support for SPRNET-1167 (Properties class now supports reading in null values)
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using Spring.Context.Support;
|
||||
@@ -115,6 +116,55 @@ namespace Spring.Objects.Factory.Config
|
||||
TestObject tb1 = (TestObject)ac.GetObject("tb1");
|
||||
Assert.AreEqual(35, tb1.Age);
|
||||
Assert.AreEqual("Erich", tb1.Name);
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
[Ignore("Does not work yet because IVariableSource cannot differentiate between invalid key and key with a null value")]
|
||||
public void WhitespaceHandling()
|
||||
{
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.Add("name", "${name}");
|
||||
pvs.Add("nickname", "${nickname}");
|
||||
ac.RegisterSingleton("tb1", typeof(TestObject), pvs);
|
||||
|
||||
IList variableSources = new ArrayList();
|
||||
variableSources.Add(new DictionaryVariableSource(new string[] { "name", string.Empty, "nickname", null }));
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.Add("VariableSources", variableSources);
|
||||
ac.RegisterSingleton("configurer", typeof(VariablePlaceholderConfigurer), pvs);
|
||||
ac.Refresh();
|
||||
|
||||
TestObject tb1 = (TestObject)ac.GetObject("tb1");
|
||||
Assert.AreEqual(string.Empty, tb1.Name);
|
||||
Assert.AreEqual(null, tb1.Nickname);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BailsOnUnresolvableVariable()
|
||||
{
|
||||
StaticApplicationContext ac = new StaticApplicationContext();
|
||||
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.Add("nickname", "${nickname}");
|
||||
ac.RegisterSingleton("tb1", typeof(TestObject), pvs);
|
||||
|
||||
IList variableSources = new ArrayList();
|
||||
variableSources.Add(new DictionaryVariableSource(new string[] { }));
|
||||
pvs = new MutablePropertyValues();
|
||||
pvs.Add("VariableSources", variableSources);
|
||||
ac.RegisterSingleton("configurer", typeof(VariablePlaceholderConfigurer), pvs);
|
||||
|
||||
try
|
||||
{
|
||||
ac.Refresh();
|
||||
Assert.Fail("something changed wrt VariablePlaceholder resolution");
|
||||
}
|
||||
catch (ObjectDefinitionStoreException ex)
|
||||
{
|
||||
Assert.IsTrue( ex.Message.IndexOf("nickname") > -1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -101,7 +101,7 @@ namespace Spring.Util
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ListAndLoad ()
|
||||
public void ListAndLoad()
|
||||
{
|
||||
Properties props = new Properties();
|
||||
props.Add ("foo", "this");
|
||||
@@ -151,6 +151,21 @@ namespace Spring.Util
|
||||
Assert.IsTrue("true".Equals(props["leadingspace"]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhitespaceProperties()
|
||||
{
|
||||
string input = "key1 =\t\nkey2:\nkey3";
|
||||
|
||||
Stream s = new MemoryStream(Encoding.ASCII.GetBytes(input));
|
||||
Properties props = new Properties();
|
||||
props.Load(s);
|
||||
|
||||
Assert.AreEqual(string.Empty, props["key1"], "key1 should have empty value");
|
||||
Assert.AreEqual(string.Empty, props["key2"], "key2 should have empty value");
|
||||
Assert.IsTrue(props.ContainsKey("key3"));
|
||||
Assert.IsNull(props["key3"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Continuation()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user