674835517c0c434e05468ae579b4069c2f837f37
[idea/community.git] / plugins / hg4idea / testSrc / org / zmlx / hg4idea / test / HgRevertTestCase.java
1 package org.zmlx.hg4idea.test;
2
3 import org.testng.annotations.Test;
4 import org.zmlx.hg4idea.HgRevisionNumber;
5 import org.zmlx.hg4idea.command.HgCatCommand;
6 import org.zmlx.hg4idea.command.HgRevertCommand;
7
8 import java.nio.charset.Charset;
9
10 import static org.testng.Assert.assertEquals;
11
12 public class HgRevertTestCase extends HgAbstractTestCase {
13   @Test
14   public void testRevertToCurrentRevision() throws Exception {
15     fillFile(myProjectRepo, new String[]{"file.txt"}, "initial contents");
16     runHgOnProjectRepo("add", ".");
17     runHgOnProjectRepo("commit", "-m", "initial contents");
18
19     fillFile(myProjectRepo, new String[]{"file.txt"}, "new contents");
20
21     HgRevertCommand revertCommand = new HgRevertCommand(myProject);
22     revertCommand.execute(getHgFile("file.txt"), null, false);
23
24     HgCatCommand catCommand = new HgCatCommand(myProject);
25     String content = catCommand.execute(getHgFile("file.txt"), null, Charset.defaultCharset());
26
27     assertEquals(content, "initial contents");
28   }
29
30
31   @Test
32   public void testRevertToGivenRevision() throws Exception {
33     fillFile(myProjectRepo, new String[]{"file.txt"}, "initial contents");
34     runHgOnProjectRepo("add", ".");
35     runHgOnProjectRepo("commit", "-m", "initial contents");
36
37     fillFile(myProjectRepo, new String[]{"file.txt"}, "new contents");
38     runHgOnProjectRepo("commit", "-m", "new contents");
39
40     HgRevertCommand revertCommand = new HgRevertCommand(myProject);
41     revertCommand.execute(getHgFile("file.txt"), HgRevisionNumber.getLocalInstance("0"), false);
42
43     HgCatCommand catCommand = new HgCatCommand(myProject);
44     String content = catCommand.execute(getHgFile("file.txt"), HgRevisionNumber.getLocalInstance("0"), Charset.defaultCharset());
45
46     assertEquals(content, "initial contents");
47   }
48
49 }