Mercurial > hg4j
comparison test/org/tmatesoft/hg/test/TestRevert.java @ 526:2f9ed6bcefa2
Initial support for Revert command with accompanying minor refactoring
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Tue, 15 Jan 2013 17:07:19 +0100 |
parents | |
children | 47b7bedf0569 |
comparison
equal
deleted
inserted
replaced
525:0be5be8d57e9 | 526:2f9ed6bcefa2 |
---|---|
1 /* | |
2 * Copyright (c) 2013 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.test; | |
18 | |
19 import static org.junit.Assert.assertEquals; | |
20 import static org.junit.Assert.assertTrue; | |
21 | |
22 import java.io.File; | |
23 import java.io.FileOutputStream; | |
24 | |
25 import org.junit.Rule; | |
26 import org.junit.Test; | |
27 import org.tmatesoft.hg.core.HgRevertCommand; | |
28 import org.tmatesoft.hg.repo.HgLookup; | |
29 import org.tmatesoft.hg.repo.HgRepository; | |
30 import org.tmatesoft.hg.util.Path; | |
31 | |
32 | |
33 /** | |
34 * | |
35 * @author Artem Tikhomirov | |
36 * @author TMate Software Ltd. | |
37 */ | |
38 public class TestRevert { | |
39 | |
40 @Rule | |
41 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | |
42 private HgRepository repo; | |
43 private ExecHelper eh; | |
44 | |
45 | |
46 public TestRevert() { | |
47 } | |
48 | |
49 @Test | |
50 public void testCommand() throws Exception { | |
51 File tmpDir = Configuration.get().getTempDir(); | |
52 tmpDir.mkdirs(); | |
53 eh = new ExecHelper(new OutputParser.Stub(), tmpDir); | |
54 File testRepoLoc = TestIncoming.createEmptyDir("test-revert"); | |
55 // get a copy of a repository | |
56 eh.run("hg", "clone", Configuration.get().find("log-1").getWorkingDir().toString(), testRepoLoc.getName()); | |
57 assertEquals("[sanity]", 0, eh.getExitValue()); | |
58 | |
59 repo = new HgLookup().detect(testRepoLoc); | |
60 Path targetFile = Path.create("b"); | |
61 modifyFileAppend(new File(testRepoLoc, targetFile.toString())); | |
62 | |
63 StatusOutputParser statusParser = new StatusOutputParser(); | |
64 eh = new ExecHelper(statusParser, testRepoLoc); | |
65 eh.run("hg", "status", "-A"); | |
66 assertEquals("[sanity]", 1, statusParser.getModified().size()); | |
67 assertEquals("[sanity]", 2, statusParser.getClean().size()); | |
68 assertEquals("[sanity]", targetFile, statusParser.getModified().get(0)); | |
69 | |
70 HgRevertCommand cmd = new HgRevertCommand(repo); | |
71 cmd.file(targetFile).execute(); | |
72 statusParser.reset(); | |
73 eh.run("hg", "status", "-A"); | |
74 | |
75 assertEquals(3, statusParser.getClean().size()); | |
76 assertTrue(statusParser.getClean().contains(targetFile)); | |
77 assertEquals(1, statusParser.getUnknown().size()); | |
78 assertEquals(targetFile.toString() + ".orig", statusParser.getUnknown().get(0).toString()); | |
79 } | |
80 | |
81 private static void modifyFileAppend(File f) throws Exception { | |
82 assertTrue(f.isFile()); | |
83 FileOutputStream fos = new FileOutputStream(f, true); | |
84 fos.write("XXX".getBytes()); | |
85 fos.close(); | |
86 } | |
87 } |