refactored to junit4 annotations

This commit is contained in:
wumpz
2017-03-30 13:02:30 +02:00
parent e76c9ff1d3
commit cc585e2e97
4 changed files with 34 additions and 8 deletions

View File

@@ -4,10 +4,13 @@ import difflib.DiffRow;
import difflib.DiffRowGenerator;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class DiffRowGeneratorTest extends TestCase {
public class DiffRowGeneratorTest {
@Test
public void testGenerator_Default() {
String first = "anything \n \nother";
String second ="anything\n\nother";
@@ -21,6 +24,7 @@ public class DiffRowGeneratorTest extends TestCase {
assertEquals(3, rows.size());
}
@Test
public void testGenerator_InlineDiff() {
String first = "anything \n \nother";
String second ="anything\n\nother";
@@ -36,6 +40,7 @@ public class DiffRowGeneratorTest extends TestCase {
assertTrue(rows.get(0).getOldLine().indexOf("<span") > 0);
}
@Test
public void testGenerator_IgnoreWhitespaces() {
String first = "anything \n \nother\nmore lines";
String second ="anything\n\nother\nsome more lines";

View File

@@ -5,10 +5,13 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
public class DiffTest extends TestCase {
public class DiffTest {
@Test
public void testDiff_Insert() {
final Patch<String> patch = DiffUtils.diff(Arrays.asList("hhh"), Arrays.asList("hhh", "jjj", "kkk"));
assertNotNull(patch);
@@ -19,6 +22,7 @@ public class DiffTest extends TestCase {
assertEquals(new Chunk<String>(1, Arrays.asList("jjj", "kkk")), delta.getRevised());
}
@Test
public void testDiff_Delete() {
final Patch<String> patch = DiffUtils.diff(Arrays.asList("ddd", "fff", "ggg"), Arrays.asList("ggg"));
assertNotNull(patch);
@@ -29,6 +33,7 @@ public class DiffTest extends TestCase {
assertEquals(new Chunk<String>(0, Collections.<String> emptyList()), delta.getRevised());
}
@Test
public void testDiff_Change() {
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc");
final List<String> changeTest_to = Arrays.asList("aaa", "zzz", "ccc");
@@ -42,12 +47,14 @@ public class DiffTest extends TestCase {
assertEquals(new Chunk<String>(1, Arrays.asList("zzz")), delta.getRevised());
}
@Test
public void testDiff_EmptyList() {
final Patch<String> patch = DiffUtils.diff(new ArrayList<String>(), new ArrayList<String>());
assertNotNull(patch);
assertEquals(0, patch.getDeltas().size());
}
@Test
public void testDiff_EmptyListWithNonEmpty() {
final Patch<String> patch = DiffUtils.diff(new ArrayList<String>(), Arrays.asList("aaa"));
assertNotNull(patch);

View File

@@ -10,9 +10,11 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import junit.framework.TestCase;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;
public class GenerateUnifiedDiffTest extends TestCase {
public class GenerateUnifiedDiffTest {
public List<String> fileToLines(String filename) {
@@ -40,6 +42,7 @@ public class GenerateUnifiedDiffTest extends TestCase {
return lines;
}
@Test
public void testGenerateUnified() {
List<String> origLines = fileToLines(TestConstants.MOCK_FOLDER + "original.txt");
List<String> revLines = fileToLines(TestConstants.MOCK_FOLDER + "revised.txt");
@@ -47,6 +50,7 @@ public class GenerateUnifiedDiffTest extends TestCase {
verify(origLines, revLines, "original.txt", "revised.txt");
}
@Test
public void testGenerateUnifiedWithOneDelta() {
List<String> origLines = fileToLines(TestConstants.MOCK_FOLDER + "one_delta_test_original.txt");
List<String> revLines = fileToLines(TestConstants.MOCK_FOLDER + "one_delta_test_revised.txt");
@@ -54,12 +58,14 @@ public class GenerateUnifiedDiffTest extends TestCase {
verify(origLines, revLines, "one_delta_test_original.txt", "one_delta_test_revised.txt");
}
@Test
public void testGenerateUnifiedDiffWithoutAnyDeltas() {
List<String> test = Arrays.asList("abc");
Patch<String> patch = DiffUtils.diff(test, test);
DiffUtils.generateUnifiedDiff("abc", "abc", test, patch, 0);
}
@Test
public void testDiff_Issue10() {
final List<String> baseLines = fileToLines(TestConstants.MOCK_FOLDER + "issue10_base.txt");
final List<String> patchLines = fileToLines(TestConstants.MOCK_FOLDER + "issue10_patch.txt");
@@ -74,12 +80,14 @@ public class GenerateUnifiedDiffTest extends TestCase {
/**
* Issue 12
*/
@Test
public void testPatchWithNoDeltas() {
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() {
final List<String> lines1 = fileToLines(TestConstants.MOCK_FOLDER + "5A.txt");
final List<String> lines2 = fileToLines(TestConstants.MOCK_FOLDER + "5B.txt");
@@ -89,6 +97,7 @@ public class GenerateUnifiedDiffTest extends TestCase {
/**
* Issue 19
*/
@Test
public void testDiffWithHeaderLineInText() {
List<String> original = new ArrayList<String>();
List<String> revised = new ArrayList<String>();

View File

@@ -5,10 +5,13 @@ import difflib.Patch;
import difflib.PatchFailedException;
import java.util.Arrays;
import java.util.List;
import junit.framework.TestCase;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Test;
public class PatchTest extends TestCase {
public class PatchTest {
@Test
public void testPatch_Insert() {
final List<String> insertTest_from = Arrays.asList("hhh");
final List<String> insertTest_to = Arrays.asList("hhh", "jjj", "kkk", "lll");
@@ -21,6 +24,7 @@ public class PatchTest extends TestCase {
}
}
@Test
public void testPatch_Delete() {
final List<String> deleteTest_from = Arrays.asList("ddd", "fff", "ggg", "hhh");
final List<String> deleteTest_to = Arrays.asList("ggg");
@@ -33,6 +37,7 @@ public class PatchTest extends TestCase {
}
}
@Test
public void testPatch_Change() {
final List<String> changeTest_from = Arrays.asList("aaa", "bbb", "ccc", "ddd");
final List<String> changeTest_to = Arrays.asList("aaa", "bxb", "cxc", "ddd");