Skip to content

Commit 26c3615

Browse files
committed
1 parent 3b8c271 commit 26c3615

File tree

2 files changed

+12
-25
lines changed

2 files changed

+12
-25
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Diff Utils library is an OpenSource library for performing the comparison operat
33

44
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.
55

6-
This is originally a fork of java-diff-utils from Google Code Archive.
6+
**This is originally a fork of java-diff-utils from Google Code Archive.**
77

88
## Main Features ##
99

@@ -12,6 +12,7 @@ This is originally a fork of java-diff-utils from Google Code Archive.
1212
* patch and unpatch the text with the given patch
1313
* parsing the unified diff format
1414
* producing human-readable differences
15+
* inline difference construction
1516

1617
### Algoritms ###
1718

@@ -20,7 +21,7 @@ This library implements Myer's diff algorithm. But it can easily replaced by any
2021
### Changelog ###
2122
* Version 1.4
2223
* switch to maven and removed other artifacts
23-
* changed groupid to *com.github.java-diff-utils* due to different forks at github
24+
* changed groupid to **com.github.java-diff-utils** due to different forks at github
2425
* updated maven plugins
2526
* JDK 1.8 compatibility
2627
* support for inline merge

src/test/java/difflib/GenerateUnifiedDiffTest.java

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,39 @@
44
import difflib.patch.Patch;
55
import difflib.patch.PatchFailedException;
66
import java.io.BufferedReader;
7+
import java.io.FileNotFoundException;
78
import java.io.FileReader;
89
import java.io.IOException;
910
import java.util.ArrayList;
1011
import java.util.Arrays;
11-
import java.util.LinkedList;
1212
import java.util.List;
1313
import static org.junit.Assert.assertTrue;
1414
import static org.junit.Assert.fail;
1515
import org.junit.Test;
1616

1717
public class GenerateUnifiedDiffTest {
1818

19-
public List<String> fileToLines(String filename) {
20-
List<String> lines = new LinkedList<>();
19+
private static List<String> fileToLines(String filename) throws FileNotFoundException, IOException {
20+
List<String> lines = new ArrayList<>();
2121
String line = "";
22-
BufferedReader in = null;
23-
try {
24-
in = new BufferedReader(new FileReader(filename));
22+
try (BufferedReader in = new BufferedReader(new FileReader(filename))) {
2523
while ((line = in.readLine()) != null) {
2624
lines.add(line);
2725
}
28-
} catch (IOException e) {
29-
e.printStackTrace();
30-
fail(e.getMessage());
31-
} finally {
32-
if (in != null) {
33-
try {
34-
in.close();
35-
} catch (IOException e) {
36-
// ignore ... any errors should already have been
37-
// reported via an IOException from the final flush.
38-
}
39-
}
4026
}
4127
return lines;
4228
}
4329

4430
@Test
45-
public void testGenerateUnified() throws DiffException {
31+
public void testGenerateUnified() throws DiffException, IOException {
4632
List<String> origLines = fileToLines(TestConstants.MOCK_FOLDER + "original.txt");
4733
List<String> revLines = fileToLines(TestConstants.MOCK_FOLDER + "revised.txt");
4834

4935
verify(origLines, revLines, "original.txt", "revised.txt");
5036
}
5137

5238
@Test
53-
public void testGenerateUnifiedWithOneDelta() throws DiffException {
39+
public void testGenerateUnifiedWithOneDelta() throws DiffException, IOException {
5440
List<String> origLines = fileToLines(TestConstants.MOCK_FOLDER + "one_delta_test_original.txt");
5541
List<String> revLines = fileToLines(TestConstants.MOCK_FOLDER + "one_delta_test_revised.txt");
5642

@@ -65,7 +51,7 @@ public void testGenerateUnifiedDiffWithoutAnyDeltas() throws DiffException {
6551
}
6652

6753
@Test
68-
public void testDiff_Issue10() {
54+
public void testDiff_Issue10() throws IOException {
6955
final List<String> baseLines = fileToLines(TestConstants.MOCK_FOLDER + "issue10_base.txt");
7056
final List<String> patchLines = fileToLines(TestConstants.MOCK_FOLDER + "issue10_patch.txt");
7157
final Patch<String> p = DiffUtils.parseUnifiedDiff(patchLines);
@@ -80,14 +66,14 @@ public void testDiff_Issue10() {
8066
* Issue 12
8167
*/
8268
@Test
83-
public void testPatchWithNoDeltas() throws DiffException {
69+
public void testPatchWithNoDeltas() throws DiffException, IOException {
8470
final List<String> lines1 = fileToLines(TestConstants.MOCK_FOLDER + "issue11_1.txt");
8571
final List<String> lines2 = fileToLines(TestConstants.MOCK_FOLDER + "issue11_2.txt");
8672
verify(lines1, lines2, "issue11_1.txt", "issue11_2.txt");
8773
}
8874

8975
@Test
90-
public void testDiff5() throws DiffException {
76+
public void testDiff5() throws DiffException, IOException {
9177
final List<String> lines1 = fileToLines(TestConstants.MOCK_FOLDER + "5A.txt");
9278
final List<String> lines2 = fileToLines(TestConstants.MOCK_FOLDER + "5B.txt");
9379
verify(lines1, lines2, "5A.txt", "5B.txt");

0 commit comments

Comments
 (0)