IDEA-68731 Batch process hg revert and hg resolve. Get rid of HgFile.
[idea/community.git] / plugins / hg4idea / testSrc / org / zmlx / hg4idea / test / HgRevertTest.java
1 package org.zmlx.hg4idea.test;
2
3 import com.intellij.vcsUtil.VcsUtil;
4 import org.testng.annotations.Test;
5 import org.zmlx.hg4idea.HgRevisionNumber;
6 import org.zmlx.hg4idea.command.HgCatCommand;
7 import org.zmlx.hg4idea.command.HgRevertCommand;
8
9 import java.io.File;
10 import java.nio.charset.Charset;
11 import java.util.Collections;
12
13 import static org.testng.Assert.assertEquals;
14
15 public class HgRevertTest extends HgSingleUserTest {
16   @Test
17   public void testRevertToCurrentRevision() throws Exception {
18     fillFile(myProjectDir, new String[]{"file.txt"}, "initial contents");
19     runHgOnProjectRepo("add", ".");
20     runHgOnProjectRepo("commit", "-m", "initial contents");
21
22     fillFile(myProjectDir, new String[]{"file.txt"}, "new contents");
23
24     HgRevertCommand revertCommand = new HgRevertCommand(myProject);
25     revertCommand.execute(myRepo.getDir(), Collections.singleton(VcsUtil.getFilePath(new File(myProjectDir, "file.txt"))), null, false);
26
27     HgCatCommand catCommand = new HgCatCommand(myProject);
28     String content = catCommand.execute(getHgFile("file.txt"), null, Charset.defaultCharset());
29
30     assertEquals(content, "initial contents");
31   }
32
33
34   @Test
35   public void testRevertToGivenRevision() throws Exception {
36     fillFile(myProjectDir, new String[]{"file.txt"}, "initial contents");
37     runHgOnProjectRepo("add", ".");
38     runHgOnProjectRepo("commit", "-m", "initial contents");
39
40     fillFile(myProjectDir, new String[]{"file.txt"}, "new contents");
41     runHgOnProjectRepo("commit", "-m", "new contents");
42
43     HgRevertCommand revertCommand = new HgRevertCommand(myProject);
44     revertCommand.execute(myRepo.getDir(), Collections.singleton(VcsUtil.getFilePath(new File(myProjectDir, "file.txt"))), HgRevisionNumber.getLocalInstance("0"), false);
45
46     HgCatCommand catCommand = new HgCatCommand(myProject);
47     String content = catCommand.execute(getHgFile("file.txt"), HgRevisionNumber.getLocalInstance("0"), Charset.defaultCharset());
48
49     assertEquals(content, "initial contents");
50   }
51
52 }