View Javadoc
1   package org.codehaus.plexus.interpolation;
2   
3   /*
4    * Copyright 2001-2008 Codehaus Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  
19  import java.util.Properties;
20  
21  import junit.framework.TestCase;
22  
23  public class PrefixedValueSourceWrapperTest
24      extends TestCase
25  {
26  
27      public void testShouldReturnValueForPropertyVSWRappedWithSinglePrefix()
28      {
29          String prefix = "prefix.";
30          String key = "key";
31          String value = "value";
32  
33          Properties props = new Properties();
34          props.setProperty( key, value );
35  
36          PrefixedValueSourceWrapper wrapper = new PrefixedValueSourceWrapper( new PropertiesBasedValueSource( props ), prefix );
37  
38          assertEquals( value, wrapper.getValue( prefix + key ) );
39      }
40  
41      public void testShouldReturnNullForIncorrectPrefixUsingPropertyVSWRappedWithSinglePrefix()
42      {
43          String prefix = "prefix.";
44          String otherPrefix = "other.";
45          String key = "key";
46          String value = "value";
47  
48          Properties props = new Properties();
49          props.setProperty( key, value );
50  
51          PrefixedValueSourceWrapper wrapper = new PrefixedValueSourceWrapper( new PropertiesBasedValueSource( props ), prefix );
52  
53          assertNull( wrapper.getValue( otherPrefix + key ) );
54      }
55  
56      public void testShouldNullForMissingValueInPropertyVSWRappedWithSinglePrefix()
57      {
58          String prefix = "prefix.";
59          String key = "key";
60  
61          Properties props = new Properties();
62  
63          PrefixedValueSourceWrapper wrapper = new PrefixedValueSourceWrapper( new PropertiesBasedValueSource( props ), prefix );
64  
65          assertNull( wrapper.getValue( prefix + key ) );
66      }
67  
68  }