1 package org.apache.maven.plugin.resources;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24 import java.util.Properties;
25
26
27
28
29
30
31 public class EnhancedPropertyUtilsTest
32 extends AbstractPropertyUtilsTest
33 {
34 private static final String validationFileName =
35 "/target/test-classes/unit/propertiesutils-test/enhanced_validation.properties";
36
37 private static final String propFileName = "/target/test-classes/unit/propertiesutils-test/enhanced.properties";
38
39 private final Properties baseProps = new Properties();
40
41 protected void setUp()
42 throws Exception
43 {
44 super.setUp();
45 this.baseProps.setProperty( "prop1", "valueOfProperty1" );
46 }
47
48 protected File getPropertyFile()
49 {
50 final File propFile = new File( getBasedir(), propFileName );
51
52 if ( !propFile.exists() )
53 {
54 return null;
55 }
56
57 return propFile;
58 }
59
60 protected File getValidationFile()
61 {
62 final File file = new File( getBasedir(), validationFileName );
63
64 if ( !file.exists() )
65 {
66 return null;
67 }
68
69 return file;
70 }
71
72
73
74
75
76
77 public void testBasicLoadProperty()
78 throws Exception
79 {
80 final Properties props = PropertyUtils.loadPropertyFile( this.propertyFile, this.baseProps );
81
82 assertNotNull( props );
83 assertTrue( validateProperties( props ) );
84 }
85
86
87
88
89
90
91 public void testNonExistentProperty()
92 throws Exception
93 {
94 final Properties props = PropertyUtils.loadPropertyFile( this.propertyFile, this.baseProps );
95
96 assertNotNull( props );
97 assertNull( props.getProperty( "does_not_exist" ) );
98 }
99
100
101
102
103
104
105 public void testException()
106 throws Exception
107 {
108 try
109 {
110 PropertyUtils.loadPropertyFile( new File( "NON_EXISTENT_FILE" ), this.baseProps );
111 fail( "Should not have been able to load properties from a non-existent file" );
112 }
113 catch ( IOException e )
114 {
115
116 }
117 }
118 }