diff --git a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java index bccce1d799..2227ce787e 100644 --- a/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java +++ b/app/server/appsmith-git/src/main/java/com/appsmith/git/service/GitExecutorImpl.java @@ -424,69 +424,59 @@ public class GitExecutorImpl implements GitExecutor { } @Override - public Mono> listBranches( - Path repoSuffix, String remoteUrl, String privateKey, String publicKey, Boolean refreshBranches) { - - String gitAction = Boolean.TRUE.equals(refreshBranches) - ? AnalyticsEvents.GIT_SYNC_BRANCH.getEventName() - : AnalyticsEvents.GIT_LIST_LOCAL_BRANCH.getEventName(); - Stopwatch processStopwatch = StopwatchHelpers.startStopwatch(repoSuffix, gitAction); - ; + public Mono> listBranches(Path repoSuffix) { Path baseRepoPath = createRepoPath(repoSuffix); return Mono.fromCallable(() -> { log.debug(Thread.currentThread().getName() + ": Get branches for the application " + repoSuffix); - TransportConfigCallback transportConfigCallback = - new SshTransportConfigCallback(privateKey, publicKey); Git git = Git.open(baseRepoPath.toFile()); List refList = git.branchList() .setListMode(ListBranchCommand.ListMode.ALL) .call(); - String defaultBranch = null; - - if (Boolean.TRUE.equals(refreshBranches)) { - // Get default branch name from the remote - defaultBranch = git.lsRemote() - .setRemote(remoteUrl) - .setTransportConfigCallback(transportConfigCallback) - .callAsMap() - .get("HEAD") - .getTarget() - .getName(); - } List branchList = new ArrayList<>(); GitBranchDTO gitBranchDTO = new GitBranchDTO(); if (refList.isEmpty()) { gitBranchDTO.setBranchName(git.getRepository().getBranch()); - gitBranchDTO.setDefault(true); branchList.add(gitBranchDTO); } else { - if (Boolean.TRUE.equals(refreshBranches)) { - gitBranchDTO.setBranchName(defaultBranch.replace("refs/heads/", "")); - gitBranchDTO.setDefault(true); - branchList.add(gitBranchDTO); - } - for (Ref ref : refList) { - if (!ref.getName().equals(defaultBranch)) { - gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName(ref.getName() - .replace("refs/", "") - .replace("heads/", "") - .replace("remotes/", "")); - gitBranchDTO.setDefault(false); - branchList.add(gitBranchDTO); - } + // if (!ref.getName().equals(defaultBranch)) { + gitBranchDTO = new GitBranchDTO(); + gitBranchDTO.setBranchName(ref.getName() + .replace("refs/", "") + .replace("heads/", "") + .replace("remotes/", "")); + branchList.add(gitBranchDTO); } } git.close(); - processStopwatch.stopAndLogTimeInMillis(); return branchList; }) .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) .subscribeOn(scheduler); } + @Override + public Mono getRemoteDefaultBranch(Path repoSuffix, String remoteUrl, String privateKey, String publicKey) { + Path baseRepoPath = createRepoPath(repoSuffix); + return Mono.fromCallable(() -> { + TransportConfigCallback transportConfigCallback = + new SshTransportConfigCallback(privateKey, publicKey); + Git git = Git.open(baseRepoPath.toFile()); + + return git.lsRemote() + .setRemote(remoteUrl) + .setTransportConfigCallback(transportConfigCallback) + .callAsMap() + .get("HEAD") + .getTarget() + .getName() + .replace("refs/heads/", ""); + }) + .timeout(Duration.ofMillis(Constraint.TIMEOUT_MILLIS)) + .subscribeOn(scheduler); + } + /** * This method will handle the git-status functionality * diff --git a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/GitExecutor.java b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/GitExecutor.java index b078dcb6f6..0965ba933c 100644 --- a/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/GitExecutor.java +++ b/app/server/appsmith-interfaces/src/main/java/com/appsmith/external/git/GitExecutor.java @@ -114,9 +114,13 @@ public interface GitExecutor { * @param repoSuffix suffixedPath used to generate the base repo path this includes orgId, defaultAppId, repoName * @return List of branches for the application */ - Mono> listBranches( - Path repoSuffix, String remoteUrl, String privateKey, String publicKey, Boolean isDefaultBranchNeeded); + // Mono> listBranches( + // Path repoSuffix, String remoteUrl, String privateKey, String publicKey, Boolean + // isDefaultBranchNeeded); + Mono getRemoteDefaultBranch(Path repoSuffix, String remoteUrl, String privateKey, String publicKey); + + Mono> listBranches(Path repoSuffix); /** * This method will handle the git-status functionality * diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java index 251b8fd8f4..a459c4048b 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/helpers/GitUtils.java @@ -1,5 +1,6 @@ package com.appsmith.server.helpers; +import com.appsmith.server.domains.GitApplicationMetadata; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.util.WebClientUtils; @@ -95,4 +96,10 @@ public class GitUtils { } return sshUrl.split("\\.")[0].replaceFirst("git@", ""); } + + public static String getDefaultBranchName(GitApplicationMetadata gitApplicationMetadata) { + return StringUtils.isEmptyOrNull(gitApplicationMetadata.getDefaultBranchName()) + ? gitApplicationMetadata.getBranchName() + : gitApplicationMetadata.getDefaultBranchName(); + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java index cb6046c0f4..e5941e6ae3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCE.java @@ -17,6 +17,7 @@ import com.appsmith.server.dtos.GitPullDTO; import org.eclipse.jgit.lib.BranchTrackingStatus; import reactor.core.publisher.Mono; +import java.nio.file.Path; import java.util.List; import java.util.Map; @@ -55,6 +56,8 @@ public interface GitServiceCE { Mono> listBranchForApplication( String defaultApplicationId, Boolean pruneBranches, String currentBranch); + Mono syncDefaultBranchNameFromRemote(Path repoPath, Application rootApp); + Mono getGitApplicationMetadata(String defaultApplicationId); Mono getStatus(String defaultApplicationId, boolean compareRemote, String branchName); diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java index 6493931123..07bcb8e1ae 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/ce/GitServiceCEImpl.java @@ -1163,7 +1163,7 @@ public class GitServiceCEImpl implements GitServiceCE { String privateKey = gitApplicationMetadata.getGitAuth().getPrivateKey(); String publicKey = gitApplicationMetadata.getGitAuth().getPublicKey(); return Mono.zip( - gitExecutor.listBranches(repoSuffix, remoteUrl, privateKey, publicKey, false), + gitExecutor.listBranches(repoSuffix), Mono.just(defaultApplication), Mono.just(repoSuffix), Mono.just(defaultApplicationBranchName)); @@ -1305,12 +1305,7 @@ public class GitServiceCEImpl implements GitServiceCE { .onErrorResume(error -> Mono.error( new AppsmithException(AppsmithError.GIT_ACTION_FAILED, "fetch", error)))) .flatMap(ignore -> gitExecutor - .listBranches( - repoSuffix, - srcBranchGitData.getRemoteUrl(), - defaultGitAuth.getPrivateKey(), - defaultGitAuth.getPublicKey(), - false) + .listBranches(repoSuffix) .flatMap(branchList -> { boolean isDuplicateName = branchList.stream() // We are only supporting origin as the remote name so this is safe @@ -1390,10 +1385,23 @@ public class GitServiceCEImpl implements GitServiceCE { return Mono.error(new AppsmithException(AppsmithError.INVALID_PARAMETER, FieldName.BRANCH_NAME)); } + // get the root application + Mono rootAppMono = getApplicationById(defaultApplicationId); + // If the user is trying to check out remote branch, create a new branch if the branch does not exist already if (branchName.startsWith("origin/")) { String finalBranchName = branchName.replaceFirst("origin/", ""); - return listBranchForApplication(defaultApplicationId, false, branchName) + return addFileLock(defaultApplicationId) + .then(rootAppMono) + .flatMap(application -> { + GitApplicationMetadata gitApplicationMetadata = application.getGitApplicationMetadata(); + Path repoPath = Paths.get( + application.getWorkspaceId(), + gitApplicationMetadata.getDefaultApplicationId(), + gitApplicationMetadata.getRepoName()); + return gitExecutor.listBranches(repoPath); + }) + .flatMap(branchList -> releaseFileLock(defaultApplicationId).thenReturn(branchList)) .flatMap(gitBranchDTOList -> { long branchMatchCount = gitBranchDTOList.stream() .filter(gitBranchDTO -> @@ -1411,7 +1419,7 @@ public class GitServiceCEImpl implements GitServiceCE { }); } - return getApplicationById(defaultApplicationId) + return rootAppMono .flatMap(application -> { if (isInvalidDefaultApplicationGitMetadata(application.getGitApplicationMetadata())) { return Mono.error(new AppsmithException(AppsmithError.INVALID_GIT_SSH_CONFIGURATION)); @@ -1604,30 +1612,81 @@ public class GitServiceCEImpl implements GitServiceCE { return Mono.create(sink -> pullMono.subscribe(sink::success, sink::error, null, sink.currentContext())); } + private Flux updateDefaultBranchName( + Path repoPath, String defaultBranchName, String defaultApplicationId) { + // Get the application from DB by new defaultBranch name + return applicationService + .findByBranchNameAndDefaultApplicationId( + defaultBranchName, defaultApplicationId, applicationPermission.getEditPermission()) + // Check if the branch is already present, If not follow checkout remote flow + .onErrorResume(throwable -> checkoutRemoteBranch(defaultApplicationId, defaultBranchName)) + // ensure the local branch exists + .then(gitExecutor + .createAndCheckoutToBranch(repoPath, defaultBranchName) + .onErrorComplete()) + // Update the default branch name in all the child applications + .thenMany(applicationService + .findAllApplicationsByDefaultApplicationId( + defaultApplicationId, applicationPermission.getEditPermission()) + .flatMap(application2 -> { + application2.getGitApplicationMetadata().setDefaultBranchName(defaultBranchName); + return applicationService.save(application2); + })); + } + + @Override + public Mono syncDefaultBranchNameFromRemote(Path repoPath, Application rootApp) { + GitApplicationMetadata metadata = rootApp.getGitApplicationMetadata(); + GitAuth gitAuth = metadata.getGitAuth(); + return addFileLock(metadata.getDefaultApplicationId()) + .then(gitExecutor.getRemoteDefaultBranch( + repoPath, metadata.getRemoteUrl(), gitAuth.getPrivateKey(), gitAuth.getPublicKey())) + .flatMap(defaultBranchNameInRemote -> { + String defaultBranchInDb = GitUtils.getDefaultBranchName(metadata); + if (StringUtils.isEmptyOrNull(defaultBranchNameInRemote)) { + // If the default branch name in remote is empty or same as the one in DB, nothing to do + return Mono.just(defaultBranchInDb); + } + return updateDefaultBranchName( + repoPath, defaultBranchNameInRemote, metadata.getDefaultApplicationId()) + .then() + .thenReturn(defaultBranchNameInRemote); + }) + .flatMap(branchName -> + releaseFileLock(metadata.getDefaultApplicationId()).thenReturn(branchName)); + } + @Override public Mono> listBranchForApplication( String defaultApplicationId, Boolean pruneBranches, String currentBranch) { - // File lock - Mono> branchMono = getApplicationById(defaultApplicationId) - .flatMap(application -> addFileLock(defaultApplicationId).map(status -> application)) - .flatMap(application -> { + + // get the root application + Mono rootAppMono = getApplicationById(defaultApplicationId).cache(); + + Mono repoPathMono = rootAppMono + .map(application -> { GitApplicationMetadata gitApplicationMetadata = application.getGitApplicationMetadata(); if (gitApplicationMetadata == null || gitApplicationMetadata.getDefaultApplicationId() == null || gitApplicationMetadata.getRepoName() == null) { log.error("Git config is not present for application {}", defaultApplicationId); - return Mono.error( - new AppsmithException(AppsmithError.INVALID_GIT_CONFIGURATION, GIT_CONFIG_ERROR)); + throw new AppsmithException(AppsmithError.INVALID_GIT_CONFIGURATION, GIT_CONFIG_ERROR); } - Path repoPath = Paths.get( + return Paths.get( application.getWorkspaceId(), gitApplicationMetadata.getDefaultApplicationId(), gitApplicationMetadata.getRepoName()); + }) + .cache(); - Mono> gitBranchDTOMono; - // Fetch remote first if the prune branch is valid + Mono> gitBranchListMono = Mono.zip(rootAppMono, repoPathMono) + .flatMap(objects -> addFileLock(defaultApplicationId).thenReturn(objects)) + .flatMap(objects -> { + GitApplicationMetadata gitApplicationMetadata = + objects.getT1().getGitApplicationMetadata(); + Path repoPath = objects.getT2(); if (Boolean.TRUE.equals(pruneBranches)) { - gitBranchDTOMono = gitExecutor + return gitExecutor .fetchRemote( repoPath, gitApplicationMetadata.getGitAuth().getPublicKey(), @@ -1635,82 +1694,49 @@ public class GitServiceCEImpl implements GitServiceCE { false, currentBranch, true) - .flatMap(s -> gitExecutor.listBranches( - repoPath, - gitApplicationMetadata.getRemoteUrl(), - gitApplicationMetadata.getGitAuth().getPrivateKey(), - gitApplicationMetadata.getGitAuth().getPublicKey(), - true)); + .then(gitExecutor.listBranches(repoPath)); } else { - // Fetch default branch from DB if the pruneBranches is false else fetch from remote - gitBranchDTOMono = gitExecutor.listBranches( - repoPath, - gitApplicationMetadata.getRemoteUrl(), - gitApplicationMetadata.getGitAuth().getPrivateKey(), - gitApplicationMetadata.getGitAuth().getPublicKey(), - false); - } - return Mono.zip(gitBranchDTOMono, Mono.just(application)).onErrorResume(error -> { - if (error instanceof RepositoryNotFoundException) { - Mono> branchListMono = handleRepoNotFoundException(defaultApplicationId); - return Mono.zip(branchListMono, Mono.just(application), Mono.just(repoPath)); - } - return Mono.error(new AppsmithException( - AppsmithError.GIT_ACTION_FAILED, "branch --list", error.getMessage())); - }); - }) - .flatMap(objects -> releaseFileLock(defaultApplicationId).thenReturn(objects)) - .flatMap(tuple -> { - List gitBranchListDTOS = tuple.getT1(); - Application application = tuple.getT2(); - GitApplicationMetadata gitApplicationMetadata = application.getGitApplicationMetadata(); - final String dbDefaultBranch = - StringUtils.isEmptyOrNull(gitApplicationMetadata.getDefaultBranchName()) - ? gitApplicationMetadata.getBranchName() - : gitApplicationMetadata.getDefaultBranchName(); - - if (Boolean.TRUE.equals(pruneBranches)) { - String defaultBranchRemote = gitBranchListDTOS.stream() - .filter(GitBranchDTO::isDefault) - .map(GitBranchDTO::getBranchName) - .findFirst() - .orElse(dbDefaultBranch); - - if (defaultBranchRemote.equals(dbDefaultBranch)) { - return Mono.just(gitBranchListDTOS).zipWith(Mono.just(application)); - } else { - // Get the application from DB by new defaultBranch name - return applicationService - .findByBranchNameAndDefaultApplicationId( - defaultBranchRemote, - defaultApplicationId, - applicationPermission.getEditPermission()) - // Check if the branch is already present, If not follow checkout remote flow - .onErrorResume(throwable -> - checkoutRemoteBranch(defaultApplicationId, defaultBranchRemote)) - // Update the default branch name in all the child applications - .flatMapMany(application1 -> applicationService - .findAllApplicationsByDefaultApplicationId( - defaultApplicationId, applicationPermission.getEditPermission()) - .flatMap(application2 -> { - application2 - .getGitApplicationMetadata() - .setDefaultBranchName(defaultBranchRemote); - return applicationService.save(application2); - })) - // Return the deleted branches - .then(Mono.just(gitBranchListDTOS).zipWith(Mono.just(application))); - } - } else { - gitBranchListDTOS.stream() - .filter(branchDTO -> - StringUtils.equalsIgnoreCase(branchDTO.getBranchName(), dbDefaultBranch)) - .findFirst() - .ifPresent(branchDTO -> branchDTO.setDefault(true)); - return Mono.just(gitBranchListDTOS).zipWith(Mono.just(application)); + return gitExecutor.listBranches(repoPath); } }) - // Add BE analytics + .flatMap(branchDTOList -> releaseFileLock(defaultApplicationId).thenReturn(branchDTOList)); + + Mono defaultBranchMono; + if (!Boolean.TRUE.equals(pruneBranches)) { + defaultBranchMono = rootAppMono + .map(application -> { + GitApplicationMetadata gitApplicationMetadata = application.getGitApplicationMetadata(); + if (gitApplicationMetadata == null + || gitApplicationMetadata.getDefaultApplicationId() == null) { + throw new AppsmithException(AppsmithError.INVALID_GIT_CONFIGURATION, GIT_CONFIG_ERROR); + } + return gitApplicationMetadata; + }) + .map(GitUtils::getDefaultBranchName); + } else { + defaultBranchMono = Mono.zip(rootAppMono, repoPathMono).flatMap(objects -> { + Path repoPath = objects.getT2(); + Application rootApp = objects.getT1(); + return syncDefaultBranchNameFromRemote(repoPath, rootApp); + }); + } + + // set the default branch flag to true for the default branch + Mono> branchMono = defaultBranchMono + .zipWhen(defaultBranch -> gitBranchListMono) + .map(objects -> { + String defaultBranch = objects.getT1(); + List gitBranchDTOList = objects.getT2(); + + for (GitBranchDTO branchDTO : gitBranchDTOList) { + if (StringUtils.equalsIgnoreCase(branchDTO.getBranchName(), defaultBranch)) { + branchDTO.setDefault(true); + break; + } + } + return gitBranchDTOList; + }) + .zipWith(rootAppMono) .flatMap(tuple -> { List gitBranchDTOList = tuple.getT1(); Application application = tuple.getT2(); @@ -2919,12 +2945,7 @@ public class GitServiceCEImpl implements GitServiceCE { gitApplicationMetadata.getRemoteUrl(), gitAuth.getPrivateKey(), gitAuth.getPublicKey()) - .flatMap(defaultBranch -> gitExecutor.listBranches( - repoPath, - gitApplicationMetadata.getRemoteUrl(), - gitAuth.getPrivateKey(), - gitAuth.getPublicKey(), - false)) + .flatMap(defaultBranch -> gitExecutor.listBranches(repoPath)) .flatMap(gitBranchDTOList -> { List branchList = gitBranchDTOList.stream() .filter(gitBranchDTO -> diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/GitExecutorTest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/GitExecutorTest.java index 94db0c93c0..e0fedd0dc5 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/git/GitExecutorTest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/git/GitExecutorTest.java @@ -263,8 +263,7 @@ public class GitExecutorTest { Mono branchMono = gitExecutor .createAndCheckoutToBranch(path, "test1") .flatMap(s -> gitExecutor.createAndCheckoutToBranch(path, "test2")); - Mono> gitBranchDTOMono = - branchMono.then(gitExecutor.listBranches(path, "remoteUrl", "publicKey", "privateKey", false)); + Mono> gitBranchDTOMono = branchMono.then(gitExecutor.listBranches(path)); StepVerifier.create(gitBranchDTOMono).assertNext(gitBranchDTOS -> { assertThat(gitBranchDTOS.stream().count()).isEqualTo(3); diff --git a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/GitServiceCETest.java b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/GitServiceCETest.java index 4edf28b298..39c86c4f40 100644 --- a/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/GitServiceCETest.java +++ b/app/server/appsmith-server/src/test/java/com/appsmith/server/services/ce/GitServiceCETest.java @@ -116,6 +116,7 @@ import static com.appsmith.server.acl.AclPermission.READ_PAGES; import static com.appsmith.server.constants.FieldName.DEFAULT_PAGE_LAYOUT; import static java.lang.Boolean.TRUE; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; @ExtendWith(SpringExtension.class) @@ -223,8 +224,7 @@ public class GitServiceCETest { Mockito.when(gitCloudServicesUtils.getPrivateRepoLimitForOrg(eq(workspaceId), Mockito.anyBoolean())) .thenReturn(Mono.just(-1)); - Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())) - .thenReturn(Mono.just(new MockPluginExecutor())); + Mockito.when(pluginExecutorHelper.getPluginExecutor(any())).thenReturn(Mono.just(new MockPluginExecutor())); if (TRUE.equals(isSetupDone)) { return; @@ -278,28 +278,25 @@ public class GitServiceCETest { if (StringUtils.isEmpty(branchName)) { branchName = DEFAULT_BRANCH; } - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(branchName)); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); - Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) + Mockito.when(gitExecutor.pushApplication(any(Path.class), any(), any(), any(), any())) .thenReturn(Mono.just("success")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("path"))); Application testApplication = new Application(); @@ -455,11 +452,9 @@ public class GitServiceCETest { GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testRepo.git", testUserProfile); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(false)); + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(false)); Mono applicationMono = gitService.connectApplicationToGit(application1.getId(), gitConnectDTO, "baseUrl"); @@ -487,10 +482,9 @@ public class GitServiceCETest { GitConnectDTO gitConnectDTO = getConnectRequest("https://github.com/test/testRepo.git", testUserProfile); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.error(new ClassCastException("TransportHttp"))); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); Mono applicationMono = gitService.connectApplicationToGit(application1.getId(), gitConnectDTO, "baseUrl"); @@ -505,10 +499,9 @@ public class GitServiceCETest { @WithUserDetails(value = "api_user") public void connectApplicationToGit_InvalidFilePath_ThrowIOException() throws IOException { - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))) .thenThrow(new IOException("Error while accessing the file system")); Application testApplication = new Application(); @@ -537,11 +530,9 @@ public class GitServiceCETest { @WithUserDetails(value = "api_user") public void connectApplicationToGit_ClonedRepoNotEmpty_Failure() throws IOException { - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(false)); + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(false)); Application testApplication = new Application(); GitApplicationMetadata gitApplicationMetadata = new GitApplicationMetadata(); @@ -569,10 +560,9 @@ public class GitServiceCETest { @WithUserDetails(value = "api_user") public void connectApplicationToGit_cloneException_throwGitException() throws IOException { - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.error(new Exception("error message"))); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testRepo.git", testUserProfile); Mono applicationMono = @@ -588,28 +578,27 @@ public class GitServiceCETest { @WithUserDetails(value = "api_user") public void connectApplicationToGit_WithEmptyPublishedPages_CloneSuccess() throws IOException, GitAPIException { - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("success")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -617,11 +606,10 @@ public class GitServiceCETest { Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Application testApplication = new Application(); @@ -664,28 +652,27 @@ public class GitServiceCETest { public void connectApplicationToGit_WithoutGitProfileUsingDefaultProfile_CloneSuccess() throws IOException, GitAPIException { - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("success")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -693,13 +680,12 @@ public class GitServiceCETest { Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); GitProfile gitProfile = new GitProfile(); gitProfile.setAuthorName(null); @@ -770,28 +756,27 @@ public class GitServiceCETest { @WithUserDetails(value = "api_user") public void connectApplicationToGit_WithNonEmptyPublishedPages_CloneSuccess() throws IOException, GitAPIException { - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("success")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -799,13 +784,12 @@ public class GitServiceCETest { Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); Application testApplication = new Application(); GitApplicationMetadata gitApplicationMetadata = new GitApplicationMetadata(); @@ -858,29 +842,27 @@ public class GitServiceCETest { Mockito.when(gitCloudServicesUtils.getPrivateRepoLimitForOrg(Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just(0)); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("success")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Application testApplication = new Application(); @@ -919,29 +901,27 @@ public class GitServiceCETest { Mockito.when(gitCloudServicesUtils.getPrivateRepoLimitForOrg( eq(limitPrivateRepoTestWorkspaceId), Mockito.anyBoolean())) .thenReturn(Mono.just(3)); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("success")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Application application1 = @@ -981,28 +961,27 @@ public class GitServiceCETest { @WithUserDetails(value = "api_user") public void connectApplicationToGit_WithValidCustomGitDomain_CloneSuccess() throws IOException, GitAPIException { - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("success")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -1010,11 +989,10 @@ public class GitServiceCETest { Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Application testApplication = new Application(); @@ -1121,16 +1099,9 @@ public class GitServiceCETest { remoteGitBranchDTO.setBranchName("origin/defaultBranch"); branchList.add(remoteGitBranchDTO); - Mockito.when(gitExecutor.listBranches( - Mockito.any(Path.class), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - eq(false))) - .thenReturn(Mono.just(branchList)); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); - Mockito.when(pluginExecutorHelper.getPluginExecutor(Mockito.any())) - .thenReturn(Mono.just(new MockPluginExecutor())); + Mockito.when(gitExecutor.listBranches(any(Path.class))).thenReturn(Mono.just(branchList)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(pluginExecutorHelper.getPluginExecutor(any())).thenReturn(Mono.just(new MockPluginExecutor())); Application testApplication = new Application(); GitApplicationMetadata gitApplicationMetadata = new GitApplicationMetadata(); @@ -1375,15 +1346,15 @@ public class GitServiceCETest { @WithUserDetails(value = "api_user") public void listBranchForApplication_applicationWithInvalidGitConfig_throwError() throws IOException { - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Application testApplication = new Application(); testApplication.setGitApplicationMetadata(null); testApplication.setName("listBranchForApplication_GitFailure_ThrowError"); testApplication.setWorkspaceId(workspaceId); + Application application1 = applicationPageService.createApplication(testApplication).block(); @@ -1401,32 +1372,25 @@ public class GitServiceCETest { @Test @WithUserDetails(value = "api_user") public void listBranchForApplication_defaultBranchNotChangesInRemote_Success() throws IOException, GitAPIException { - List branchList = new ArrayList<>(); - GitBranchDTO gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("defaultBranch"); - gitBranchDTO.setDefault(true); - branchList.add(gitBranchDTO); - gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("origin/defaultBranch"); - gitBranchDTO.setDefault(false); - branchList.add(gitBranchDTO); + List branchList = List.of( + createGitBranchDTO("defaultBranch", false), + createGitBranchDTO("feature1", false), + createGitBranchDTO("origin/defaultBranch", false), + createGitBranchDTO("origin/feature1", false)); - Mockito.when(gitExecutor.listBranches( - Mockito.any(Path.class), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - eq(true))) - .thenReturn(Mono.just(branchList)); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.listBranches(any(Path.class))).thenReturn(Mono.just(branchList)); + Mockito.when(gitExecutor.getRemoteDefaultBranch( + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.createAndCheckoutToBranch(any(Path.class), eq("defaultBranch"))) + .thenReturn(Mono.just("defaultBranch")); + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(Mono.just("defaultBranch")); + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), eq(false), @@ -1451,47 +1415,32 @@ public class GitServiceCETest { @WithUserDetails(value = "api_user") public void listBranchForApplication_defaultBranchChangesInRemoteExistsInDB_Success() throws IOException, GitAPIException { - List branchList = new ArrayList<>(); - GitBranchDTO gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("defaultBranch"); - gitBranchDTO.setDefault(false); - branchList.add(gitBranchDTO); - gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("feature1"); - gitBranchDTO.setDefault(true); - branchList.add(gitBranchDTO); - gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("origin/defaultBranch"); - gitBranchDTO.setDefault(false); - branchList.add(gitBranchDTO); - gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("origin/feature1"); - gitBranchDTO.setDefault(false); - branchList.add(gitBranchDTO); + List branchList = List.of( + createGitBranchDTO("defaultBranch", false), + createGitBranchDTO("feature1", false), + createGitBranchDTO("origin/defaultBranch", false), + createGitBranchDTO("origin/feature1", false)); - Mockito.when(gitExecutor.listBranches( - Mockito.any(Path.class), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - eq(true))) - .thenReturn(Mono.just(branchList)); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.listBranches(any(Path.class))).thenReturn(Mono.just(branchList)); + Mockito.when(gitExecutor.getRemoteDefaultBranch( + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(Mono.just("feature1")); + Mockito.when(gitExecutor.createAndCheckoutToBranch(any(Path.class), eq("feature1"))) + .thenReturn(Mono.just("feature1")); + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), eq(false), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("status")); - Mockito.when(gitExecutor.deleteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.deleteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Application application1 = createApplicationConnectedToGit( @@ -1516,53 +1465,44 @@ public class GitServiceCETest { .verifyComplete(); } + private GitBranchDTO createGitBranchDTO(String branchName, boolean isDefault) { + GitBranchDTO gitBranchDTO = new GitBranchDTO(); + gitBranchDTO.setBranchName(branchName); + gitBranchDTO.setDefault(isDefault); + return gitBranchDTO; + } + @Test @WithUserDetails(value = "api_user") public void listBranchForApplication_defaultBranchChangesInRemoteDoesNotExistsInDB_Success() throws IOException, GitAPIException { - List branchList = new ArrayList<>(); - GitBranchDTO gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("defaultBranch"); - gitBranchDTO.setDefault(false); - branchList.add(gitBranchDTO); - gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("feature1"); - gitBranchDTO.setDefault(true); - branchList.add(gitBranchDTO); - gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("origin/defaultBranch"); - gitBranchDTO.setDefault(false); - branchList.add(gitBranchDTO); - gitBranchDTO = new GitBranchDTO(); - gitBranchDTO.setBranchName("origin/feature1"); - gitBranchDTO.setDefault(false); - branchList.add(gitBranchDTO); + List branchList = List.of( + createGitBranchDTO("defaultBranch", false), + createGitBranchDTO("feature1", false), + createGitBranchDTO("origin/defaultBranch", false), + createGitBranchDTO("origin/feature1", false)); ApplicationJson applicationJson = createAppJson(filePath).block(); - - Mockito.when(gitExecutor.listBranches( - Mockito.any(Path.class), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - eq(true))) - .thenReturn(Mono.just(branchList)); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.createAndCheckoutToBranch(any(Path.class), eq("feature1"))) + .thenReturn(Mono.just("feature1")); + Mockito.when(gitExecutor.listBranches(any(Path.class))).thenReturn(Mono.just(branchList)); + Mockito.when(gitExecutor.getRemoteDefaultBranch( + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + .thenReturn(Mono.just("feature1")); + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), eq(false), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("status")); - Mockito.when(gitExecutor.checkoutRemoteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutRemoteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just("feature1")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) @@ -1604,29 +1544,29 @@ public class GitServiceCETest { gitStatusDTO.setIsClean(true); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("path"))); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); Mockito.when(gitExecutor.pullApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(mergeStatusDTO)); - Mockito.when(gitExecutor.getStatus(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.getStatus(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(gitStatusDTO)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), eq(false), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetched")); - Mockito.when(gitExecutor.resetToLastCommit(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.resetToLastCommit(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mono applicationMono = gitService.pullApplication( @@ -1650,13 +1590,13 @@ public class GitServiceCETest { mergeStatusDTO.setMergeAble(true); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenThrow(new IOException("Error accessing the file System")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(new ApplicationJson())); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), eq(false), @@ -1664,7 +1604,7 @@ public class GitServiceCETest { Mockito.anyBoolean())) .thenReturn(Mono.just("fetched")); Mockito.when(gitExecutor.pullApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -1692,14 +1632,14 @@ public class GitServiceCETest { mergeStatusDTO.setMergeAble(true); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.justOrEmpty(applicationJson)); - Mockito.when(gitExecutor.getStatus(Mockito.any(), Mockito.any())).thenReturn(Mono.just(new GitStatusDTO())); + Mockito.when(gitExecutor.getStatus(any(), any())).thenReturn(Mono.just(new GitStatusDTO())); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), @@ -1707,13 +1647,13 @@ public class GitServiceCETest { Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); Mockito.when(gitExecutor.pullApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(mergeStatusDTO)); - Mockito.when(gitExecutor.resetToLastCommit(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.resetToLastCommit(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mono applicationMono = gitService.pullApplication( @@ -1750,23 +1690,23 @@ public class GitServiceCETest { gitStatusDTO.setBehindCount(0); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); - Mockito.when(gitExecutor.isMergeBranch(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.isMergeBranch(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(mergeStatus)); - Mockito.when(gitExecutor.getStatus(Mockito.any(), Mockito.any())).thenReturn(Mono.just(gitStatusDTO)); + Mockito.when(gitExecutor.getStatus(any(), any())).thenReturn(Mono.just(gitStatusDTO)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.resetToLastCommit(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.resetToLastCommit(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(TRUE)); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mono applicationMono = gitService.isBranchMergeable(application.getId(), gitMergeDTO); @@ -1793,23 +1733,23 @@ public class GitServiceCETest { mergeStatus.setMergeAble(false); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); - Mockito.when(gitExecutor.isMergeBranch(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.isMergeBranch(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(mergeStatus)); - Mockito.when(gitExecutor.getStatus(Mockito.any(), Mockito.any())).thenReturn(Mono.just(new GitStatusDTO())); + Mockito.when(gitExecutor.getStatus(any(), any())).thenReturn(Mono.just(new GitStatusDTO())); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.resetToLastCommit(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.resetToLastCommit(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(Boolean.FALSE)); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mono applicationMono = gitService.isBranchMergeable(application.getId(), gitMergeDTO); @@ -1843,23 +1783,23 @@ public class GitServiceCETest { mergeStatus.setMergeAble(false); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("path"))); - Mockito.when(gitExecutor.isMergeBranch(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.isMergeBranch(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(mergeStatus)); - Mockito.when(gitExecutor.getStatus(Mockito.any(), Mockito.any())).thenReturn(Mono.just(gitStatusDTO)); + Mockito.when(gitExecutor.getStatus(any(), any())).thenReturn(Mono.just(gitStatusDTO)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.resetToLastCommit(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.resetToLastCommit(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(Boolean.FALSE)); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mono applicationMono = @@ -1905,21 +1845,19 @@ public class GitServiceCETest { branchList.add(gitBranchDTO); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.checkoutRemoteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutRemoteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just("testBranch")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); - Mockito.when(gitExecutor.listBranches( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(Mono.just(branchList)); + Mockito.when(gitExecutor.listBranches(any())).thenReturn(Mono.just(branchList)); Mono applicationMono = gitService .checkoutBranch(gitConnectedApplication.getId(), "origin/branchNotInLocal") @@ -1964,21 +1902,19 @@ public class GitServiceCETest { branchList.add(gitBranchDTO); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.checkoutRemoteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutRemoteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just("testBranch")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); - Mockito.when(gitExecutor.listBranches( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(Mono.just(branchList)); + Mockito.when(gitExecutor.listBranches(any())).thenReturn(Mono.just(branchList)); // set custom theme to the git connected application Mono setCustomThemeToGitConnectedAppMono = themeService @@ -2052,11 +1988,9 @@ public class GitServiceCETest { gitBranchDTO.setBranchName("origin/branchInLocal"); branchList.add(gitBranchDTO); - Mockito.when(gitExecutor.listBranches( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(Mono.just(branchList)); + Mockito.when(gitExecutor.listBranches(any())).thenReturn(Mono.just(branchList)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), @@ -2099,10 +2033,10 @@ public class GitServiceCETest { commitDTO.setCommitMessage("empty commit"); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -2157,7 +2091,7 @@ public class GitServiceCETest { gitService.commitApplication(commitDTO, gitConnectedApplication.getId(), DEFAULT_BRANCH); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn( Mono.error(new RepositoryNotFoundException(AppsmithError.REPOSITORY_NOT_FOUND.getMessage()))); @@ -2179,10 +2113,10 @@ public class GitServiceCETest { commitDTO.setCommitMessage("commit message"); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -2209,20 +2143,20 @@ public class GitServiceCETest { commitDTO.setCommitMessage("commit message"); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("sample response for commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -2256,20 +2190,20 @@ public class GitServiceCETest { commitDTO.setCommitMessage("empty commit"); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.error(new EmptyCommitException("nothing to commit"))); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -2317,8 +2251,7 @@ public class GitServiceCETest { applicationService.getApplicationByDefaultApplicationIdAndDefaultBranch(preCommitApplication.getId()); // Mocking a git push failure - Mockito.when(gitExecutor.pushApplication( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) + Mockito.when(gitExecutor.pushApplication(any(), any(), any(), any(), any())) .thenReturn(Mono.error(new AppsmithException(AppsmithError.GIT_UPSTREAM_CHANGES))); StepVerifier.create(commitMono) @@ -2367,10 +2300,9 @@ public class GitServiceCETest { Mono commitMono = gitService.commitApplication(commitDTO, preCommitApplication.getId(), DEFAULT_BRANCH); // Mocking a git push failure - Mockito.when(gitExecutor.pushApplication( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) + Mockito.when(gitExecutor.pushApplication(any(), any(), any(), any(), any())) .thenReturn(Mono.just("REJECTED_OTHERREASON, pre-receive hook declined")); - Mockito.when(gitExecutor.resetHard(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.resetHard(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); StepVerifier.create(commitMono) @@ -2417,19 +2349,17 @@ public class GitServiceCETest { GitBranchDTO createGitBranchDTO = new GitBranchDTO(); createGitBranchDTO.setBranchName("branchInRemote"); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.listBranches( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(Mono.just(branchList)); + Mockito.when(gitExecutor.listBranches(any())).thenReturn(Mono.just(branchList)); Mono createBranchMono = gitService.createBranch( gitConnectedApplication.getId(), createGitBranchDTO, @@ -2453,48 +2383,44 @@ public class GitServiceCETest { GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testRepo.git", testUserProfile); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.listBranches( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(Mono.just(new ArrayList<>())); - Mockito.when(gitExecutor.createAndCheckoutToBranch(Mockito.any(), Mockito.any())) + Mockito.when(gitExecutor.listBranches(any())).thenReturn(Mono.just(new ArrayList<>())); + Mockito.when(gitExecutor.createAndCheckoutToBranch(any(), any())) .thenReturn(Mono.just(createGitBranchDTO.getBranchName())); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("System generated commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("pushed successfully")); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(DEFAULT_BRANCH)); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Application testApplication = new Application(); @@ -2700,48 +2626,44 @@ public class GitServiceCETest { GitConnectDTO gitConnectDTO = getConnectRequest("git@github.com:test/testRepo.git", testUserProfile); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.listBranches( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(Mono.just(new ArrayList<>())); - Mockito.when(gitExecutor.createAndCheckoutToBranch(Mockito.any(), Mockito.any())) + Mockito.when(gitExecutor.listBranches(any())).thenReturn(Mono.just(new ArrayList<>())); + Mockito.when(gitExecutor.createAndCheckoutToBranch(any(), any())) .thenReturn(Mono.just(createGitBranchDTO.getBranchName())); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("System generated commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("pushed successfully")); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(DEFAULT_BRANCH)); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Application testApplication = new Application(); @@ -2794,48 +2716,44 @@ public class GitServiceCETest { } private void mockitoSetUp(GitBranchDTO createGitBranchDTO) throws GitAPIException, IOException { - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.listBranches( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(Mono.just(new ArrayList<>())); - Mockito.when(gitExecutor.createAndCheckoutToBranch(Mockito.any(), Mockito.any())) + Mockito.when(gitExecutor.listBranches(any())).thenReturn(Mono.just(new ArrayList<>())); + Mockito.when(gitExecutor.createAndCheckoutToBranch(any(), any())) .thenReturn(Mono.just(createGitBranchDTO.getBranchName())); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("System generated commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("pushed successfully")); - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(DEFAULT_BRANCH)); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); } @@ -3139,29 +3057,27 @@ public class GitServiceCETest { @WithUserDetails(value = "api_user") public void connectApplicationToGit_cancelledMidway_cloneSuccess() throws IOException { - Mockito.when(gitExecutor.cloneApplication( - Mockito.any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitExecutor.cloneApplication(any(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranchName")); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("success")); - Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(Mockito.any(Path.class))) - .thenReturn(Mono.just(true)); - Mockito.when(gitFileUtils.initializeReadme(Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString())) + Mockito.when(gitFileUtils.checkIfDirectoryIsEmpty(any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.initializeReadme(any(Path.class), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("textPath"))); Application testApplication = new Application(); @@ -3219,20 +3135,20 @@ public class GitServiceCETest { applicationPageService.createPage(page).block(); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("committed successfully")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -3270,36 +3186,34 @@ public class GitServiceCETest { GitBranchDTO createGitBranchDTO = new GitBranchDTO(); createGitBranchDTO.setBranchName("midway_cancelled_branch"); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyBoolean())) .thenReturn(Mono.just("fetchResult")); - Mockito.when(gitExecutor.listBranches( - Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) - .thenReturn(Mono.just(new ArrayList<>())); - Mockito.when(gitExecutor.createAndCheckoutToBranch(Mockito.any(), Mockito.any())) + Mockito.when(gitExecutor.listBranches(any())).thenReturn(Mono.just(new ArrayList<>())); + Mockito.when(gitExecutor.createAndCheckoutToBranch(any(), any())) .thenReturn(Mono.just(createGitBranchDTO.getBranchName())); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("System generated commit")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -3470,12 +3384,12 @@ public class GitServiceCETest { applicationJson.setDatasourceList(new ArrayList<>()); Mockito.when(gitExecutor.cloneApplication( - Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); Mono applicationMono = gitService.importApplicationFromGit(workspaceId, gitConnectDTO); @@ -3496,7 +3410,7 @@ public class GitServiceCETest { applicationJson.setDatasourceList(new ArrayList<>()); Mockito.when(gitExecutor.cloneApplication( - Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) @@ -3542,7 +3456,7 @@ public class GitServiceCETest { applicationPageService.createApplication(testApplication).block(); Mockito.when(gitExecutor.cloneApplication( - Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) @@ -3603,12 +3517,12 @@ public class GitServiceCETest { datasourceService.create(datasource).block(); Mockito.when(gitExecutor.cloneApplication( - Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); Mono applicationMono = gitService.importApplicationFromGit(workspaceId, gitConnectDTO); @@ -3668,12 +3582,12 @@ public class GitServiceCETest { Mockito.when(gitCloudServicesUtils.getPrivateRepoLimitForOrg(eq(testWorkspaceId), Mockito.anyBoolean())) .thenReturn(Mono.just(3)); Mockito.when(gitExecutor.cloneApplication( - Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); gitService .importApplicationFromGit(testWorkspaceId, gitConnectDTO) @@ -3738,12 +3652,12 @@ public class GitServiceCETest { datasourceService.create(datasource).block(); Mockito.when(gitExecutor.cloneApplication( - Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); Mono applicationMono = gitService.importApplicationFromGit(workspaceId, gitConnectDTO); @@ -3762,12 +3676,12 @@ public class GitServiceCETest { ApplicationJson applicationJson = new ApplicationJson(); Mockito.when(gitExecutor.cloneApplication( - Mockito.any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just("defaultBranch")); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); - Mockito.when(gitFileUtils.deleteLocalRepo(Mockito.any(Path.class))).thenReturn(Mono.just(true)); + Mockito.when(gitFileUtils.deleteLocalRepo(any(Path.class))).thenReturn(Mono.just(true)); Mono applicationMono = gitService.importApplicationFromGit(workspaceId, gitConnectDTO); @@ -3785,7 +3699,7 @@ public class GitServiceCETest { Application application = createApplicationConnectedToGit("deleteBranch_staleBranchNotInDB_Success", "master"); application.getGitApplicationMetadata().setDefaultBranchName("master"); applicationService.save(application).block(); - Mockito.when(gitExecutor.deleteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.deleteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mono applicationMono = gitService.deleteBranch(application.getId(), "test"); @@ -3803,7 +3717,7 @@ public class GitServiceCETest { Application application = createApplicationConnectedToGit("deleteBranch_existsInDB_Success", "master"); application.getGitApplicationMetadata().setDefaultBranchName("test"); applicationService.save(application).block(); - Mockito.when(gitExecutor.deleteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.deleteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mono applicationMono = gitService.deleteBranch(application.getId(), "master"); @@ -3823,7 +3737,7 @@ public class GitServiceCETest { createApplicationConnectedToGit("deleteBranch_branchDoesNotExist_ThrowError", "master"); application.getGitApplicationMetadata().setDefaultBranchName("test"); applicationService.save(application).block(); - Mockito.when(gitExecutor.deleteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.deleteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(false)); Mono applicationMono = gitService.deleteBranch(application.getId(), "master"); @@ -3840,7 +3754,7 @@ public class GitServiceCETest { Application application = createApplicationConnectedToGit("deleteBranch_defaultBranch_ThrowError", "master"); application.getGitApplicationMetadata().setDefaultBranchName("master"); applicationService.save(application).block(); - Mockito.when(gitExecutor.deleteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.deleteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(false)); Mono applicationMono = gitService.deleteBranch(application.getId(), "master"); @@ -3864,7 +3778,7 @@ public class GitServiceCETest { branchApp.getGitApplicationMetadata().setDefaultApplicationId(application.getId()); applicationService.save(branchApp).block(); - Mockito.when(gitExecutor.deleteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.deleteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mono applicationMono = gitService.deleteBranch(application.getId(), "master"); @@ -3898,12 +3812,12 @@ public class GitServiceCETest { gitStatusDTO.setIsClean(true); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("path"))); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); - Mockito.when(gitExecutor.rebaseBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.rebaseBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mono applicationMono = gitService.discardChanges( @@ -3934,22 +3848,22 @@ public class GitServiceCETest { gitStatusDTO.setIsClean(true); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get("path"))); Mockito.when(gitFileUtils.reconstructApplicationJsonFromGitRepo( Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(applicationJson)); Mockito.when(gitExecutor.pullApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString())) .thenReturn(Mono.just(mergeStatusDTO)); - Mockito.when(gitExecutor.getStatus(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.getStatus(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(gitStatusDTO)); Mockito.when(gitExecutor.fetchRemote( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), eq(true), @@ -3999,7 +3913,7 @@ public class GitServiceCETest { branchApp.getGitApplicationMetadata().setDefaultApplicationId(application.getId()); applicationService.save(branchApp).block(); - Mockito.when(gitExecutor.deleteBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.deleteBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); gitService @@ -4045,20 +3959,20 @@ public class GitServiceCETest { applicationPageService.createPage(page).block(); Mockito.when(gitFileUtils.saveApplicationToLocalRepo( - Mockito.any(Path.class), Mockito.any(ApplicationJson.class), Mockito.anyString())) + any(Path.class), any(ApplicationJson.class), Mockito.anyString())) .thenReturn(Mono.just(Paths.get(""))); Mockito.when(gitExecutor.commitApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyBoolean())) .thenReturn(Mono.just("committed successfully")); - Mockito.when(gitExecutor.checkoutToBranch(Mockito.any(Path.class), Mockito.anyString())) + Mockito.when(gitExecutor.checkoutToBranch(any(Path.class), Mockito.anyString())) .thenReturn(Mono.just(true)); Mockito.when(gitExecutor.pushApplication( - Mockito.any(Path.class), + any(Path.class), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), @@ -4155,13 +4069,7 @@ public class GitServiceCETest { ApplicationJson applicationJson = createAppJson(filePath).block(); assert applicationJson != null; // the list of branches does not contain the develop branch - Mockito.when(gitExecutor.listBranches( - Mockito.any(Path.class), - Mockito.anyString(), - Mockito.anyString(), - Mockito.anyString(), - eq(false))) - .thenReturn(Mono.just(branches)); + Mockito.when(gitExecutor.listBranches(Mockito.any(Path.class))).thenReturn(Mono.just(branches)); Mockito.when(gitExecutor.fetchRemote( Mockito.any(Path.class), Mockito.anyString(),