View Javadoc

1   package org.kuali.spring.util;
2   
3   import java.io.IOException;
4   import java.util.Properties;
5   
6   import junit.framework.Assert;
7   
8   import org.junit.Test;
9   
10  public class PropertiesRetrieverTest {
11  
12  	@Test
13  	public void test1() throws IOException {
14  		String key = "foo";
15  		String val = "bar";
16  		Properties properties = new Properties();
17  		properties.setProperty(key, val);
18  		ValueRetriever retriever = new PropertiesRetriever(properties);
19  
20  		String resolvedProperty = retriever.retrieveValue(key);
21  		String unresolvedProperty = retriever.retrieveValue("A-Key-That-Does-Not-Exist");
22  
23  		Assert.assertEquals(val, resolvedProperty);
24  		Assert.assertNull(unresolvedProperty);
25  
26  	}
27  
28  	@Test
29  	public void test2() throws IOException {
30  		String key = "foo";
31  		String val = "bar";
32  		Properties properties = new Properties();
33  		properties.setProperty(key, val);
34  		PropertiesRetriever retriever = new PropertiesRetriever();
35  		retriever.setProperties(properties);
36  
37  		String resolvedProperty = retriever.retrieveValue(key);
38  		String unresolvedProperty = retriever.retrieveValue("A-Key-That-Does-Not-Exist");
39  
40  		Assert.assertEquals(val, resolvedProperty);
41  		Assert.assertNull(unresolvedProperty);
42  
43  		Properties resolverProperties = retriever.getProperties();
44  		Assert.assertEquals(properties.getProperty(key), resolverProperties.getProperty(key));
45  
46  	}
47  
48  }