Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Pursehouse2017-03-12 22:44:11 -0400
committerMatthias Sohn2017-03-16 16:13:19 -0400
commit6b025671a8ab3dba438aa16a004ee378c1863bce (patch)
tree0bdb5bd831c38433a4a0cd31b4b23afb06aa55ca /org.eclipse.egit.ui.test/src/org/eclipse/egit
parent4c829541d483ea6b94d0bb40c8106fb5e3dca281 (diff)
downloadegit-6b025671a8ab3dba438aa16a004ee378c1863bce.tar.gz
egit-6b025671a8ab3dba438aa16a004ee378c1863bce.tar.xz
egit-6b025671a8ab3dba438aa16a004ee378c1863bce.zip
Open Git instances in try-with-resource in tests
Change-Id: I881cab412475d692f02e2d5bf76677c08fb3ac54 Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.egit.ui.test/src/org/eclipse/egit')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/httpauth/PushTest.java7
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java7
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushTagsWizardTest.java5
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java4
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java13
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java54
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java5
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java21
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/share/SharingWizardTest.java8
9 files changed, 72 insertions, 52 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/httpauth/PushTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/httpauth/PushTest.java
index e7c9a0bb0..28a9e1351 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/httpauth/PushTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/httpauth/PushTest.java
@@ -73,9 +73,10 @@ public class PushTest extends EGitTestCase {
// change file
TestUtil.appendFileContent(file, "additional content", true);
// commit change
- Git git = new Git(localRepository);
- git.add().addFilepattern(SampleTestRepository.A_txt_name).call();
- git.commit().setMessage("Change").call();
+ try (Git git = new Git(localRepository)) {
+ git.add().addFilepattern(SampleTestRepository.A_txt_name).call();
+ git.commit().setMessage("Change").call();
+ }
configurePush();
// push change
PushWizardTester wizardTester = new PushWizardTester();
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java
index 46bc78233..1f9a671f3 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/actions/SwitchToMenuTest.java
@@ -83,9 +83,10 @@ public class SwitchToMenuTest extends LocalRepositoryTestCase {
File gitDir = createProjectAndCommitToRepository();
// create additional reflog entries
- Git git = new Git(lookupRepository(gitDir));
- git.checkout().setName("stable").call();
- git.checkout().setName("master").call();
+ try (Git git = new Git(lookupRepository(gitDir))) {
+ git.checkout().setName("stable").call();
+ git.checkout().setName("master").call();
+ }
selectionWithProj1Common();
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushTagsWizardTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushTagsWizardTest.java
index 3a0a3fac2..ce19fa4f9 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushTagsWizardTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/push/PushTagsWizardTest.java
@@ -39,8 +39,9 @@ public class PushTagsWizardTest extends LocalRepositoryTestCase {
@Test
public void pushTag() throws Exception {
- Git git = new Git(repository);
- git.tag().setName("foo").setMessage("Foo tag").call();
+ try (Git git = new Git(repository)) {
+ git.tag().setName("foo").setMessage("Foo tag").call();
+ }
PushTagsWizardTester wizard = PushTagsWizardTester
.startWizard(selectProject());
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java
index 5dce9342e..7fae3168a 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/synchronize/model/GitModelCacheTest.java
@@ -107,7 +107,9 @@ public class GitModelCacheTest extends GitModelTestCase {
writeTrashFile(repo, "dir/b.txt", "trash");
writeTrashFile(repo, "dir/c.txt", "trash");
writeTrashFile(repo, "dir/d.txt", "trash");
- new Git(repo).add().addFilepattern("dir").call();
+ try (Git git = new Git(repo)) {
+ git.add().addFilepattern("dir").call();
+ }
Map<String, Change> changes = StagedChangeCache.build(repo);
assertEquals(4, changes.size());
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java
index e8155b833..7047e0b8e 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/stagview/StagingViewTest.java
@@ -108,14 +108,15 @@ public class StagingViewTest extends LocalRepositoryTestCase {
@Test
public void testMergeConflict() throws Exception {
- Git git = new Git(repository);
- git.checkout().setCreateBranch(true).setName("side").call();
- commitOneFileChange("on side");
+ try (Git git = new Git(repository)) {
+ git.checkout().setCreateBranch(true).setName("side").call();
+ commitOneFileChange("on side");
- git.checkout().setName("master").call();
- commitOneFileChange("on master");
+ git.checkout().setName("master").call();
+ commitOneFileChange("on master");
- git.merge().include(repository.findRef("side")).call();
+ git.merge().include(repository.findRef("side")).call();
+ }
assertEquals(RepositoryState.MERGING, repository.getRepositoryState());
StagingViewTester stagingView = StagingViewTester
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java
index 9cdc47d90..f863e9b2f 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/test/team/actions/CompareActionsTest.java
@@ -191,26 +191,30 @@ public class CompareActionsTest extends LocalRepositoryTestCase {
public void testCompareWithPreviousWithMerge() throws Exception {
Repository repo = lookupRepository(repositoryFile);
- Git git = new Git(repo);
- ObjectId masterId = repo.resolve("refs/heads/master");
- Ref newBranch = git.checkout().setCreateBranch(true)
- .setStartPoint(commitOfTag.name()).setName("toMerge").call();
- ByteArrayInputStream bis = new ByteArrayInputStream(
- "Modified".getBytes("UTF-8"));
- ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
- .getFolder(FOLDER).getFile(FILE2)
- .setContents(bis, false, false, null);
- bis.close();
- git.commit().setAll(true).setMessage("To be merged").call();
- git.merge().include(masterId).call();
- String menuLabel = util
- .getPluginLocalizedValue("CompareWithPreviousAction.label");
- SWTBotShell selectDialog = openCompareWithDialog(menuLabel, UIText.CommitSelectDialog_WindowTitle);
- assertEquals(2, selectDialog.bot().table().rowCount());
- selectDialog.close();
- // cleanup: checkout again master and delete merged branch
- git.checkout().setName("refs/heads/master").call();
- git.branchDelete().setBranchNames(newBranch.getName()).setForce(true).call();
+ try (Git git = new Git(repo)) {
+ ObjectId masterId = repo.resolve("refs/heads/master");
+ Ref newBranch = git.checkout().setCreateBranch(true)
+ .setStartPoint(commitOfTag.name()).setName("toMerge")
+ .call();
+ ByteArrayInputStream bis = new ByteArrayInputStream(
+ "Modified".getBytes("UTF-8"));
+ ResourcesPlugin.getWorkspace().getRoot().getProject(PROJ1)
+ .getFolder(FOLDER).getFile(FILE2)
+ .setContents(bis, false, false, null);
+ bis.close();
+ git.commit().setAll(true).setMessage("To be merged").call();
+ git.merge().include(masterId).call();
+ String menuLabel = util
+ .getPluginLocalizedValue("CompareWithPreviousAction.label");
+ SWTBotShell selectDialog = openCompareWithDialog(menuLabel,
+ UIText.CommitSelectDialog_WindowTitle);
+ assertEquals(2, selectDialog.bot().table().rowCount());
+ selectDialog.close();
+ // cleanup: checkout again master and delete merged branch
+ git.checkout().setName("refs/heads/master").call();
+ git.branchDelete().setBranchNames(newBranch.getName())
+ .setForce(true).call();
+ }
}
@Test
@@ -229,8 +233,9 @@ public class CompareActionsTest extends LocalRepositoryTestCase {
assertTreeCompareChanges(1);
// add to index -> no more changes
- new Git(lookupRepository(repositoryFile)).add().addFilepattern(
- PROJ1 + "/" + FOLDER + "/" + FILE1).call();
+ try (Git git = new Git(lookupRepository(repositoryFile))) {
+ git.add().addFilepattern(PROJ1 + "/" + FOLDER + "/" + FILE1).call();
+ }
clickCompareWith(compareWithIndexActionLabel);
@@ -263,8 +268,9 @@ public class CompareActionsTest extends LocalRepositoryTestCase {
assertSynchronizeFile1Changed();
// add to index -> should still show as change
- new Git(lookupRepository(repositoryFile)).add().addFilepattern(
- PROJ1 + "/" + FOLDER + "/" + FILE1).call();
+ try (Git git = new Git(lookupRepository(repositoryFile))) {
+ git.add().addFilepattern(PROJ1 + "/" + FOLDER + "/" + FILE1).call();
+ }
clickCompareWithAndWaitForSync(compareWithHeadMenuLabel);
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java
index b6550b13b..30dbfe941 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/AbstractSynchronizeViewTest.java
@@ -150,8 +150,9 @@ public abstract class AbstractSynchronizeViewTest extends
protected void createTag(String tagName)
throws Exception {
- new Git(lookupRepository(repositoryFile)).tag().setName(tagName)
- .setMessage(tagName).call();
+ try (Git git = new Git(lookupRepository(repositoryFile))) {
+ git.tag().setName(tagName).setMessage(tagName).call();
+ }
}
protected void makeChangesAndCommit(String projectName) throws Exception {
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java
index 0dece5db1..9a50468a0 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/view/synchronize/SynchronizeViewGitChangeSetModelTest.java
@@ -322,11 +322,14 @@ public class SynchronizeViewGitChangeSetModelTest extends
// then file FILE1 should be in index
Repository repo = lookupRepository(repositoryFile);
- Status status = new Git(repo).status().call();
+ Status status;
+ try (Git git = new Git(repo)) {
+ status = git.status().call();
+ }
assertThat(Long.valueOf(status.getChanged().size()),
is(Long.valueOf(1L)));
- assertThat(status.getChanged().iterator().next(), is(PROJ1 + "/"
- + FOLDER + "/" + FILE1));
+ assertThat(status.getChanged().iterator().next(),
+ is(PROJ1 + "/" + FOLDER + "/" + FILE1));
}
@Test
@@ -349,11 +352,13 @@ public class SynchronizeViewGitChangeSetModelTest extends
// then file FILE1 should be unchanged in working tree
Repository repo = lookupRepository(repositoryFile);
- Status status = new Git(repo).status().call();
- assertThat(Long.valueOf(status.getModified().size()),
- is(Long.valueOf(1)));
- assertThat(status.getModified().iterator().next(), is(PROJ1 + "/"
- + FOLDER + "/" + FILE2));
+ try (Git git = new Git(repo)) {
+ Status status = git.status().call();
+ assertThat(Long.valueOf(status.getModified().size()),
+ is(Long.valueOf(1)));
+ assertThat(status.getModified().iterator().next(),
+ is(PROJ1 + "/" + FOLDER + "/" + FILE2));
+ }
}
@Test
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/share/SharingWizardTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/share/SharingWizardTest.java
index bda8f27d0..0afc98c55 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/share/SharingWizardTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/wizards/share/SharingWizardTest.java
@@ -211,9 +211,11 @@ public class SharingWizardTest extends LocalRepositoryTestCase {
Repository repo3 = FileRepositoryBuilder.create(new File(
createProject(projectName3), ".git"));
repo3.create();
- Git git = new Git(repo3);
- git.add().addFilepattern(".").call();
- git.commit().setAuthor("A U Thior", "au.thor@example.com").setMessage("Created Project 3").call();
+ try (Git git = new Git(repo3)) {
+ git.add().addFilepattern(".").call();
+ git.commit().setAuthor("A U Thior", "au.thor@example.com")
+ .setMessage("Created Project 3").call();
+ }
repo3.close();
ExistingOrNewPage existingOrNewPage = sharingWizard.openWizard(

Back to the top