junit-team/junit — pull request #675 by avandeursen (2013-05-09 09:41:44+00:00)
Title: Test class for String Comparison Compactors, and off-by-one refactoring of compactor.

Added 12 testcases for compacting failure comparisons, and refactored an off-by-one inconsistency.

When String equality assertions fail, JUnit highlights string differences using formatting such as `"abc[pqr]…"`.

This string compacting is fairly tricky and the current implementation was only tested incompletely and indirectly via the AssertionTest class.

I took the old tests from [junit.tests.framework.ComparisonCompactorTest](src/test/java/junit/tests/framework/ComparisonCompactorTest.java), and updated them to a new (parameterized) tests actually running on the `org.junit` compactor.

While running branch coverage analysis, it became appearant that in the `ComparisonFailure` class the `fSuffix` condition in `compactString` could never be false:

if (fPrefix > 0) {
result = computeCommonPrefix() + result;
}
if (fSuffix > 0) {
result = result + computeCommonSuffix();
}

The reason was an off-by-one error in the computation of `fSuffix`, making it always greater than or equal to 1, but never 0 (unlike `fPrefix`, which can be zero).

I fixed the off by one inconsistency, replacing four "+1" occurrences
by one missing "-1".