[Mercurial Tests] Renamed AbstractHgTestCase to HgAbstractTestCase for unification.
[idea/community.git] / plugins / hg4idea / testSrc / org / zmlx / hg4idea / test / HgRenameTestCase.java
1 // Copyright 2008-2010 Victor Iacoban
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software distributed under
10 // the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
11 // either express or implied. See the License for the specific language governing permissions and
12 // limitations under the License.
13 package org.zmlx.hg4idea.test;
14
15 import com.intellij.openapi.vfs.VirtualFile;
16 import org.testng.annotations.Test;
17
18 import java.io.File;
19
20 public class HgRenameTestCase extends HgAbstractTestCase {
21
22   @Test
23   public void testRenameUnmodifiedFile() throws Exception {
24     VirtualFile file = createFileInCommand("a.txt", "new file content");
25     runHgOnProjectRepo("commit", "-m", "added file");
26     renameFileInCommand(file, "b.txt");
27     verify(runHgOnProjectRepo("status"), added("b.txt"), removed("a.txt"));
28   }
29
30   @Test
31   public void testRenameModifiedFile() throws Exception {
32     VirtualFile file = createFileInCommand("a.txt", "new file content");
33     runHgOnProjectRepo("commit", "-m", "added file");
34     editFileInCommand(myProject, file, "modified new file content");
35     verify(runHgOnProjectRepo("status"), modified("a.txt"));
36     renameFileInCommand(file, "b.txt");
37     verify(runHgOnProjectRepo("status"), added("b.txt"), removed("a.txt"));
38   }
39
40   @Test
41   public void testRenameNewFile() throws Exception {
42     VirtualFile file = createFileInCommand("a.txt", "new file content");
43     renameFileInCommand(file, "b.txt");
44     verify(runHgOnProjectRepo("status"), added("b.txt"));
45   }
46
47   @Test
48   public void testRenameRenamedFile() throws Exception {
49     VirtualFile file = createFileInCommand("a.txt", "new file content");
50     runHgOnProjectRepo("commit", "-m", "added file");
51     renameFileInCommand(file, "b.txt");
52     renameFileInCommand(file, "c.txt");
53     verify(runHgOnProjectRepo("status"), added("c.txt"), removed("a.txt"));
54   }
55
56   @Test
57   public void testRenameVersionedFolder() throws Exception {
58     VirtualFile parent = createDirInCommand(myWorkingCopyDir, "com");
59     createFileInCommand(parent, "a.txt", "new file content");
60     runHgOnProjectRepo("commit", "-m", "added file");
61     renameFileInCommand(parent, "org");
62     verify(runHgOnProjectRepo("status"), added("org", "a.txt"), removed("com", "a.txt"));
63   }
64
65   @Test
66   public void testRenameUnversionedFolder() throws Exception {
67     VirtualFile parent = createDirInCommand(myWorkingCopyDir, "com");
68
69     File unversionedFile = new File(parent.getPath(), "a.txt");
70     makeFile(unversionedFile);
71     verify(runHgOnProjectRepo("status"), unknown("com", "a.txt"));
72
73     renameFileInCommand(parent, "org");
74     verify(runHgOnProjectRepo("status"), unknown("org", "a.txt"));
75   }
76
77   @Test
78   public void testRenameUnversionedFile() throws Exception {
79     File unversionedFile = new File(myWorkingCopyDir.getPath(), "a.txt");
80     VirtualFile file = makeFile(unversionedFile);
81     verify(runHgOnProjectRepo("status"), unknown("a.txt"));
82
83     renameFileInCommand(file, "b.txt");
84     verify(runHgOnProjectRepo("status"), unknown("b.txt"));
85   }
86
87 }