This is an automated email from the ASF dual-hosted git repository. hboutemy pushed a commit to annotated tag maven-filtering-1.0-alpha-1 in repository https://gitbox.apache.org/repos/asf/maven-filtering.git
commit ab64b03234d71115c2f8458128c6d6ad579a3b9c Author: Oliver Lamy <[email protected]> AuthorDate: Mon Feb 4 21:22:15 2008 +0000 add unit on PropertyUtils git-svn-id: https://svn.apache.org/repos/asf/maven/sandbox/trunk/shared/maven-filtering@618443 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/shared/filtering/PropertyUtilsTest.java | 101 +++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java new file mode 100755 index 0000000..70d3fe0 --- /dev/null +++ b/src/test/java/org/apache/maven/shared/filtering/PropertyUtilsTest.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.shared.filtering; + +import java.io.File; +import java.io.FileWriter; +import java.util.Properties; + +import org.codehaus.plexus.PlexusTestCase; + +/** + * @author <a href="mailto:[email protected]">olamy</a> + * @since 4 f�vr. 08 + * @version $Id$ + */ +public class PropertyUtilsTest + extends PlexusTestCase +{ + private static File testDirectory = new File( getBasedir(), "target/test-classes/" ); + + + + public void testBasic() + throws Exception + { + File basicProp = new File( testDirectory, "basic.properties" ); + + if ( basicProp.exists() ) + { + basicProp.delete(); + } + + basicProp.createNewFile(); + FileWriter writer = new FileWriter( basicProp ); + + writer.write( "ghost=${non_existent}\n" ); + writer.write( "key=${untat_na_damgo}\n" ); + writer.write( "untat_na_damgo=gani_man\n" ); + writer.flush(); + writer.close(); + + Properties prop = PropertyUtils.loadPropertyFile( basicProp, false, false ); + assertTrue( prop.getProperty( "key" ).equals( "gani_man" ) ); + assertTrue( prop.getProperty( "ghost" ).equals( "${non_existent}" ) ); + } + + public void testSystemProperties() + throws Exception + { + File systemProp = new File( testDirectory, "system.properties" ); + + if ( systemProp.exists() ) + { + systemProp.delete(); + } + + systemProp.createNewFile(); + FileWriter writer = new FileWriter( systemProp ); + + writer.write( "key=${user.dir}" ); + writer.flush(); + writer.close(); + + Properties prop = PropertyUtils.loadPropertyFile( systemProp, false, true ); + assertTrue( prop.getProperty( "key" ).equals( System.getProperty( "user.dir" ) ) ); + } + + public void testException() + throws Exception + { + File nonExistent = new File( testDirectory, "not_existent_file" ); + + assertFalse( "property file exist: " + nonExistent.toString(), nonExistent.exists() ); + + try + { + PropertyUtils.loadPropertyFile( nonExistent, true, false ); + assertTrue( "Exception failed", false ); + } + catch ( Exception ex ) + { + // exception ok + } + } +}
