Remove redundant constructor parameter

The repository can be retrieved from the context and does not have to be
passed through by every constructor
This commit is contained in:
René Pfeuffer
2020-05-12 15:45:58 +02:00
parent d1c6a33c67
commit d5d9690389
80 changed files with 308 additions and 425 deletions

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
@@ -40,7 +40,7 @@ import static org.junit.Assert.assertNotNull;
/**
* Unit tests for {@link GitBlameCommand}.
*
*
* @author Sebastian Sdorra
*/
public class GitBlameCommandTest extends AbstractGitCommandTestBase
@@ -48,7 +48,7 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
/**
* Tests blame command with default branch.
*
*
* @throws IOException
* @
*/
@@ -60,18 +60,18 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
BlameResult result = createCommand().getBlameResult(request);
assertNotNull(result);
assertEquals(2, result.getTotal());
assertEquals(2, result.getTotal());
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", result.getLine(0).getRevision());
assertEquals("fcd0ef1831e4002ac43ea539f4094334c79ea9ec", result.getLine(1).getRevision());
// set default branch and test again
createContext().setConfig(new GitRepositoryConfig("test-branch"));
result = createCommand().getBlameResult(request);
assertNotNull(result);
assertEquals(1, result.getTotal());
assertEquals(1, result.getTotal());
assertEquals("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4", result.getLine(0).getRevision());
}
/**
* Method description
*
@@ -156,6 +156,6 @@ public class GitBlameCommandTest extends AbstractGitCommandTestBase
*/
private GitBlameCommand createCommand()
{
return new GitBlameCommand(createContext(), repository);
return new GitBlameCommand(createContext());
}
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import org.junit.Test;
@@ -107,11 +107,11 @@ public class GitBranchCommandTest extends AbstractGitCommandTestBase {
}
private GitBranchCommand createCommand() {
return new GitBranchCommand(createContext(), repository, hookContextFactory, eventBus);
return new GitBranchCommand(createContext(), hookContextFactory, eventBus);
}
private List<Branch> readBranches(GitContext context) throws IOException {
return new GitBranchesCommand(context, repository).getBranches();
return new GitBranchesCommand(context).getBranches();
}
@Test

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import org.eclipse.jgit.api.Git;
@@ -36,7 +36,6 @@ import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import sonia.scm.repository.Branch;
import sonia.scm.repository.GitRepositoryConfig;
import sonia.scm.repository.Repository;
import java.io.IOException;
import java.util.List;
@@ -73,7 +72,7 @@ class GitBranchesCommandTest {
@BeforeEach
void initCommand() {
master = createRef("master", "0000");
branchesCommand = new GitBranchesCommand(context, new Repository("1", "git", "space", "X")) {
branchesCommand = new GitBranchesCommand(context) {
@Override
Git createGit() {
return git;

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import org.junit.Test;
@@ -121,7 +121,7 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
@Test
public void testAsynchronousBrowse() throws IOException {
try (AsyncExecutorStepper executor = stepperAsynchronousExecutor()) {
GitBrowseCommand command = new GitBrowseCommand(createContext(), repository, null, executor);
GitBrowseCommand command = new GitBrowseCommand(createContext(), null, executor);
List<BrowserResult> updatedResults = new LinkedList<>();
BrowseCommandRequest request = new BrowseCommandRequest(updatedResults::add);
FileObject root = command.getBrowserResult(request).getFile();
@@ -354,6 +354,6 @@ public class GitBrowseCommandTest extends AbstractGitCommandTestBase {
}
private GitBrowseCommand createCommand() {
return new GitBrowseCommand(createContext(), repository, lfsBlobStoreFactory, synchronousExecutor());
return new GitBrowseCommand(createContext(), lfsBlobStoreFactory, synchronousExecutor());
}
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import org.hamcrest.BaseMatcher;
@@ -46,7 +46,7 @@ import static org.mockito.Mockito.when;
/**
* Unit tests for {@link GitCatCommand}.
*
*
* TODO add not found test
*
* @author Sebastian Sdorra
@@ -61,9 +61,9 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase {
// without default branch, the repository head should be used
CatCommandRequest request = new CatCommandRequest();
request.setPath("a.txt");
assertEquals("a\nline for blame", execute(request));
// set default branch for repository and check again
createContext().setConfig(new GitRepositoryConfig("test-branch"));
assertEquals("a and b", execute(request));
@@ -134,7 +134,7 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase {
CatCommandRequest request = new CatCommandRequest();
request.setPath("b.txt");
InputStream catResultStream = new GitCatCommand(createContext(), repository, null).getCatResultStream(request);
InputStream catResultStream = new GitCatCommand(createContext(), null).getCatResultStream(request);
assertEquals('b', catResultStream.read());
assertEquals('\n', catResultStream.read());
@@ -157,7 +157,7 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase {
request.setRevision("lfs-test");
request.setPath("lfs-image.png");
InputStream catResultStream = new GitCatCommand(createContext(), repository, lfsBlobStoreFactory)
InputStream catResultStream = new GitCatCommand(createContext(), lfsBlobStoreFactory)
.getCatResultStream(request);
assertEquals('i', catResultStream.read());
@@ -174,8 +174,7 @@ public class GitCatCommandTest extends AbstractGitCommandTestBase {
try
{
new GitCatCommand(createContext(), repository, null).getCatResult(request,
baos);
new GitCatCommand(createContext(), null).getCatResult(request, baos);
}
finally
{

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import org.junit.Test;
@@ -78,7 +78,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
@Test
public void diffForOneRevisionShouldCreateDiff() throws IOException {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext());
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4");
ByteArrayOutputStream output = new ByteArrayOutputStream();
@@ -88,7 +88,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
@Test
public void diffForOneBranchShouldCreateDiff() throws IOException {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext());
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("test-branch");
ByteArrayOutputStream output = new ByteArrayOutputStream();
@@ -98,7 +98,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
@Test
public void diffForPathShouldCreateLimitedDiff() throws IOException {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext());
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("test-branch");
diffCommandRequest.setPath("a.txt");
@@ -109,7 +109,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
@Test
public void diffBetweenTwoBranchesShouldCreateDiff() throws IOException {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext());
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("master");
diffCommandRequest.setAncestorChangeset("test-branch");
@@ -120,7 +120,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
@Test
public void diffBetweenTwoBranchesForPathShouldCreateLimitedDiff() throws IOException {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext());
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("master");
diffCommandRequest.setAncestorChangeset("test-branch");
@@ -132,7 +132,7 @@ public class GitDiffCommandTest extends AbstractGitCommandTestBase {
@Test
public void diffBetweenTwoBranchesWithMergedIntegrationBranchShouldCreateDiffOfAllIncomingChanges() throws IOException {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext());
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("partially_merged");
diffCommandRequest.setAncestorChangeset("master");

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import org.junit.Test;
@@ -104,7 +104,7 @@ public class GitDiffResultCommandTest extends AbstractGitCommandTestBase {
}
private DiffResult createDiffResult(String s) throws IOException {
GitDiffResultCommand gitDiffResultCommand = new GitDiffResultCommand(createContext(), repository);
GitDiffResultCommand gitDiffResultCommand = new GitDiffResultCommand(createContext());
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision(s);

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
@@ -32,7 +32,6 @@ import org.junit.Ignore;
import org.junit.Test;
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.Repository;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
import java.io.IOException;
@@ -82,7 +81,7 @@ public class GitIncomingCommandTest
assertCommitsEquals(c1, cpr.getChangesets().get(0));
assertCommitsEquals(c2, cpr.getChangesets().get(1));
}
/**
* Method description
*
@@ -97,8 +96,8 @@ public class GitIncomingCommandTest
write(outgoing, outgoingDirectory, "a.txt", "content of a.txt");
commit(outgoing, "added a");
GitPullCommand pull = new GitPullCommand(handler, new GitContext(incomingDirectory, null, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())), incomingRepository);
GitPullCommand pull = new GitPullCommand(handler, new GitContext(incomingDirectory, incomingRepository, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())));
PullCommandRequest req = new PullCommandRequest();
req.setRemoteRepository(outgoingRepository);
pull.pull(req);
@@ -182,7 +181,6 @@ public class GitIncomingCommandTest
*/
private GitIncomingCommand createCommand()
{
return new GitIncomingCommand(handler, new GitContext(incomingDirectory, incomingRepository, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())),
this.incomingRepository);
return new GitIncomingCommand(handler, new GitContext(incomingDirectory, incomingRepository, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())));
}
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import org.junit.Test;
@@ -110,6 +110,6 @@ public class GitLogCommandAncestorTest extends AbstractGitCommandTestBase
private GitLogCommand createCommand()
{
return new GitLogCommand(createContext(), repository);
return new GitLogCommand(createContext());
}
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import com.google.common.io.Files;
@@ -180,7 +180,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
assertEquals("douglas.adams@hitchhiker.com", c.getAuthor().getMail());
assertEquals("added a and b files", c.getDescription());
GitModificationsCommand gitModificationsCommand = new GitModificationsCommand(createContext(), repository);
GitModificationsCommand gitModificationsCommand = new GitModificationsCommand(createContext());
Modifications modifications = gitModificationsCommand.getModifications(revision);
assertNotNull(modifications);
@@ -279,6 +279,6 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
private GitLogCommand createCommand()
{
return new GitLogCommand(createContext(), repository);
return new GitLogCommand(createContext());
}
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import com.github.sdorra.shiro.ShiroRule;
@@ -317,7 +317,7 @@ public class GitMergeCommandTest extends AbstractGitCommandTestBase {
assertThat(mergeAuthor.getName()).isEqualTo("Dirk Gently");
assertThat(message).isEqualTo("squash three commits");
GitModificationsCommand modificationsCommand = new GitModificationsCommand(createContext(), repository);
GitModificationsCommand modificationsCommand = new GitModificationsCommand(createContext());
List<String> changes = modificationsCommand.getModifications("master").getAdded();
assertThat(changes.size()).isEqualTo(3);
}
@@ -423,7 +423,7 @@ public class GitMergeCommandTest extends AbstractGitCommandTestBase {
}
private GitMergeCommand createCommand(Consumer<Git> interceptor) {
return new GitMergeCommand(createContext(), repository, new SimpleGitWorkdirFactory(new WorkdirProvider())) {
return new GitMergeCommand(createContext(), new SimpleGitWorkdirFactory(new WorkdirProvider())) {
@Override
<R, W extends GitCloneWorker<R>> R inClone(Function<Git, W> workerSupplier, GitWorkdirFactory workdirFactory, String initialBranch) {
Function<Git, W> interceptedWorkerSupplier = git -> {

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import org.junit.Rule;
@@ -91,7 +91,7 @@ public class GitMergeCommand_Conflict_Test extends AbstractGitCommandTestBase {
}
private MergeConflictResult computeMergeConflictResult(String branchToMerge, String targetBranch) {
GitMergeCommand gitMergeCommand = new GitMergeCommand(createContext(), repository, new SimpleGitWorkdirFactory(new WorkdirProvider()));
GitMergeCommand gitMergeCommand = new GitMergeCommand(createContext(), new SimpleGitWorkdirFactory(new WorkdirProvider()));
MergeCommandRequest mergeCommandRequest = new MergeCommandRequest();
mergeCommandRequest.setBranchToMerge(branchToMerge);
mergeCommandRequest.setTargetBranch(targetBranch);

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import org.eclipse.jgit.revwalk.RevCommit;
@@ -42,8 +42,8 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
@Before
public void init() {
incomingModificationsCommand = new GitModificationsCommand(new GitContext(incomingDirectory, null, null), incomingRepository);
outgoingModificationsCommand = new GitModificationsCommand(new GitContext(outgoingDirectory, null, null), outgoingRepository);
incomingModificationsCommand = new GitModificationsCommand(new GitContext(incomingDirectory, incomingRepository, null));
outgoingModificationsCommand = new GitModificationsCommand(new GitContext(outgoingDirectory, outgoingRepository, null));
}
@Test
@@ -87,13 +87,11 @@ public class GitModificationsCommandTest extends AbstractRemoteCommandTestBase {
}
void pushOutgoingAndPullIncoming() throws IOException {
GitPushCommand cmd = new GitPushCommand(handler, new GitContext(outgoingDirectory, null, null),
outgoingRepository);
GitPushCommand cmd = new GitPushCommand(handler, new GitContext(outgoingDirectory, outgoingRepository, null));
PushCommandRequest request = new PushCommandRequest();
request.setRemoteRepository(incomingRepository);
cmd.push(request);
GitPullCommand pullCommand = new GitPullCommand(handler, new GitContext(incomingDirectory, null, null),
incomingRepository);
GitPullCommand pullCommand = new GitPullCommand(handler, new GitContext(incomingDirectory, incomingRepository, null));
PullCommandRequest pullRequest = new PullCommandRequest();
pullRequest.setRemoteRepository(incomingRepository);
pullCommand.pull(pullRequest);

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import com.github.sdorra.shiro.ShiroRule;
@@ -323,7 +323,7 @@ public class GitModifyCommandTest extends AbstractGitCommandTestBase {
}
private GitModifyCommand createCommand() {
return new GitModifyCommand(createContext(), repository, new SimpleGitWorkdirFactory(new WorkdirProvider()), lfsBlobStoreFactory);
return new GitModifyCommand(createContext(), new SimpleGitWorkdirFactory(new WorkdirProvider()), lfsBlobStoreFactory);
}
@FunctionalInterface

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import com.github.sdorra.shiro.ShiroRule;
@@ -130,7 +130,7 @@ public class GitModifyCommand_LFSTest extends AbstractGitCommandTestBase {
}
private GitModifyCommand createCommand() {
return new GitModifyCommand(createContext(), repository, new SimpleGitWorkdirFactory(new WorkdirProvider()), lfsBlobStoreFactory);
return new GitModifyCommand(createContext(), new SimpleGitWorkdirFactory(new WorkdirProvider()), lfsBlobStoreFactory);
}
@Override

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
import com.github.sdorra.shiro.ShiroRule;
@@ -101,7 +101,7 @@ public class GitModifyCommand_withEmptyRepositoryTest extends AbstractGitCommand
}
private GitModifyCommand createCommand() {
return new GitModifyCommand(createContext(), repository, new SimpleGitWorkdirFactory(new WorkdirProvider()), lfsBlobStoreFactory);
return new GitModifyCommand(createContext(), new SimpleGitWorkdirFactory(new WorkdirProvider()), lfsBlobStoreFactory);
}
@FunctionalInterface

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
@@ -31,7 +31,6 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.junit.Test;
import sonia.scm.api.v2.resources.GitRepositoryConfigStoreProvider;
import sonia.scm.repository.ChangesetPagingResult;
import sonia.scm.repository.Repository;
import sonia.scm.store.InMemoryConfigurationStoreFactory;
import java.io.IOException;
@@ -43,7 +42,7 @@ import static org.junit.Assert.assertNotNull;
/**
* Unit tests for {@link OutgoingCommand}.
*
*
* @author Sebastian Sdorra
*/
public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase
@@ -98,8 +97,8 @@ public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase
commit(outgoing, "added a");
GitPushCommand push = new GitPushCommand(handler,
new GitContext(outgoingDirectory, null, null),
outgoingRepository);
new GitContext(outgoingDirectory, outgoingRepository, null)
);
PushCommandRequest req = new PushCommandRequest();
req.setRemoteRepository(incomingRepository);
@@ -152,7 +151,6 @@ public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase
*/
private GitOutgoingCommand createCommand()
{
return new GitOutgoingCommand(handler, new GitContext(outgoingDirectory, outgoingRepository, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())),
outgoingRepository);
return new GitOutgoingCommand(handler, new GitContext(outgoingDirectory, outgoingRepository, new GitRepositoryConfigStoreProvider(new InMemoryConfigurationStoreFactory())));
}
}

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.repository.spi;
//~--- non-JDK imports --------------------------------------------------------
@@ -89,7 +89,6 @@ public class GitPushCommandTest extends AbstractRemoteCommandTestBase
*/
private GitPushCommand createCommand()
{
return new GitPushCommand(handler, new GitContext(outgoingDirectory, null, null),
outgoingRepository);
return new GitPushCommand(handler, new GitContext(outgoingDirectory, outgoingRepository, null));
}
}