001: package net.sf.clirr.core.internal.checks;
002:
003: import net.sf.clirr.core.internal.ClassChangeCheck;
004: import net.sf.clirr.core.Severity;
005: import net.sf.clirr.core.ScopeSelector;
006: import net.sf.clirr.core.internal.checks.MethodSetCheck;
007: import net.sf.clirr.core.internal.checks.AbstractCheckTestCase;
008: import net.sf.clirr.core.internal.checks.ExpectedDiff;
009:
010: /**
011: * TODO: Docs.
012: *
013: * @author lkuehne
014: */
015: public class MethodSetCheckTest extends AbstractCheckTestCase {
016: public void testMethodCheck() throws Exception {
017: ExpectedDiff[] expected = new ExpectedDiff[] {
018:
019: // method addition and removal
020: new ExpectedDiff(
021: "Method 'public void removedMethod(java.lang.String)' has been removed",
022: Severity.ERROR, "testlib.MethodsChange",
023: "public void removedMethod(java.lang.String)",
024: null),
025: new ExpectedDiff(
026: "Accessibility of method 'public int getPriv2()' has been decreased from public to private",
027: Severity.ERROR, "testlib.MethodsChange",
028: "public int getPriv2()", null),
029: new ExpectedDiff(
030: "Method 'protected MethodsChange(int, boolean)' has been added",
031: Severity.INFO, "testlib.MethodsChange",
032: "protected MethodsChange(int, boolean)", null),
033: new ExpectedDiff(
034: "Method 'public java.lang.Long getPrivSquare()' has been added",
035: Severity.INFO, "testlib.MethodsChange",
036: "public java.lang.Long getPrivSquare()", null),
037:
038: new ExpectedDiff(
039: "Method 'public void moveToSuper()' has been added",
040: Severity.INFO, "testlib.ComplexMethodMoveBase",
041: "public void moveToSuper()", null),
042: new ExpectedDiff(
043: "Method 'public void moveToSuper()' is now implemented in superclass testlib.ComplexMethodMoveBase",
044: Severity.INFO, "testlib.ComplexMethodMoveSub",
045: "public void moveToSuper()", null),
046:
047: new ExpectedDiff(
048: "Method 'public void method()' has been removed, but an inherited definition exists.",
049: Severity.INFO, "testlib.AbstractImpl",
050: "public void method()", null),
051:
052: // Constructor changes
053: new ExpectedDiff(
054: "Parameter 1 of 'protected MethodsChange(int)' has changed its type to java.lang.Integer",
055: Severity.ERROR, "testlib.MethodsChange",
056: "protected MethodsChange(int)", null),
057:
058: // return type changes
059: new ExpectedDiff(
060: "Return type of method 'public java.lang.Number getPrivAsNumber()' has been changed to java.lang.Integer",
061: Severity.ERROR, "testlib.MethodsChange",
062: "public java.lang.Number getPrivAsNumber()",
063: null),
064: // TODO: INFO if method is final
065: new ExpectedDiff(
066: "Return type of method 'public java.lang.Integer getPrivAsInteger()' has been changed to java.lang.Number",
067: Severity.ERROR, "testlib.MethodsChange",
068: "public java.lang.Integer getPrivAsInteger()",
069: null),
070:
071: // parameter list changes
072: // Note: This is the current behaviour, not necessarily the spec of the desired behaviour
073: // TODO: need to check assignability of types (and check if method or class is final?)
074: new ExpectedDiff(
075: "In method 'public void printPriv()' the number of arguments has changed",
076: Severity.ERROR, "testlib.MethodsChange",
077: "public void printPriv()", null),
078: new ExpectedDiff(
079: "Parameter 1 of 'public void strengthenParamType(java.lang.Object)' has changed its type to java.lang.String",
080: Severity.ERROR,
081: "testlib.MethodsChange",
082: "public void strengthenParamType(java.lang.Object)",
083: null),
084: new ExpectedDiff(
085: "Parameter 1 of 'public void weakenParamType(java.lang.String)' has changed its type to java.lang.Object",
086: Severity.ERROR,
087: "testlib.MethodsChange",
088: "public void weakenParamType(java.lang.String)",
089: null),
090: new ExpectedDiff(
091: "Parameter 1 of 'public void changeParamType(java.lang.String)' has changed its type to java.lang.Integer",
092: Severity.ERROR,
093: "testlib.MethodsChange",
094: "public void changeParamType(java.lang.String)",
095: null),
096:
097: // deprecation changes
098: new ExpectedDiff(
099: "Method 'public void becomesDeprecated()' has been deprecated",
100: Severity.INFO, "testlib.MethodsChange",
101: "public void becomesDeprecated()", null),
102: new ExpectedDiff(
103: "Method 'public void becomesUndeprecated()' is no longer deprecated",
104: Severity.INFO, "testlib.MethodsChange",
105: "public void becomesUndeprecated()", null),
106:
107: // modifier changes
108: new ExpectedDiff(
109: "Method 'public void becomesFinal()' is now final",
110: Severity.ERROR, "testlib.MethodsChange",
111: "public void becomesFinal()", null),
112: new ExpectedDiff(
113: "Method 'public void becomesNonFinal()' is no longer final",
114: Severity.INFO, "testlib.MethodsChange",
115: "public void becomesNonFinal()", null),
116:
117: // declared exceptions
118: // TODO
119: };
120: verify(expected);
121: }
122:
123: protected final ClassChangeCheck createCheck(TestDiffListener tdl) {
124: return new MethodSetCheck(tdl, new ScopeSelector());
125: }
126: }
|