passing through exceptions

This commit is contained in:
wumpz
2017-04-03 15:14:52 +02:00
parent 37556b7dba
commit c819f96edd
4 changed files with 24 additions and 20 deletions

View File

@@ -7,6 +7,7 @@ import difflib.patch.ChangeDelta;
import difflib.patch.Patch;
import difflib.patch.DeleteDelta;
import difflib.*;
import difflib.algorithm.DiffException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -19,7 +20,7 @@ import org.junit.Test;
public class DiffUtilsTest {
@Test
public void testDiff_Insert() {
public void testDiff_Insert() throws DiffException {
final Patch<String> patch = DiffUtils.diff(Arrays.asList("hhh"), Arrays.
asList("hhh", "jjj", "kkk"));
assertNotNull(patch);
@@ -31,7 +32,7 @@ public class DiffUtilsTest {
}
@Test
public void testDiff_Delete() {
public void testDiff_Delete() throws DiffException {
final Patch<String> patch = DiffUtils.diff(Arrays.asList("ddd", "fff", "ggg"), Arrays.
asList("ggg"));
assertNotNull(patch);
@@ -43,7 +44,7 @@ public class DiffUtilsTest {
}
@Test
public void testDiff_Change() {
public void testDiff_Change() throws DiffException {
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc");
final List<String> changeTest_to = Arrays.asList("aaa", "zzz", "ccc");
@@ -57,14 +58,14 @@ public class DiffUtilsTest {
}
@Test
public void testDiff_EmptyList() {
public void testDiff_EmptyList() throws DiffException {
final Patch<String> patch = DiffUtils.diff(new ArrayList<>(), new ArrayList<>());
assertNotNull(patch);
assertEquals(0, patch.getDeltas().size());
}
@Test
public void testDiff_EmptyListWithNonEmpty() {
public void testDiff_EmptyListWithNonEmpty() throws DiffException {
final Patch<String> patch = DiffUtils.diff(new ArrayList<>(), Arrays.asList("aaa"));
assertNotNull(patch);
assertEquals(1, patch.getDeltas().size());
@@ -73,7 +74,7 @@ public class DiffUtilsTest {
}
@Test
public void testDiffInline() {
public void testDiffInline() throws DiffException {
final Patch<String> patch = DiffUtils.diffInline("", "test");
assertEquals(1, patch.getDeltas().size());
assertTrue(patch.getDeltas().get(0) instanceof InsertDelta);
@@ -83,7 +84,7 @@ public class DiffUtilsTest {
}
@Test
public void testDiffInline2() {
public void testDiffInline2() throws DiffException {
final Patch<String> patch = DiffUtils.diffInline("es", "fest");
assertEquals(2, patch.getDeltas().size());
assertTrue(patch.getDeltas().get(0) instanceof InsertDelta);

View File

@@ -1,6 +1,7 @@
package diffutils;
import difflib.DiffUtils;
import difflib.algorithm.DiffException;
import difflib.patch.Patch;
import difflib.patch.PatchFailedException;
import java.io.BufferedReader;
@@ -42,7 +43,7 @@ public class GenerateUnifiedDiffTest {
}
@Test
public void testGenerateUnified() {
public void testGenerateUnified() throws DiffException {
List<String> origLines = fileToLines(TestConstants.MOCK_FOLDER + "original.txt");
List<String> revLines = fileToLines(TestConstants.MOCK_FOLDER + "revised.txt");
@@ -50,7 +51,7 @@ public class GenerateUnifiedDiffTest {
}
@Test
public void testGenerateUnifiedWithOneDelta() {
public void testGenerateUnifiedWithOneDelta() throws DiffException {
List<String> origLines = fileToLines(TestConstants.MOCK_FOLDER + "one_delta_test_original.txt");
List<String> revLines = fileToLines(TestConstants.MOCK_FOLDER + "one_delta_test_revised.txt");
@@ -58,7 +59,7 @@ public class GenerateUnifiedDiffTest {
}
@Test
public void testGenerateUnifiedDiffWithoutAnyDeltas() {
public void testGenerateUnifiedDiffWithoutAnyDeltas() throws DiffException {
List<String> test = Arrays.asList("abc");
Patch<String> patch = DiffUtils.diff(test, test);
DiffUtils.generateUnifiedDiff("abc", "abc", test, patch, 0);
@@ -80,14 +81,14 @@ public class GenerateUnifiedDiffTest {
* Issue 12
*/
@Test
public void testPatchWithNoDeltas() {
public void testPatchWithNoDeltas() throws DiffException {
final List<String> lines1 = fileToLines(TestConstants.MOCK_FOLDER + "issue11_1.txt");
final List<String> lines2 = fileToLines(TestConstants.MOCK_FOLDER + "issue11_2.txt");
verify(lines1, lines2, "issue11_1.txt", "issue11_2.txt");
}
@Test
public void testDiff5() {
public void testDiff5() throws DiffException {
final List<String> lines1 = fileToLines(TestConstants.MOCK_FOLDER + "5A.txt");
final List<String> lines2 = fileToLines(TestConstants.MOCK_FOLDER + "5B.txt");
verify(lines1, lines2, "5A.txt", "5B.txt");
@@ -97,7 +98,7 @@ public class GenerateUnifiedDiffTest {
* Issue 19
*/
@Test
public void testDiffWithHeaderLineInText() {
public void testDiffWithHeaderLineInText() throws DiffException {
List<String> original = new ArrayList<>();
List<String> revised = new ArrayList<>();
@@ -119,7 +120,7 @@ public class GenerateUnifiedDiffTest {
}
private void verify(List<String> origLines, List<String> revLines,
String originalFile, String revisedFile) {
String originalFile, String revisedFile) throws DiffException {
Patch<String> patch = DiffUtils.diff(origLines, revLines);
List<String> unifiedDiff = DiffUtils.generateUnifiedDiff(originalFile, revisedFile,
origLines, patch, 10);

View File

@@ -1,6 +1,7 @@
package diffutils.patch;
import difflib.DiffUtils;
import difflib.algorithm.DiffException;
import difflib.patch.Patch;
import difflib.patch.PatchFailedException;
import java.util.Arrays;
@@ -12,7 +13,7 @@ import org.junit.Test;
public class PatchTest {
@Test
public void testPatch_Insert() {
public void testPatch_Insert() throws DiffException {
final List<String> insertTest_from = Arrays.asList("hhh");
final List<String> insertTest_to = Arrays.asList("hhh", "jjj", "kkk", "lll");
@@ -25,7 +26,7 @@ public class PatchTest {
}
@Test
public void testPatch_Delete() {
public void testPatch_Delete() throws DiffException {
final List<String> deleteTest_from = Arrays.asList("ddd", "fff", "ggg", "hhh");
final List<String> deleteTest_to = Arrays.asList("ggg");
@@ -38,7 +39,7 @@ public class PatchTest {
}
@Test
public void testPatch_Change() {
public void testPatch_Change() throws DiffException {
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");

View File

@@ -1,5 +1,6 @@
package diffutils.rows;
import difflib.algorithm.DiffException;
import difflib.text.DiffRow;
import difflib.text.DiffRowGenerator;
import java.util.Arrays;
@@ -11,7 +12,7 @@ import org.junit.Test;
public class DiffRowGeneratorTest {
@Test
public void testGenerator_Default() {
public void testGenerator_Default() throws DiffException {
String first = "anything \n \nother";
String second = "anything\n\nother";
@@ -25,7 +26,7 @@ public class DiffRowGeneratorTest {
}
@Test
public void testGenerator_InlineDiff() {
public void testGenerator_InlineDiff() throws DiffException {
String first = "anything \n \nother";
String second = "anything\n\nother";
@@ -41,7 +42,7 @@ public class DiffRowGeneratorTest {
}
@Test
public void testGenerator_IgnoreWhitespaces() {
public void testGenerator_IgnoreWhitespaces() throws DiffException {
String first = "anything \n \nother\nmore lines";
String second = "anything\n\nother\nsome more lines";