mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
Implement first steps for merge
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package sonia.scm.repository;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class CloseableWrapperTest {
|
||||
|
||||
@Test
|
||||
public void x() {
|
||||
Consumer<String> wrapped = new Consumer<String>() {
|
||||
// no this cannot be replaced with a lambda because otherwise we could not use Mockito#spy
|
||||
@Override
|
||||
public void accept(String s) {
|
||||
}
|
||||
};
|
||||
|
||||
Consumer<String> closer = spy(wrapped);
|
||||
|
||||
try (CloseableWrapper<String> wrapper = new CloseableWrapper<>("test", closer)) {
|
||||
// nothing to do here
|
||||
}
|
||||
|
||||
verify(closer).accept("test");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package sonia.scm.repository;
|
||||
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import sonia.scm.repository.spi.AbstractGitCommandTestBase;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
public class GitWorkdirPoolTest extends AbstractGitCommandTestBase {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void emptyPoolShouldCreateNewWorkdir() throws IOException {
|
||||
GitWorkdirPool pool = new GitWorkdirPool(temporaryFolder.newFolder());
|
||||
File masterRepo = createRepositoryDirectory();
|
||||
|
||||
CloseableWrapper<Repository> workingCopy = pool.getWorkingCopy(masterRepo);
|
||||
|
||||
assertThat(workingCopy)
|
||||
.isNotNull()
|
||||
.extracting(w -> w.get().getDirectory())
|
||||
.isNotEqualTo(masterRepo);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cloneFromPoolShouldBeClosed() throws IOException {
|
||||
PoolWithSpy pool = new PoolWithSpy(temporaryFolder.newFolder());
|
||||
File masterRepo = createRepositoryDirectory();
|
||||
|
||||
try (CloseableWrapper<Repository> workingCopy = pool.getWorkingCopy(masterRepo)) {
|
||||
assertThat(workingCopy).isNotNull();
|
||||
}
|
||||
verify(pool.createdClone).close();
|
||||
}
|
||||
|
||||
private static class PoolWithSpy extends GitWorkdirPool {
|
||||
PoolWithSpy(File poolDirectory) {
|
||||
super(poolDirectory);
|
||||
}
|
||||
|
||||
Git createdClone;
|
||||
@Override
|
||||
protected Git cloneRepository(File bareRepository, File destination) throws GitAPIException {
|
||||
createdClone = spy(super.cloneRepository(bareRepository, destination));
|
||||
return createdClone;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,9 @@ public class AbstractGitCommandTestBase extends ZippedRepositoryTestBase
|
||||
@After
|
||||
public void close()
|
||||
{
|
||||
context.close();
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user