-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDiffrTest.java
More file actions
95 lines (76 loc) · 3.32 KB
/
DiffrTest.java
File metadata and controls
95 lines (76 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package diffr.diff;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.common.io.LineProcessor;
import com.google.common.io.Resources;
import diffr.util.instruction.Instruction;
import diffr.util.instruction.InstructionComposer;
import diffr.util.instruction.InstructionParser;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
/**
* Tests {@link Diffr}.
*
* @author Sarina Gurung
* @author Jakub D Kozlowski
* @since 0.3
*/
public class DiffrTest {
private static final String DEFAULT_PROVIDER = "default-provider";
@DataProvider(name = "default-provider")
public Object[][] getFiles() throws URISyntaxException, IOException {
final List<Object[]> files = Lists.newArrayList();
final File originalDir = new File(Resources.getResource("original").toURI());
for (final File originalFile : originalDir.listFiles()) {
final File newFile = new File(Resources.getResource("new/" + originalFile.getName()).toURI());
final File patchFile = new File(Resources.getResource("patch/" + originalFile.getName()).toURI());
files.add(new Object[]{
Files.readLines(originalFile, Charset.defaultCharset()),
Files.readLines(newFile, Charset.defaultCharset()),
Files.readLines(patchFile, Charset.defaultCharset(), new LineProcessor<List<Instruction>>() {
private List<Instruction> instructions = Lists.newArrayList();
@Override
public boolean processLine(String s) throws IOException {
instructions.add(InstructionParser.parseInstruction(s).get());
return true;
}
@Override
public List<Instruction> getResult() {
return instructions;
}
})
});
}
return files.toArray(new Object[][]{});
}
@Test(expectedExceptions = NullPointerException.class)
public void testConstructorNullOriginalFile() {
new Diffr(null, Collections.EMPTY_LIST);
}
@Test(expectedExceptions = NullPointerException.class)
public void testConstructorNullNewFile() {
new Diffr(Collections.EMPTY_LIST, null);
}
@Test(dataProvider = DEFAULT_PROVIDER)
public void testDiff(final List<String> originalFile,
final List<String> newFile,
final List<Instruction> patchFile)
throws IOException, URISyntaxException {
final Diffr d = new Diffr(originalFile, newFile);
final Iterator<Instruction> actualInstructions = d.diff().iterator();
for (final Instruction expected : patchFile) {
final Instruction actual = actualInstructions.next();
assertThat(InstructionComposer.composeString(actual),
is(InstructionComposer.composeString(expected)));
}
}
}