001: /*
002: * @(#)PropertyCheckUtil.java
003: *
004: * Copyright (C) 2004 Matt Albrecht
005: * groboclown@users.sourceforge.net
006: * http://groboutils.sourceforge.net
007: *
008: * Permission is hereby granted, free of charge, to any person obtaining a
009: * copy of this software and associated documentation files (the "Software"),
010: * to deal in the Software without restriction, including without limitation
011: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
012: * and/or sell copies of the Software, and to permit persons to whom the
013: * Software is furnished to do so, subject to the following conditions:
014: *
015: * The above copyright notice and this permission notice shall be included in
016: * all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
019: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
020: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
021: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
022: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
023: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
024: * DEALINGS IN THE SOFTWARE.
025: */
026:
027: package net.sourceforge.groboutils.codecoverage.v2.ant;
028:
029: import java.io.FileInputStream;
030: import java.io.IOException;
031: import java.io.InputStream;
032: import java.util.Enumeration;
033: import java.util.Properties;
034:
035: import junit.framework.Assert;
036:
037: /**
038: * Checks for property files.
039: *
040: * @author Matt Albrecht <a href="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
041: * @version $Date: 2004/04/15 05:48:27 $
042: * @since March 9, 2004
043: */
044: public class PropertyCheckUtil extends Assert {
045: public static void assertEquals( String text, Properties expected,
046: Properties actual )
047: {
048: StringBuffer missing = new StringBuffer( text );
049: int badCount = 0;
050:
051: Enumeration enum = expected.propertyNames();
052: while (enum.hasMoreElements())
053: {
054: String key = (String)enum.nextElement();
055: String value = expected.getProperty( key );
056: String actualValue = expected.getProperty( key );
057: if (!value.equals( actualValue ))
058: {
059: ++badCount;
060: missing.append( "; expected property '" ).
061: append( key ).append( "' to have value '" ).
062: append( value ).append( "', but found '" ).
063: append( actualValue ).append( "'" );
064: }
065: }
066:
067: enum = actual.propertyNames();
068: while (enum.hasMoreElements())
069: {
070: String key = (String)enum.nextElement();
071: if (expected.getProperty( key ) == null)
072: {
073: ++badCount;
074: missing.append( "; found extra property '" ).
075: append( key ).append( "' = '" ).
076: append( actual.getProperty( key ) ).append( "'" );
077: }
078: }
079:
080: if (badCount > 0)
081: {
082: fail( missing.toString() );
083: }
084: }
085:
086: public static Properties loadGroboProperties() throws IOException {
087: return loadProperties("./grobocoverage.properties");
088: }
089:
090: public static Properties loadProperties(String file)
091: throws IOException {
092: Properties props = new Properties();
093: InputStream is = new FileInputStream(file);
094: try {
095: props.load(is);
096: } finally {
097: is.close();
098: }
099: return props;
100: }
101: }
|