From 26c361565edd426e5f4dd9a328d9a358ff792847 Mon Sep 17 00:00:00 2001 From: wumpz Date: Mon, 10 Apr 2017 17:10:28 +0200 Subject: [PATCH] --- README.md | 5 +-- .../java/difflib/GenerateUnifiedDiffTest.java | 32 ++++++------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 70a75dc..043eae4 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Diff Utils library is an OpenSource library for performing the comparison operat Main reason to build this library was the lack of easy-to-use libraries with all the usual stuff you need while working with diff files. Originally it was inspired by JRCS library and it's nice design of diff module. -This is originally a fork of java-diff-utils from Google Code Archive. +**This is originally a fork of java-diff-utils from Google Code Archive.** ## Main Features ## @@ -12,6 +12,7 @@ This is originally a fork of java-diff-utils from Google Code Archive. * patch and unpatch the text with the given patch * parsing the unified diff format * producing human-readable differences + * inline difference construction ### Algoritms ### @@ -20,7 +21,7 @@ This library implements Myer's diff algorithm. But it can easily replaced by any ### Changelog ### * Version 1.4 * switch to maven and removed other artifacts - * changed groupid to *com.github.java-diff-utils* due to different forks at github + * changed groupid to **com.github.java-diff-utils** due to different forks at github * updated maven plugins * JDK 1.8 compatibility * support for inline merge diff --git a/src/test/java/difflib/GenerateUnifiedDiffTest.java b/src/test/java/difflib/GenerateUnifiedDiffTest.java index fe8bcc4..6f70563 100644 --- a/src/test/java/difflib/GenerateUnifiedDiffTest.java +++ b/src/test/java/difflib/GenerateUnifiedDiffTest.java @@ -4,11 +4,11 @@ import difflib.algorithm.DiffException; import difflib.patch.Patch; import difflib.patch.PatchFailedException; import java.io.BufferedReader; +import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.LinkedList; import java.util.List; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -16,33 +16,19 @@ import org.junit.Test; public class GenerateUnifiedDiffTest { - public List fileToLines(String filename) { - List lines = new LinkedList<>(); + private static List fileToLines(String filename) throws FileNotFoundException, IOException { + List lines = new ArrayList<>(); String line = ""; - BufferedReader in = null; - try { - in = new BufferedReader(new FileReader(filename)); + try (BufferedReader in = new BufferedReader(new FileReader(filename))) { while ((line = in.readLine()) != null) { lines.add(line); } - } catch (IOException e) { - e.printStackTrace(); - fail(e.getMessage()); - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException e) { - // ignore ... any errors should already have been - // reported via an IOException from the final flush. - } - } } return lines; } @Test - public void testGenerateUnified() throws DiffException { + public void testGenerateUnified() throws DiffException, IOException { List origLines = fileToLines(TestConstants.MOCK_FOLDER + "original.txt"); List revLines = fileToLines(TestConstants.MOCK_FOLDER + "revised.txt"); @@ -50,7 +36,7 @@ public class GenerateUnifiedDiffTest { } @Test - public void testGenerateUnifiedWithOneDelta() throws DiffException { + public void testGenerateUnifiedWithOneDelta() throws DiffException, IOException { List origLines = fileToLines(TestConstants.MOCK_FOLDER + "one_delta_test_original.txt"); List revLines = fileToLines(TestConstants.MOCK_FOLDER + "one_delta_test_revised.txt"); @@ -65,7 +51,7 @@ public class GenerateUnifiedDiffTest { } @Test - public void testDiff_Issue10() { + public void testDiff_Issue10() throws IOException { final List baseLines = fileToLines(TestConstants.MOCK_FOLDER + "issue10_base.txt"); final List patchLines = fileToLines(TestConstants.MOCK_FOLDER + "issue10_patch.txt"); final Patch p = DiffUtils.parseUnifiedDiff(patchLines); @@ -80,14 +66,14 @@ public class GenerateUnifiedDiffTest { * Issue 12 */ @Test - public void testPatchWithNoDeltas() throws DiffException { + public void testPatchWithNoDeltas() throws DiffException, IOException { final List lines1 = fileToLines(TestConstants.MOCK_FOLDER + "issue11_1.txt"); final List lines2 = fileToLines(TestConstants.MOCK_FOLDER + "issue11_2.txt"); verify(lines1, lines2, "issue11_1.txt", "issue11_2.txt"); } @Test - public void testDiff5() throws DiffException { + public void testDiff5() throws DiffException, IOException { final List lines1 = fileToLines(TestConstants.MOCK_FOLDER + "5A.txt"); final List lines2 = fileToLines(TestConstants.MOCK_FOLDER + "5B.txt"); verify(lines1, lines2, "5A.txt", "5B.txt");