001: package net.sf.clirr.core.internal.checks;
002:
003: import net.sf.clirr.core.ApiDifference;
004: import net.sf.clirr.core.MessageTranslator;
005: import net.sf.clirr.core.Severity;
006:
007: /**
008: * Describes an expected API change.
009: */
010:
011: public final class ExpectedDiff {
012: private static MessageTranslator translator = new MessageTranslator();
013:
014: private String report;
015: private Severity binaryCompatibilitySeverity;
016: private Severity sourceCompatibilitySeverity;
017: private String affectedClass;
018: private String affectedMethod;
019: private String affectedField;
020:
021: /**
022: * Create a new API difference representation.
023: *
024: * @param report a human readable string describing the change that was made, must be non-null.
025: * @param severity the severity in terms of binary and source code compatibility, must be non-null.
026: * @param clazz the fully qualified class name where the change occured, must be non-null.
027: * @param method the method signature of the method that changed, <code>null</code>
028: * if no method was affected.
029: * @param field the field name where the change occured, <code>null</code>
030: * if no field was affected.
031: */
032: public ExpectedDiff(String report, Severity severity, String clazz,
033: String method, String field) {
034: this (report, severity, severity, clazz, method, field);
035: }
036:
037: /**
038: * Create a new API difference representation.
039: *
040: * @param report a human readable string describing the change that was made, must be non-null.
041: * @param binarySeverity the severity in terms of binary compatibility, must be non-null.
042: * @param sourceSeverity the severity in terms of source code compatibility, must be non-null.
043: * @param clazz the fully qualified class name where the change occured, must be non-null.
044: * @param method the method signature of the method that changed, <code>null</code>
045: * if no method was affected.
046: * @param field the field name where the change occured, <code>null</code>
047: * if no field was affected.
048: */
049: public ExpectedDiff(String report, Severity binarySeverity,
050: Severity sourceSeverity, String clazz, String method,
051: String field) {
052: checkNonNull(report);
053: checkNonNull(binarySeverity);
054: checkNonNull(sourceSeverity);
055: checkNonNull(clazz);
056:
057: this .report = report;
058: this .binaryCompatibilitySeverity = binarySeverity;
059: this .sourceCompatibilitySeverity = sourceSeverity;
060: this .affectedClass = clazz;
061: this .affectedField = field;
062: this .affectedMethod = method;
063: }
064:
065: /**
066: * Trivial utility method to verify that a specific object is non-null.
067: */
068: private void checkNonNull(Object o) {
069: if (o == null) {
070: throw new IllegalArgumentException();
071: }
072: }
073:
074: /**
075: * {@inheritDoc}
076: */
077: public String toString() {
078: return report + " (" + binaryCompatibilitySeverity + ") - "
079: + affectedClass + '[' + affectedField + '/'
080: + affectedMethod + ']';
081: }
082:
083: /**
084: * Returns true if the provided ApiDifference object matches the
085: * expected value.
086: */
087: public boolean matches(ApiDifference diff) {
088: if (!report.equals(diff.getReport(translator))) {
089: return false;
090: }
091:
092: if (!binaryCompatibilitySeverity.equals(diff
093: .getBinaryCompatibilitySeverity())) {
094: return false;
095: }
096:
097: if (!sourceCompatibilitySeverity.equals(diff
098: .getSourceCompatibilitySeverity())) {
099: return false;
100: }
101:
102: final String otherClass = diff.getAffectedClass();
103: if (!affectedClass.equals(otherClass)) {
104: return false;
105: }
106:
107: final String otherMethod = diff.getAffectedMethod();
108: if (affectedMethod != null ? !affectedMethod
109: .equals(otherMethod) : otherMethod != null) {
110: return false;
111: }
112:
113: final String otherField = diff.getAffectedField();
114: if (affectedField != null ? !affectedField.equals(otherField)
115: : otherField != null) {
116: return false;
117: }
118:
119: return true;
120: }
121: }
|