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 com.jeantessier.classreader.*;
036:
037: public class TestCodeDifferenceStrategy extends
038: TestDifferencesFactoryBase {
039: private CodeDifferenceStrategy strategy;
040:
041: protected void setUp() throws Exception {
042: super .setUp();
043:
044: strategy = new CodeDifferenceStrategy();
045: }
046:
047: public void testUnmodifiedConstantValue() {
048: ConstantValue_attribute oldValue = getOldJar().getClassfile(
049: "UnmodifiedPackage.UnmodifiedInterface").getField(
050: "unmodifiedField").getConstantValue();
051: ConstantValue_attribute newValue = getNewJar().getClassfile(
052: "UnmodifiedPackage.UnmodifiedInterface").getField(
053: "unmodifiedField").getConstantValue();
054:
055: assertFalse(strategy.isConstantValueDifferent(oldValue,
056: newValue));
057: }
058:
059: public void testRemovedConstantValue() {
060: ConstantValue_attribute oldValue = getOldJar().getClassfile(
061: "ModifiedPackage.ModifiedInterface").getField(
062: "removedField").getConstantValue();
063: ConstantValue_attribute newValue = null;
064:
065: assertTrue(strategy
066: .isConstantValueDifferent(oldValue, newValue));
067: }
068:
069: public void testModifiedConstantValue() {
070: ConstantValue_attribute oldValue = getOldJar().getClassfile(
071: "ModifiedPackage.ModifiedInterface").getField(
072: "modifiedValueField").getConstantValue();
073: ConstantValue_attribute newValue = getNewJar().getClassfile(
074: "ModifiedPackage.ModifiedInterface").getField(
075: "modifiedValueField").getConstantValue();
076:
077: assertTrue(strategy
078: .isConstantValueDifferent(oldValue, newValue));
079: }
080:
081: public void testNewConstantValue() {
082: ConstantValue_attribute oldValue = null;
083: ConstantValue_attribute newValue = getNewJar().getClassfile(
084: "ModifiedPackage.ModifiedInterface").getField(
085: "newField").getConstantValue();
086:
087: assertTrue(strategy
088: .isConstantValueDifferent(oldValue, newValue));
089: }
090:
091: public void testUnmodifiedCode() {
092: Code_attribute oldCode = getOldJar().getClassfile(
093: "UnmodifiedPackage.UnmodifiedClass").getMethod(
094: "unmodifiedMethod()").getCode();
095: Code_attribute newCode = getNewJar().getClassfile(
096: "UnmodifiedPackage.UnmodifiedClass").getMethod(
097: "unmodifiedMethod()").getCode();
098:
099: assertFalse(strategy.isCodeDifferent(oldCode, newCode));
100: }
101:
102: public void testModifiedCode() {
103: Code_attribute oldCode = getOldJar().getClassfile(
104: "ModifiedPackage.ModifiedClass").getMethod(
105: "modifiedCodeMethod()").getCode();
106: Code_attribute newCode = getNewJar().getClassfile(
107: "ModifiedPackage.ModifiedClass").getMethod(
108: "modifiedCodeMethod()").getCode();
109:
110: assertTrue(strategy.isCodeDifferent(oldCode, newCode));
111: }
112: }
|