Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug #3994 Issue with tests in hop-plugins-misc-git on Windows #4220

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugins/misc/git/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<name>Hop Plugins Miscellaneous Git</name>

<properties>
<dependency.jgit.revision>6.7.0.202309050840-r</dependency.jgit.revision>
<dependency.jgit.revision>6.10.0.202406032230-r</dependency.jgit.revision>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand All @@ -38,7 +39,6 @@
import org.apache.hop.git.model.revision.ObjectRevision;
import org.apache.hop.ui.core.dialog.EnterSelectionDialog;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PullResult;
import org.eclipse.jgit.api.RemoteAddCommand;
import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.errors.MissingObjectException;
Expand All @@ -50,10 +50,9 @@
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

public class UIGitTest extends RepositoryTestCase {
private Git git;
Expand All @@ -74,6 +73,21 @@ public void setUp() throws Exception {
db2 = createWorkRepository();
}

@Override
@After
public void tearDown() throws Exception {
this.db.close();
if (!System.getProperty("os.name").contains("Windows")) {
super.tearDown();
} else {
int lastBackslashIndex = uiGit.getDirectory().lastIndexOf('\\');
String updatedPath = uiGit.getDirectory().substring(0, lastBackslashIndex);

File f = new File(updatedPath);
FileUtils.forceDeleteOnExit(f);
}
}

@Test
public void testGetBranch() {
assertEquals("master", uiGit.getBranch());
Expand Down Expand Up @@ -129,8 +143,7 @@ public void shouldNotCommitWhenAuthorNameMalformed() throws Exception {
writeTrashFile("Test.txt", "Hello world");
uiGit.add("Test.txt");

thrown.expect(NullPointerException.class);
uiGit.commit("random author", "Initial commit");
assertThrows(NullPointerException.class, () -> uiGit.commit("random author", "Initial commit"));
}

@Test
Expand Down Expand Up @@ -219,7 +232,7 @@ public void testPull() throws Exception {
FileUtils.writeStringToFile(sourceFile, "Hello world", "UTF-8");
git2.add().addFilepattern("SomeFile.txt").call();
git2.commit().setMessage("Initial commit for source").call();
PullResult pullResult = git.pull().call();
git.pull().call();

// change the source file
FileUtils.writeStringToFile(sourceFile, "Another change", "UTF-8");
Expand Down Expand Up @@ -328,8 +341,6 @@ public void testPush() throws Exception {
assertEquals("refs/remotes/origin/master", uiGit.getExpandedName("origin/master", "branch"));
}

@Rule public ExpectedException thrown = ExpectedException.none();

@Test
public void testShouldPushOnlyToOrigin() throws Exception {
// origin for db2
Expand Down Expand Up @@ -360,9 +371,9 @@ public void testShouldPushOnlyToOrigin() throws Exception {

uiGit.push();

// The followings should throw MissingObjectException
thrown.expect(MissingObjectException.class);
db3.resolve(commit.getId().getName() + "^{commit}");
assertThrows(
MissingObjectException.class, () -> db3.resolve(commit.getId().getName() + "^{commit}"));

db3.resolve(tagRef.getObjectId().getName());
}

Expand Down Expand Up @@ -433,7 +444,7 @@ public void testRevertPath() throws Exception {
// commit something
File file = writeTrashFile("Test.txt", "Hello world");
git.add().addFilepattern("Test.txt").call();
RevCommit commit = git.commit().setMessage("initial commit").call();
git.commit().setMessage("initial commit").call();

// Add some change
FileUtils.writeStringToFile(file, "Change", "UTF-8");
Expand Down
Loading