comparison test/org/tmatesoft/hg/test/TestRevert.java @ 536:2813a26b8999

Tests: refactor various utility methods to a single location
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 05 Feb 2013 16:36:58 +0100
parents 95bdcf75e71e
children 6ca3d0c5b4bc
comparison
equal deleted inserted replaced
535:d9c07e1432c4 536:2813a26b8999
15 * contact TMate Software at support@hg4j.com 15 * contact TMate Software at support@hg4j.com
16 */ 16 */
17 package org.tmatesoft.hg.test; 17 package org.tmatesoft.hg.test;
18 18
19 import static org.junit.Assert.assertEquals; 19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertTrue;
21 20
22 import java.io.File; 21 import java.io.File;
23 import java.io.FileOutputStream;
24 import java.io.IOException;
25 import java.util.ArrayList;
26 22
27 import org.junit.Rule; 23 import org.junit.Rule;
28 import org.junit.Test; 24 import org.junit.Test;
29 import org.tmatesoft.hg.core.HgRevertCommand; 25 import org.tmatesoft.hg.core.HgRevertCommand;
30 import org.tmatesoft.hg.repo.HgLookup; 26 import org.tmatesoft.hg.repo.HgLookup;
50 } 46 }
51 47
52 @Test 48 @Test
53 public void testCommand() throws Exception { 49 public void testCommand() throws Exception {
54 // get a copy of a repository 50 // get a copy of a repository
55 File testRepoLoc = cloneRepoToTempLocation(Configuration.get().find("log-1"), "test-revert", false); 51 File testRepoLoc = RepoUtils.cloneRepoToTempLocation(Configuration.get().find("log-1"), "test-revert", false);
56 52
57 repo = new HgLookup().detect(testRepoLoc); 53 repo = new HgLookup().detect(testRepoLoc);
58 Path targetFile = Path.create("b"); 54 Path targetFile = Path.create("b");
59 modifyFileAppend(new File(testRepoLoc, targetFile.toString())); 55 RepoUtils.modifyFileAppend(new File(testRepoLoc, targetFile.toString()));
60 56
61 StatusOutputParser statusParser = new StatusOutputParser(); 57 StatusOutputParser statusParser = new StatusOutputParser();
62 eh = new ExecHelper(statusParser, testRepoLoc); 58 eh = new ExecHelper(statusParser, testRepoLoc);
63 eh.run("hg", "status", "-A"); 59 eh.run("hg", "status", "-A");
64 assertEquals("[sanity]", 1, statusParser.getModified().size()); 60 assertEquals("[sanity]", 1, statusParser.getModified().size());
73 errorCollector.assertEquals(3, statusParser.getClean().size()); 69 errorCollector.assertEquals(3, statusParser.getClean().size());
74 errorCollector.assertTrue(statusParser.getClean().contains(targetFile)); 70 errorCollector.assertTrue(statusParser.getClean().contains(targetFile));
75 errorCollector.assertEquals(1, statusParser.getUnknown().size()); 71 errorCollector.assertEquals(1, statusParser.getUnknown().size());
76 errorCollector.assertEquals(targetFile.toString() + ".orig", statusParser.getUnknown().get(0).toString()); 72 errorCollector.assertEquals(targetFile.toString() + ".orig", statusParser.getUnknown().get(0).toString());
77 } 73 }
78
79 private static void modifyFileAppend(File f) throws IOException {
80 assertTrue(f.isFile());
81 FileOutputStream fos = new FileOutputStream(f, true);
82 fos.write("XXX".getBytes());
83 fos.close();
84 }
85
86 static File cloneRepoToTempLocation(String configRepoName, String name, boolean noupdate) throws Exception, InterruptedException {
87 return cloneRepoToTempLocation(Configuration.get().find(configRepoName), name, noupdate);
88 }
89
90 static File cloneRepoToTempLocation(HgRepository repo, String name, boolean noupdate) throws IOException, InterruptedException {
91 File testRepoLoc = TestIncoming.createEmptyDir(name);
92 ExecHelper eh = new ExecHelper(new OutputParser.Stub(), testRepoLoc.getParentFile());
93 ArrayList<String> cmd = new ArrayList<String>();
94 cmd.add("hg"); cmd.add("clone");
95 if (noupdate) {
96 cmd.add("--noupdate");
97 }
98 cmd.add(repo.getWorkingDir().toString());
99 cmd.add(testRepoLoc.getName());
100 eh.run(cmd.toArray(new String[cmd.size()]));
101 assertEquals("[sanity]", 0, eh.getExitValue());
102 return testRepoLoc;
103 }
104 } 74 }