001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.diff;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: import junit.framework.*;
039:
040: import com.jeantessier.classreader.*;
041:
042: public abstract class TestDifferencesFactoryBase extends TestCase {
043: public static final String OLD_CLASSPATH = "tests" + File.separator
044: + "JarJarDiff" + File.separator + "old";
045: public static final String NEW_CLASSPATH = "tests" + File.separator
046: + "JarJarDiff" + File.separator + "new";
047:
048: private static PackageMapper oldPackages;
049: private static PackageMapper newPackages;
050:
051: private static ClassfileLoader oldJar;
052: private static ClassfileLoader newJar;
053:
054: protected static PackageMapper getOldPackages() {
055: if (oldPackages == null) {
056: oldPackages = new PackageMapper();
057: }
058:
059: return oldPackages;
060: }
061:
062: protected static PackageMapper getNewPackages() {
063: if (newPackages == null) {
064: newPackages = new PackageMapper();
065: }
066:
067: return newPackages;
068: }
069:
070: protected static ClassfileLoader getOldJar() {
071: if (oldJar == null) {
072: oldJar = new AggregatingClassfileLoader();
073: oldJar.addLoadListener(getOldPackages());
074: oldJar.load(Collections.singleton(OLD_CLASSPATH));
075: }
076:
077: return oldJar;
078: }
079:
080: protected static ClassfileLoader getNewJar() {
081: if (newJar == null) {
082: newJar = new AggregatingClassfileLoader();
083: newJar.addLoadListener(getNewPackages());
084: newJar.load(Collections.singleton(NEW_CLASSPATH));
085: }
086:
087: return newJar;
088: }
089:
090: protected void setUp() throws Exception {
091: super .setUp();
092:
093: // Make sure classes are loaded
094: getOldJar();
095: getNewJar();
096: }
097:
098: protected Differences find(String name, Collection differences) {
099: Differences result = null;
100:
101: Iterator i = differences.iterator();
102: while (result == null && i.hasNext()) {
103: Differences candidate = (Differences) i.next();
104: if (name.equals(candidate.getName())) {
105: result = candidate;
106: }
107: }
108:
109: return result;
110: }
111: }
|