mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs] TaskBranchTest refactoring: make blinked tests more stable
* thread leaks fixed; * remove unnecessary managers from test; * add commit author for hg; * cleanUP
This commit is contained in:
@@ -121,7 +121,7 @@ public abstract class HgPlatformTest extends VcsPlatformTest {
|
||||
hg("init");
|
||||
touch("file.txt");
|
||||
hg("add file.txt");
|
||||
hg("commit -m initial");
|
||||
hg("commit -m initial -u asd");
|
||||
}
|
||||
|
||||
public void prepareSecondRepository() throws IOException {
|
||||
|
||||
@@ -16,19 +16,20 @@
|
||||
package com.intellij.tasks.vcs;
|
||||
|
||||
import com.intellij.dvcs.repo.Repository;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import git4idea.branch.GitBranchesCollection;
|
||||
import git4idea.config.GitVcsSettings;
|
||||
import git4idea.repo.GitRepository;
|
||||
import git4idea.test.GitExecutor;
|
||||
import git4idea.test.GitTestUtil;
|
||||
import git4idea.util.GitFileUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.intellij.openapi.vcs.Executor.touch;
|
||||
import static git4idea.test.GitExecutor.git;
|
||||
|
||||
public class GitTaskBranchesTest extends TaskBranchesTest {
|
||||
|
||||
@@ -50,6 +51,14 @@ public class GitTaskBranchesTest extends TaskBranchesTest {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createAndCommitChanges(@NotNull Repository repository) throws IOException, VcsException {
|
||||
touch("foo.txt");
|
||||
git("add foo.txt");
|
||||
git("commit -m commit");
|
||||
repository.update();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getDefaultBranchName() {
|
||||
@@ -60,9 +69,4 @@ public class GitTaskBranchesTest extends TaskBranchesTest {
|
||||
protected int getNumberOfBranches(@NotNull Repository repository) {
|
||||
return ((GitRepository)repository).getBranches().getLocalBranches().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addFiles(@NotNull Project project, @NotNull VirtualFile root, @NotNull VirtualFile file) throws VcsException {
|
||||
GitFileUtils.addFiles(project, root, file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
package com.intellij.tasks.vcs;
|
||||
|
||||
import com.intellij.dvcs.repo.Repository;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.impl.ProjectLevelVcsManagerImpl;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -31,6 +31,7 @@ import org.zmlx.hg4idea.repo.HgRepository;
|
||||
import org.zmlx.hg4idea.util.HgUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static com.intellij.openapi.vcs.Executor.cd;
|
||||
import static com.intellij.openapi.vcs.Executor.touch;
|
||||
@@ -54,7 +55,7 @@ public class HgTaskBranchesTest extends TaskBranchesTest {
|
||||
HgPlatformTest.initRepo(root);
|
||||
touch("a.txt");
|
||||
hg("add a.txt");
|
||||
hg("commit -m another");
|
||||
hg("commit -m another -u abc");
|
||||
hg("up -r 0");
|
||||
ProjectLevelVcsManagerImpl vcsManager = (ProjectLevelVcsManagerImpl)ProjectLevelVcsManager.getInstance(myProject);
|
||||
vcsManager.setDirectoryMapping(root, HgVcs.VCS_NAME);
|
||||
@@ -64,6 +65,15 @@ public class HgTaskBranchesTest extends TaskBranchesTest {
|
||||
return repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createAndCommitChanges(@NotNull Repository repository) throws IOException, VcsException {
|
||||
cd(repository.getRoot());
|
||||
touch("foo.txt");
|
||||
hg("add foo.txt");
|
||||
hg("commit -m another -u abc");
|
||||
repository.update();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getDefaultBranchName() {
|
||||
@@ -77,10 +87,5 @@ public class HgTaskBranchesTest extends TaskBranchesTest {
|
||||
((HgRepository)repository).getBookmarks().size();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addFiles(@NotNull Project project, @NotNull VirtualFile root, @NotNull VirtualFile file) {
|
||||
cd(root);
|
||||
hg("add " + file.getPath());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,11 @@
|
||||
package com.intellij.tasks.vcs;
|
||||
|
||||
import com.intellij.dvcs.repo.Repository;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.VcsTaskHandler;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManager;
|
||||
import com.intellij.openapi.vcs.changes.ChangeListManagerImpl;
|
||||
import com.intellij.tasks.BranchInfo;
|
||||
import com.intellij.tasks.LocalTask;
|
||||
import com.intellij.tasks.TaskManager;
|
||||
@@ -31,26 +28,30 @@ import com.intellij.tasks.actions.OpenTaskDialog;
|
||||
import com.intellij.tasks.impl.LocalTaskImpl;
|
||||
import com.intellij.tasks.impl.TaskManagerImpl;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Dmitry Avdeev
|
||||
* Date: 18.07.13
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public abstract class TaskBranchesTest extends PlatformTestCase {
|
||||
|
||||
private TaskManagerImpl myTaskManager;
|
||||
private ChangeListManagerImpl myChangeListManager;
|
||||
private VcsDirtyScopeManagerImpl myDirtyScopeManager;
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
((ChangeListManagerImpl)ChangeListManager.getInstance(myProject)).waitEverythingDoneInTestMode();
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
public void testVcsTaskHandler() throws Exception {
|
||||
|
||||
@@ -86,7 +87,7 @@ public abstract class TaskBranchesTest extends PlatformTestCase {
|
||||
assertEquals(3, getNumberOfBranches(repository));
|
||||
assertEquals(second, repository.getCurrentBranchName());
|
||||
handler.switchToTask(firstInfo, null);
|
||||
commitChanges(repository);
|
||||
createAndCommitChanges(repository);
|
||||
handler.closeTask(secondInfo, firstInfo);
|
||||
repository.update();
|
||||
assertEquals(2, getNumberOfBranches(repository));
|
||||
@@ -116,7 +117,7 @@ public abstract class TaskBranchesTest extends PlatformTestCase {
|
||||
localTask = myTaskManager.activateTask(foo, false);
|
||||
myTaskManager.createBranch(localTask, defaultTask, myTaskManager.suggestBranchName(localTask));
|
||||
assertEquals("foo", repository.getCurrentBranchName());
|
||||
commitChanges(repository);
|
||||
createAndCommitChanges(repository);
|
||||
|
||||
myTaskManager.mergeBranch(localTask);
|
||||
repository.update();
|
||||
@@ -127,27 +128,13 @@ public abstract class TaskBranchesTest extends PlatformTestCase {
|
||||
myTaskManager.activateTask(foo, false);
|
||||
}
|
||||
|
||||
private void commitChanges(@NotNull Repository repository) throws IOException, VcsException {
|
||||
VirtualFile root = repository.getRoot();
|
||||
File file = new File(root.getPath(), "foo.txt");
|
||||
assertTrue(file.createNewFile());
|
||||
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
|
||||
addFiles(getProject(), root, virtualFile);
|
||||
myDirtyScopeManager.fileDirty(virtualFile);
|
||||
myChangeListManager.ensureUpToDate(false);
|
||||
Change change = myChangeListManager.getChange(virtualFile);
|
||||
assertNotNull(change);
|
||||
ProjectLevelVcsManager.getInstance(getProject()).getAllActiveVcss()[0].getCheckinEnvironment()
|
||||
.commit(Collections.singletonList(change), "foo");
|
||||
}
|
||||
|
||||
public void testCommit() throws Exception {
|
||||
Repository repository = initRepository("foo");
|
||||
LocalTask defaultTask = myTaskManager.getActiveTask();
|
||||
LocalTaskImpl foo = myTaskManager.createLocalTask("foo");
|
||||
final LocalTask localTask = myTaskManager.activateTask(foo, false);
|
||||
myTaskManager.createBranch(localTask, defaultTask, myTaskManager.suggestBranchName(localTask));
|
||||
commitChanges(repository);
|
||||
createAndCommitChanges(repository);
|
||||
myTaskManager.mergeBranch(localTask);
|
||||
repository.update();
|
||||
assertEquals(getDefaultBranchName(), repository.getCurrentBranchName());
|
||||
@@ -245,20 +232,13 @@ public abstract class TaskBranchesTest extends PlatformTestCase {
|
||||
}
|
||||
|
||||
private List<Repository> initRepositories(String... names) {
|
||||
return ContainerUtil.map(names, new Function<String, Repository>() {
|
||||
@Override
|
||||
public Repository fun(String s) {
|
||||
return initRepository(s);
|
||||
}
|
||||
});
|
||||
return ContainerUtil.map(names, this::initRepository);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myTaskManager = (TaskManagerImpl)TaskManager.getManager(getProject());
|
||||
myChangeListManager = (ChangeListManagerImpl)ChangeListManager.getInstance(getProject());
|
||||
myDirtyScopeManager = ((VcsDirtyScopeManagerImpl)VcsDirtyScopeManager.getInstance(getProject()));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -269,5 +249,5 @@ public abstract class TaskBranchesTest extends PlatformTestCase {
|
||||
|
||||
protected abstract int getNumberOfBranches(@NotNull Repository repository);
|
||||
|
||||
protected abstract void addFiles(@NotNull Project project, @NotNull VirtualFile root, @NotNull VirtualFile file) throws VcsException;
|
||||
protected abstract void createAndCommitChanges(@NotNull Repository repository) throws IOException, VcsException;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user