]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9991 Clean up remaining references to P/R
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 20 Oct 2017 13:28:40 +0000 (15:28 +0200)
committerDuarte Meneses <duarte.meneses@sonarsource.com>
Fri, 20 Oct 2017 14:45:46 +0000 (16:45 +0200)
31 files changed:
server/sonar-server/src/main/java/org/sonar/ce/settings/ProjectConfigurationFactory.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolder.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/Branch.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolder.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutor.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersister.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/DefaultBranchImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/component/MergeBranchComponentUuids.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/duplication/CrossProjectDuplicationStatusHolderImpl.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueLifecycle.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/issue/IssueTrackingDelegator.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoDbLoader.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/BuildComponentTreeStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/PersistComponentsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStep.java
server/sonar-server/src/main/java/org/sonar/server/computation/task/projectanalysis/step/SendIssueNotificationsStep.java
server/sonar-server/src/test/java/org/sonar/ce/settings/ProjectConfigurationFactoryTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/AnalysisMetadataHolderRule.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/analysis/MutableAnalysisMetadataHolderRule.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/api/posttask/PostProjectAnalysisTasksExecutorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/BranchLoaderTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/BranchPersisterTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/component/ConfigurationRepositoryTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IntegrateIssuesVisitorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/issue/IssueTrackingDelegatorTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/scm/ScmInfoDbLoaderTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/BuildComponentTreeStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/QualityGateEventsStepTest.java
server/sonar-server/src/test/java/org/sonar/server/computation/task/projectanalysis/step/ReportPersistComponentsStepTest.java

index 2c53384e7441b01f9f156083d67fdac4c05783fb..7c99ff5a172e84cc66b4d21ac25dcea05d0b590f 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.ce.settings;
 
-import java.util.Optional;
 import org.sonar.api.ce.ComputeEngineSide;
 import org.sonar.api.config.Configuration;
 import org.sonar.api.config.Settings;
@@ -41,11 +40,10 @@ public class ProjectConfigurationFactory {
     this.dbClient = dbClient;
   }
 
-  public Configuration newProjectConfiguration(String projectKey, Optional<Branch> branch) {
+  public Configuration newProjectConfiguration(String projectKey, Branch branch) {
     Settings projectSettings = new ChildSettings(globalSettings);
     addSettings(projectSettings, projectKey);
-    getBranchName(branch).ifPresent(
-      b -> addSettings(projectSettings, generateBranchKey(projectKey, b)));
+    addSettings(projectSettings, generateBranchKey(projectKey, branch.getName()));
     return new ConfigurationBridge(projectSettings);
   }
 
@@ -54,15 +52,4 @@ public class ProjectConfigurationFactory {
       .selectProjectProperties(componentDbKey)
       .forEach(property -> settings.setProperty(property.getKey(), property.getValue()));
   }
-
-  private static Optional<String> getBranchName(Optional<Branch> branchOpt) {
-    if (!branchOpt.isPresent()) {
-      return Optional.empty();
-    }
-    Branch branch = branchOpt.get();
-    if (!branch.isLegacyFeature() && !branch.isMain()) {
-      return Optional.of(branch.getName());
-    }
-    return Optional.empty();
-  }
 }
index a1bf583932cabec11b60502ee7ce2b778fd1e80a..b8913710463354055cf468b36a184ac915db1225 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.computation.task.projectanalysis.analysis;
 
 import java.util.Map;
-import java.util.Optional;
 import javax.annotation.CheckForNull;
 import org.sonar.server.qualityprofile.QualityProfile;
 
@@ -84,12 +83,9 @@ public interface AnalysisMetadataHolder {
   boolean isCrossProjectDuplicationEnabled();
 
   /**
-   * Branch is present whatever the type of branch (long or short, main or not). However
-   * it is absent when analyzing a pull request.
-   *
-   * @throws IllegalStateException if branch has not been set
+   * Branch being analyzed. Can be of any type: long or short, main or not. 
    */
-  Optional<Branch> getBranch();
+  Branch getBranch();
 
   /**
    * The project as represented by the main branch. It is used to load settings
index fae786e5d59999b1be01d8650709fb63c86b648e..5924ff97bf4d13468e57324c47f19d9d29b00166 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.computation.task.projectanalysis.analysis;
 
 import com.google.common.collect.ImmutableMap;
 import java.util.Map;
-import java.util.Optional;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.db.component.BranchType;
@@ -123,16 +122,16 @@ public class AnalysisMetadataHolderImpl implements MutableAnalysisMetadataHolder
   }
 
   @Override
-  public MutableAnalysisMetadataHolder setBranch(@Nullable Branch branch) {
+  public MutableAnalysisMetadataHolder setBranch(Branch branch) {
     checkState(!this.branch.isInitialized(), "Branch has already been set");
     this.branch.setProperty(branch);
     return this;
   }
 
   @Override
-  public Optional<Branch> getBranch() {
+  public Branch getBranch() {
     checkState(branch.isInitialized(), BRANCH_NOT_SET);
-    return Optional.ofNullable(branch.getProperty());
+    return branch.getProperty();
   }
 
   @Override
index 7cbc50bac6af21390ee24cf195f8a174beae9985..a9af89b90f76a799c7ac7c04bdcf47056aae33aa 100644 (file)
@@ -43,8 +43,8 @@ public interface Branch extends ComponentKeyGenerator {
   String getName();
 
   /**
-   * For short living branches, indicates the branch from which it was forked.
-   * It will be empty for other types of branches.
+   * Indicates the branch from which it was forked.
+   * It will be empty for main branches or legacy branches.
    */
   Optional<String> getMergeBranchUuid();
 
index 4b5477caf8c423482e0622582a1a2c9c4df0d9cf..5e89e938320a78e15039f105b6069e42cbba2944 100644 (file)
@@ -53,7 +53,7 @@ public interface MutableAnalysisMetadataHolder extends AnalysisMetadataHolder {
   /**
    * @throws IllegalStateException if branch has already been set
    */
-  MutableAnalysisMetadataHolder setBranch(@Nullable Branch branch);
+  MutableAnalysisMetadataHolder setBranch(Branch branch);
 
   /**
    * @throws IllegalStateException if project has already been set
index 8c8f367a88b49c7f7048e5b967e9e3159be5350b..ab8eef8c46546ae350563ee533aa10be952f3f70 100644 (file)
@@ -167,10 +167,9 @@ public class PostProjectAnalysisTasksExecutor implements ComputationStepExecutor
 
   @CheckForNull
   private BranchImpl createBranch() {
-    Optional<org.sonar.server.computation.task.projectanalysis.analysis.Branch> analysisBranchOpt = analysisMetadataHolder.getBranch();
-    if (analysisBranchOpt.isPresent() && !analysisBranchOpt.get().isLegacyFeature()) {
-      org.sonar.server.computation.task.projectanalysis.analysis.Branch branch = analysisBranchOpt.get();
-      return new BranchImpl(branch.isMain(), branch.getName(), Branch.Type.valueOf(branch.getType().name()));
+    org.sonar.server.computation.task.projectanalysis.analysis.Branch analysisBranch = analysisMetadataHolder.getBranch();
+    if (!analysisBranch.isLegacyFeature()) {
+      return new BranchImpl(analysisBranch.isMain(), analysisBranch.getName(), Branch.Type.valueOf(analysisBranch.getType().name()));
     }
     return null;
   }
index 2f6cd17882621ae2439a2275c180c0d132522f03..7c3764bac7c56e46df6397e69a0c2f0329ae199c 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.computation.task.projectanalysis.component;
 
 import java.util.Date;
-import java.util.Optional;
 import javax.annotation.Nullable;
 import org.sonar.api.utils.System2;
 import org.sonar.db.DbClient;
@@ -47,12 +46,7 @@ public class BranchPersister {
   }
 
   public void persist(DbSession dbSession) {
-    Optional<Branch> branchOpt = analysisMetadataHolder.getBranch();
-    if (!branchOpt.isPresent()) {
-      return;
-    }
-
-    Branch branch = branchOpt.get();
+    Branch branch = analysisMetadataHolder.getBranch();
     String branchUuid = treeRootHolder.getRoot().getUuid();
 
     com.google.common.base.Optional<ComponentDto> branchComponentDtoOpt = dbClient.componentDao().selectByUuid(dbSession, branchUuid);
index 3f4461ba006316cbb799d04a70ebaaf4b580af96..2f0c4d35a486332c9914fe2caa892a0edd59887f 100644 (file)
@@ -35,8 +35,7 @@ import static org.apache.commons.lang.StringUtils.trimToNull;
 /**
  * The default (and legacy) implementation of {@link Branch}. It is used
  * when scanner is configured with parameter "sonar.branch" or when no branch is provided and the branch plugin is not installed.
- * A legacy branch is implemented as a fork of the project, so any branch
- * is considered as "main".
+ * A legacy branch is implemented as a fork of the project, so any branch is considered as "main".
  */
 public class DefaultBranchImpl implements Branch {
   private final String branchName;
index e91d1fc8c4a4b8ae2c3c363daee2774522f110a7..15a861d68d1c566ccb4bd7c49c0ea74902ea7d58 100644 (file)
@@ -46,7 +46,7 @@ public class MergeBranchComponentUuids {
 
   private void lazyInit() {
     if (uuidsByKey == null) {
-      String mergeBranchUuid = analysisMetadataHolder.getBranch().get().getMergeBranchUuid().get();
+      String mergeBranchUuid = analysisMetadataHolder.getBranch().getMergeBranchUuid().get();
 
       uuidsByKey = new HashMap<>();
       try (DbSession dbSession = dbClient.openSession(false)) {
index 4a463e16c695881316c4d830000f85c6bce2c665..d175b4d3db6f7ce77382aa02e3836bb7f8091610 100644 (file)
  */
 package org.sonar.server.computation.task.projectanalysis.duplication;
 
-import java.util.Optional;
 import javax.annotation.CheckForNull;
 import org.picocontainer.Startable;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
 
 import static com.google.common.base.Preconditions.checkState;
 
@@ -50,8 +48,7 @@ public class CrossProjectDuplicationStatusHolderImpl implements CrossProjectDupl
   @Override
   public void start() {
     boolean enabledInReport = analysisMetadataHolder.isCrossProjectDuplicationEnabled();
-    Optional<Branch> branch = analysisMetadataHolder.getBranch();
-    boolean supportedByBranch = !branch.isPresent() || branch.get().supportsCrossProjectCpd();
+    boolean supportedByBranch = analysisMetadataHolder.getBranch().supportsCrossProjectCpd();
     if (enabledInReport && supportedByBranch) {
       LOGGER.debug("Cross project duplication is enabled");
       this.enabled = true;
index b8f51767ed09d4ccc83627365b76af6897d46f5b..16025603b0a1bcd1c1452b09fb52c9003709b49f 100644 (file)
@@ -75,12 +75,12 @@ public class IssueLifecycle {
     raw.setKey(Uuids.create());
     raw.setNew(false);
     copyIssueAttributes(raw, base);
-    raw.setFieldChange(changeContext, IssueFieldsSetter.FROM_LONG_BRANCH, fromLongBranchName, analysisMetadataHolder.getBranch().get().getName());
+    raw.setFieldChange(changeContext, IssueFieldsSetter.FROM_LONG_BRANCH, fromLongBranchName, analysisMetadataHolder.getBranch().getName());
   }
 
   public void mergeConfirmedOrResolvedFromShortLivingBranch(DefaultIssue raw, DefaultIssue base, String fromShortBranchName) {
     copyIssueAttributes(raw, base);
-    raw.setFieldChange(changeContext, IssueFieldsSetter.FROM_SHORT_BRANCH, fromShortBranchName, analysisMetadataHolder.getBranch().get().getName());
+    raw.setFieldChange(changeContext, IssueFieldsSetter.FROM_SHORT_BRANCH, fromShortBranchName, analysisMetadataHolder.getBranch().getName());
   }
 
   private void copyIssueAttributes(DefaultIssue to, DefaultIssue from) {
index 655b482c58db82d82b08aea5811aeb3b92fe3a9d..5e2275fc1f75d261366f193bb7cc8e13ba378fd1 100644 (file)
  */
 package org.sonar.server.computation.task.projectanalysis.issue;
 
-import static java.util.Collections.emptyList;
-import static java.util.Collections.emptyMap;
-
-import java.util.Optional;
-
 import org.sonar.core.issue.DefaultIssue;
 import org.sonar.core.issue.tracking.Tracking;
 import org.sonar.db.component.BranchType;
@@ -31,6 +26,9 @@ import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetada
 import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 
+import static java.util.Collections.emptyList;
+import static java.util.Collections.emptyMap;
+
 public class IssueTrackingDelegator {
   private final ShortBranchTrackerExecution shortBranchTracker;
   private final TrackerExecution tracker;
@@ -65,10 +63,8 @@ public class IssueTrackingDelegator {
    */
   private boolean isFirstAnalysisSecondaryLongLivingBranch() {
     if (analysisMetadataHolder.isFirstAnalysis()) {
-      Optional<Branch> branch = analysisMetadataHolder.getBranch();
-      if (branch.isPresent()) {
-        return !branch.get().isMain() && branch.get().getType() == BranchType.LONG;
-      }
+      Branch branch = analysisMetadataHolder.getBranch();
+      return !branch.isMain() && branch.getType() == BranchType.LONG;
     }
     return false;
   }
index f20a90f3bf04c497f429269f3180d3cca1995ef5..84cf8790054e15f13055418034fc96b019bd3298 100644 (file)
@@ -71,8 +71,9 @@ public class ScmInfoDbLoader {
       return Optional.of(file.getUuid());
     }
 
-    Optional<Branch> branch = analysisMetadataHolder.getBranch();
-    if (branch.isPresent()) {
+    // at this point, it's the first analysis but had copyFromPrevious flag true
+    Branch branch = analysisMetadataHolder.getBranch();
+    if (branch.getMergeBranchUuid().isPresent()) {
       return Optional.ofNullable(mergeBranchComponentUuid.getUuid(file.getKey()));
     }
 
index 4c5b96896aa9fe4d40418f41f0075934ee66eb9f..fffb6cb5db0f784c4f9b13515bbddaeb2e847120 100644 (file)
@@ -19,8 +19,6 @@
  */
 package org.sonar.server.computation.task.projectanalysis.step;
 
-import java.util.Optional;
-import java.util.stream.Stream;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.sonar.db.DbClient;
@@ -92,22 +90,17 @@ public class BuildComponentTreeStep implements ComputationStep {
   }
 
   private ComponentKeyGenerator loadKeyGenerator() {
-    return Stream.of(analysisMetadataHolder.getBranch(), Optional.of(new DefaultBranchImpl()))
-      .filter(Optional::isPresent)
-      .flatMap(x -> x.map(Stream::of).orElseGet(Stream::empty))
-      .findFirst()
-      .get();
+    return analysisMetadataHolder.getBranch();
   }
 
   private ComponentKeyGenerator loadPublicKeyGenerator() {
-    Optional<Branch> branch = analysisMetadataHolder.getBranch();
-    if (!branch.isPresent()) {
-      // Used for pull request
+    Branch branch = analysisMetadataHolder.getBranch();
+
+    // for non-legacy branches, the public key is different from the DB key.
+    if (!branch.isLegacyFeature() && !branch.isMain()) {
       return new DefaultBranchImpl();
     }
-    return branch.filter(Branch::isLegacyFeature)
-      .map(b -> new DefaultBranchImpl(b.getName()))
-      .orElseGet(DefaultBranchImpl::new);
+    return branch;
   }
 
   @CheckForNull
index 216843767c01ac108e9e432ef4626b03b91db727..a49b6eef2ae0790f6a7995eff8a5591bd568b527 100644 (file)
  */
 package org.sonar.server.computation.task.projectanalysis.step;
 
-import static com.google.common.collect.FluentIterable.from;
-import static java.util.Optional.ofNullable;
-import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
-import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
-import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent;
-import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
-
+import com.google.common.base.Predicate;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Map;
@@ -33,11 +27,9 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.function.Function;
 import java.util.stream.Collectors;
-
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
-
 import org.apache.commons.io.FilenameUtils;
 import org.apache.commons.lang.StringUtils;
 import org.sonar.api.resources.Qualifiers;
@@ -49,7 +41,6 @@ import org.sonar.db.DbSession;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentUpdateDto;
 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
 import org.sonar.server.computation.task.projectanalysis.component.BranchPersister;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
@@ -62,7 +53,12 @@ import org.sonar.server.computation.task.projectanalysis.component.PathAwareVisi
 import org.sonar.server.computation.task.projectanalysis.component.TreeRootHolder;
 import org.sonar.server.computation.task.step.ComputationStep;
 
-import com.google.common.base.Predicate;
+import static com.google.common.collect.FluentIterable.from;
+import static java.util.Optional.ofNullable;
+import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
+import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
+import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent;
+import static org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor.Order.PRE_ORDER;
 
 /**
  * Persist report components
@@ -127,8 +123,7 @@ public class PersistComponentsStep implements ComputationStep {
    */
   @CheckForNull
   private String loadProjectUuidOfMainBranch() {
-    Optional<Branch> branch = analysisMetadataHolder.getBranch();
-    if (branch.isPresent() && !branch.get().isMain()) {
+    if (!analysisMetadataHolder.getBranch().isMain()) {
       return analysisMetadataHolder.getProject().getUuid();
     }
     return null;
index c49a13c453d6cc628d77889f67fd8be9e6dac0ad..c8ec6f298a5fab2bb01035c25d2c20f2dca618a2 100644 (file)
@@ -26,6 +26,7 @@ import org.sonar.api.notifications.Notification;
 import org.sonar.api.utils.log.Logger;
 import org.sonar.api.utils.log.Loggers;
 import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetadataHolder;
+import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 import org.sonar.server.computation.task.projectanalysis.component.ComponentVisitor;
 import org.sonar.server.computation.task.projectanalysis.component.CrawlerDepthLimit;
@@ -136,8 +137,10 @@ public class QualityGateEventsStep implements ComputationStep {
       .setFieldValue("alertText", rawStatus.getText())
       .setFieldValue("alertLevel", rawStatus.getStatus().toString())
       .setFieldValue("isNewAlert", Boolean.toString(isNewAlert));
-    analysisMetadataHolder.getBranch().filter(b -> !b.isMain())
-      .ifPresent(branch -> notification.setFieldValue("branch", branch.getName()));
+    Branch branch = analysisMetadataHolder.getBranch();
+    if (!branch.isMain()) {
+      notification.setFieldValue("branch", branch.getName());
+    }
     notificationService.deliver(notification);
   }
 
index b54344cc019ff6a5121ede34ee021873cf5da36e..eb3f044c9e3f165f5cf33814204a0d00a24bded0 100644 (file)
@@ -186,7 +186,8 @@ public class SendIssueNotificationsStep implements ComputationStep {
   }
 
   private String getBranchName() {
-    return analysisMetadataHolder.getBranch().filter(b -> !b.isMain()).map(Branch::getName).orElse(null);
+    Branch branch = analysisMetadataHolder.getBranch();
+    return branch.isMain() ? null : branch.getName();
   }
 
 }
index 1388284bec0a54584ea3b801fbd08cc8753692bb..2cf1dd377596a6d0dec483234144815ed99023b9 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.ce.settings;
 
-import java.util.Optional;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Configuration;
@@ -27,6 +26,7 @@ import org.sonar.api.config.internal.MapSettings;
 import org.sonar.db.DbTester;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
+import org.sonar.server.computation.task.projectanalysis.component.DefaultBranchImpl;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
@@ -47,7 +47,7 @@ public class ProjectConfigurationFactoryTest {
   @Test
   public void return_global_settings() {
     settings.setProperty("key", "value");
-    Configuration config = underTest.newProjectConfiguration(PROJECT_KEY, Optional.empty());
+    Configuration config = underTest.newProjectConfiguration(PROJECT_KEY, new DefaultBranchImpl());
 
     assertThat(config.get("key")).hasValue("value");
   }
@@ -60,7 +60,7 @@ public class ProjectConfigurationFactoryTest {
       newComponentPropertyDto(project).setKey("2").setValue("val2"),
       newComponentPropertyDto(project).setKey("3").setValue("val3"));
 
-    Configuration config = underTest.newProjectConfiguration(project.getDbKey(), Optional.empty());
+    Configuration config = underTest.newProjectConfiguration(project.getDbKey(), new DefaultBranchImpl());
 
     assertThat(config.get("1")).hasValue("val1");
     assertThat(config.get("2")).hasValue("val2");
@@ -73,7 +73,7 @@ public class ProjectConfigurationFactoryTest {
     ComponentDto project = db.components().insertPrivateProject();
     db.properties().insertProperties(newComponentPropertyDto(project).setKey("key").setValue("value2"));
 
-    Configuration projectConfig = underTest.newProjectConfiguration(project.getDbKey(), Optional.empty());
+    Configuration projectConfig = underTest.newProjectConfiguration(project.getDbKey(), new DefaultBranchImpl());
 
     assertThat(projectConfig.get("key")).hasValue("value2");
   }
@@ -84,7 +84,7 @@ public class ProjectConfigurationFactoryTest {
     ComponentDto branch = db.components().insertProjectBranch(project);
     db.properties().insertProperties(newComponentPropertyDto(branch).setKey("sonar.leak.period").setValue("1"));
 
-    Configuration config = underTest.newProjectConfiguration(project.getKey(), Optional.of(createBranch(branch.getBranch(), false)));
+    Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getBranch(), false));
 
     assertThat(config.get("sonar.leak.period")).hasValue("1");
   }
@@ -96,7 +96,7 @@ public class ProjectConfigurationFactoryTest {
     ComponentDto branch = db.components().insertProjectBranch(project);
     db.properties().insertProperties(newComponentPropertyDto(branch).setKey("sonar.leak.period").setValue("1"));
 
-    Configuration config = underTest.newProjectConfiguration(project.getKey(), Optional.of(createBranch(branch.getBranch(), false)));
+    Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getBranch(), false));
 
     assertThat(config.get("global")).hasValue("global_value");
     assertThat(config.get("sonar.leak.period")).hasValue("1");
@@ -109,7 +109,7 @@ public class ProjectConfigurationFactoryTest {
     ComponentDto branch = db.components().insertProjectBranch(project);
     db.properties().insertProperties(newComponentPropertyDto(branch).setKey("sonar.leak.period").setValue("1"));
 
-    Configuration config = underTest.newProjectConfiguration(project.getKey(), Optional.of(createBranch(branch.getBranch(), false)));
+    Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getBranch(), false));
 
     assertThat(config.get("key")).hasValue("value");
     assertThat(config.get("sonar.leak.period")).hasValue("1");
@@ -122,7 +122,7 @@ public class ProjectConfigurationFactoryTest {
     ComponentDto branch = db.components().insertProjectBranch(project);
     db.properties().insertProperties(newComponentPropertyDto(branch).setKey("sonar.leak.period").setValue("2"));
 
-    Configuration config = underTest.newProjectConfiguration(project.getKey(), Optional.of(createBranch(branch.getBranch(), false)));
+    Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getBranch(), false));
 
     assertThat(config.get("sonar.leak.period")).hasValue("2");
   }
@@ -134,7 +134,7 @@ public class ProjectConfigurationFactoryTest {
     Branch branch = createBranch("master", true);
     when(branch.isMain()).thenReturn(true);
 
-    Configuration config = underTest.newProjectConfiguration(project.getKey(), Optional.of(createBranch(branch.getName(), true)));
+    Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getName(), true));
 
     assertThat(config.get("sonar.leak.period")).hasValue("1");
   }
@@ -146,7 +146,7 @@ public class ProjectConfigurationFactoryTest {
     Branch branch = createBranch("legacy", true);
     when(branch.isLegacyFeature()).thenReturn(true);
 
-    Configuration config = underTest.newProjectConfiguration(project.getKey(), Optional.of(createBranch(branch.getName(), true)));
+    Configuration config = underTest.newProjectConfiguration(project.getKey(), createBranch(branch.getName(), true));
 
     assertThat(config.get("sonar.leak.period")).hasValue("1");
   }
index 998087518f38310ec23551f0513be0a3907c8ff7..ec05e37eba387ad0a69004492578b751f0d11bd3 100644 (file)
@@ -220,7 +220,7 @@ public class AnalysisMetadataHolderImplTest {
 
     underTest.setBranch(new DefaultBranchImpl("master"));
 
-    assertThat(underTest.getBranch().get().getName()).isEqualTo("master");
+    assertThat(underTest.getBranch().getName()).isEqualTo("master");
   }
 
   @Test
index df4faae3fcfbc5cbdb799b96a66e1fd0548f72c6..f1fb6e2a42c212b1f871ba96cd5891b71118bbf4 100644 (file)
@@ -21,7 +21,6 @@ package org.sonar.server.computation.task.projectanalysis.analysis;
 
 import java.util.Date;
 import java.util.Map;
-import java.util.Optional;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.junit.rules.ExternalResource;
@@ -143,15 +142,15 @@ public class AnalysisMetadataHolderRule extends ExternalResource implements Muta
   }
 
   @Override
-  public AnalysisMetadataHolderRule setBranch(@Nullable Branch branch) {
+  public AnalysisMetadataHolderRule setBranch(Branch branch) {
     this.branch.setProperty(branch);
     return this;
   }
 
   @Override
-  public Optional<Branch> getBranch() {
+  public Branch getBranch() {
     checkState(branch.isInitialized(), "Branch has not been set");
-    return Optional.ofNullable(branch.getProperty());
+    return branch.getProperty();
   }
 
   @Override
index 787d5ef3e0d9f6e309e1052a7bf2a7399a6df746..49c6938250946eeb096edd577ff2c0b242430f1a 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.computation.task.projectanalysis.analysis;
 
 import java.util.Map;
-import java.util.Optional;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import org.junit.rules.ExternalResource;
@@ -100,7 +99,7 @@ public class MutableAnalysisMetadataHolderRule extends ExternalResource implemen
   }
 
   @Override
-  public Optional<Branch> getBranch() {
+  public Branch getBranch() {
     return delegate.getBranch();
   }
 
index 1c9a6f786e95ba5367f5a0fc89a696dd2c1835e2..484180fabb25ad158fa4b7d802854f46fdc8caf6 100644 (file)
@@ -101,7 +101,9 @@ public class PostProjectAnalysisTasksExecutorTest {
     qualityGateStatusHolder.setStatus(QualityGateStatus.OK, ImmutableMap.of(
       CONDITION_1, ConditionStatus.create(ConditionStatus.EvaluationStatus.OK, "value"),
       CONDITION_2, ConditionStatus.NO_VALUE_STATUS));
-    analysisMetadataHolder.setBranch(null);
+    Branch branch = mock(Branch.class);
+    when(branch.getType()).thenReturn(BranchType.LONG);
+    analysisMetadataHolder.setBranch(branch);
   }
 
   @Test
@@ -215,15 +217,6 @@ public class PostProjectAnalysisTasksExecutorTest {
     assertThat(projectAnalysisArgumentCaptor.getValue().getAnalysis()).isEmpty();
   }
 
-  @Test
-  public void branch_is_empty_when_not_set_in_AnalysisMetadataHolder() {
-    underTest.finished(false);
-
-    verify(postProjectAnalysisTask).finished(projectAnalysisArgumentCaptor.capture());
-
-    assertThat(projectAnalysisArgumentCaptor.getValue().getBranch()).isEmpty();
-  }
-
   @Test
   public void branch_is_empty_when_legacy_branch_implementation_is_used() {
     analysisMetadataHolder.setBranch(new DefaultBranchImpl("feature/foo"));
index 3ed00537c4d5d3624ddc1d6cf0dfd6e74027e169..84ac5dd0d255646a3f823300faee8dc06c5d46ca 100644 (file)
@@ -58,9 +58,9 @@ public class BranchLoaderTest {
 
     new BranchLoader(metadataHolder).load(metadata);
 
-    assertThat(metadataHolder.getBranch()).isPresent();
+    assertThat(metadataHolder.getBranch()).isNotNull();
 
-    Branch branch = metadataHolder.getBranch().get();
+    Branch branch = metadataHolder.getBranch();
     assertThat(branch.isMain()).isTrue();
     assertThat(branch.getName()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
   }
@@ -73,9 +73,9 @@ public class BranchLoaderTest {
 
     new BranchLoader(metadataHolder).load(metadata);
 
-    assertThat(metadataHolder.getBranch()).isPresent();
+    assertThat(metadataHolder.getBranch()).isNotNull();
 
-    Branch branch = metadataHolder.getBranch().get();
+    Branch branch = metadataHolder.getBranch();
     assertThat(branch.isMain()).isTrue();
     assertThat(branch.getName()).isEqualTo("foo");
   }
@@ -89,9 +89,9 @@ public class BranchLoaderTest {
     FakeDelegate delegate = new FakeDelegate();
     new BranchLoader(metadataHolder, delegate).load(metadata);
 
-    assertThat(metadataHolder.getBranch()).isPresent();
+    assertThat(metadataHolder.getBranch()).isNotNull();
 
-    Branch branch = metadataHolder.getBranch().get();
+    Branch branch = metadataHolder.getBranch();
     assertThat(branch.isMain()).isTrue();
     assertThat(branch.getName()).isEqualTo("foo");
   }
index 46e56b62973729b44b6229a9568f933068b93965..3bb6b653b72a4d601029d67589ddb761b45a9f43 100644 (file)
@@ -64,13 +64,6 @@ public class BranchPersisterTest {
     underTest.persist(dbTester.getSession());
   }
 
-  @Test
-  public void skip_if_no_branch() {
-    analysisMetadataHolder.setBranch(null);
-    underTest.persist(dbTester.getSession());
-    dbTester.assertTableDoesNotExist("project_branch");
-  }
-
   @Test
   public void persist_secondary_branch() {
     analysisMetadataHolder.setBranch(createBranch(BranchType.LONG, false, "branch"));
index 139407dd6f530b39f978c3999b2643aba35f72d9..a1a8dd2d3950655fb4b589b7ca5ad29bdbb50548 100644 (file)
@@ -19,6 +19,7 @@
  */
 package org.sonar.server.computation.task.projectanalysis.component;
 
+import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonar.api.config.Configuration;
@@ -46,12 +47,20 @@ public class ConfigurationRepositoryTest {
 
   private DbClient dbClient = db.getDbClient();
   private MapSettings globalSettings = new MapSettings();
+  private Branch branch = mock(Branch.class);
   private AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule();
-  private ConfigurationRepository underTest = new ConfigurationRepositoryImpl(analysisMetadataHolder, new ProjectConfigurationFactory(globalSettings, dbClient));
+  private ConfigurationRepository underTest;
+
+  @Before
+  public void setUp() {
+    when(branch.getName()).thenReturn("branchName");
+    analysisMetadataHolder.setBranch(branch);
+    underTest = new ConfigurationRepositoryImpl(analysisMetadataHolder, new ProjectConfigurationFactory(globalSettings, dbClient));
+  }
 
   @Test
   public void get_project_settings_from_global_settings() {
-    analysisMetadataHolder.setProject(PROJECT).setBranch(null);
+    analysisMetadataHolder.setProject(PROJECT);
     globalSettings.setProperty("key", "value");
 
     Configuration config = underTest.getConfiguration();
@@ -62,7 +71,7 @@ public class ConfigurationRepositoryTest {
   @Test
   public void get_project_settings_from_db() {
     ComponentDto project = db.components().insertPrivateProject();
-    analysisMetadataHolder.setProject(Project.copyOf(project)).setBranch(null);
+    analysisMetadataHolder.setProject(Project.copyOf(project));
     insertProjectProperty(project, "key", "value");
 
     Configuration config = underTest.getConfiguration();
@@ -72,7 +81,7 @@ public class ConfigurationRepositoryTest {
 
   @Test
   public void call_twice_get_project_settings() {
-    analysisMetadataHolder.setProject(PROJECT).setBranch(null);
+    analysisMetadataHolder.setProject(PROJECT);
     globalSettings.setProperty("key", "value");
 
     Configuration config = underTest.getConfiguration();
@@ -87,7 +96,7 @@ public class ConfigurationRepositoryTest {
     globalSettings.setProperty("key", "value1");
     ComponentDto project = db.components().insertPrivateProject();
     insertProjectProperty(project, "key", "value2");
-    analysisMetadataHolder.setProject(Project.copyOf(project)).setBranch(null);
+    analysisMetadataHolder.setProject(Project.copyOf(project));
 
     Configuration config = underTest.getConfiguration();
     assertThat(config.get("key")).hasValue("value2");
@@ -97,7 +106,7 @@ public class ConfigurationRepositoryTest {
   public void project_settings_are_cached_to_avoid_db_access() {
     ComponentDto project = db.components().insertPrivateProject();
     insertProjectProperty(project, "key", "value");
-    analysisMetadataHolder.setProject(Project.copyOf(project)).setBranch(null);
+    analysisMetadataHolder.setProject(Project.copyOf(project));
 
     Configuration config = underTest.getConfiguration();
     assertThat(config.get("key")).hasValue("value");
index 0f695c19d65f4dedd017b7e417f48a2f3bcfc2dd..e9438b1f167cff5de74860f91cdecd593d7ed160 100644 (file)
@@ -267,7 +267,7 @@ public class IntegrateIssuesVisitorTest {
     Branch branch = mock(Branch.class);
     when(branch.isMain()).thenReturn(false);
     when(branch.getType()).thenReturn(BranchType.LONG);
-    when(analysisMetadataHolder.getBranch()).thenReturn(java.util.Optional.of(branch));
+    when(analysisMetadataHolder.getBranch()).thenReturn(branch);
 
     RuleKey ruleKey = RuleTesting.XOO_X1;
     // Issue from main branch has severity major
index 966f98ef6235835becdd53b69d8411c8c113f1e6..841cf0e0546636c1feeafdebeadb700c643a1402 100644 (file)
  */
 package org.sonar.server.computation.task.projectanalysis.issue;
 
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyZeroInteractions;
-import static org.mockito.Mockito.when;
-
-import java.util.Optional;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
@@ -37,6 +30,11 @@ import org.sonar.server.computation.task.projectanalysis.analysis.AnalysisMetada
 import org.sonar.server.computation.task.projectanalysis.analysis.Branch;
 import org.sonar.server.computation.task.projectanalysis.component.Component;
 
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
+
 public class IssueTrackingDelegatorTest {
   @Mock
   private ShortBranchTrackerExecution shortBranchTracker;
@@ -65,7 +63,7 @@ public class IssueTrackingDelegatorTest {
   @Test
   public void delegate_regular_tracker() {
     when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(false);
-    when(analysisMetadataHolder.getBranch()).thenReturn(Optional.empty());
+    when(analysisMetadataHolder.getBranch()).thenReturn(mock(Branch.class));
 
     underTest.track(component);
 
@@ -79,7 +77,7 @@ public class IssueTrackingDelegatorTest {
     Branch branch = mock(Branch.class);
     when(branch.getType()).thenReturn(BranchType.LONG);
     when(branch.isMain()).thenReturn(false);
-    when(analysisMetadataHolder.getBranch()).thenReturn(Optional.of(branch));
+    when(analysisMetadataHolder.getBranch()).thenReturn(branch);
     when(analysisMetadataHolder.isFirstAnalysis()).thenReturn(true);
 
     underTest.track(component);
@@ -94,7 +92,7 @@ public class IssueTrackingDelegatorTest {
   public void delegate_short_branch_tracker() {
     Branch branch = mock(Branch.class);
     when(branch.getType()).thenReturn(BranchType.SHORT);
-    when(analysisMetadataHolder.getBranch()).thenReturn(Optional.empty());
+    when(analysisMetadataHolder.getBranch()).thenReturn(mock(Branch.class));
     when(analysisMetadataHolder.isShortLivingBranch()).thenReturn(true);
 
     underTest.track(component);
index 22b950770fb00d9ff4c98260b316aed9a5c5934d..ca10c46e0f729de5a9ad790ddc08f8976c4b13b3 100644 (file)
@@ -22,6 +22,7 @@ package org.sonar.server.computation.task.projectanalysis.scm;
 import com.google.common.collect.ImmutableList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Optional;
 import javax.annotation.Nullable;
 import org.junit.Rule;
 import org.junit.Test;
@@ -94,6 +95,7 @@ public class ScmInfoDbLoaderTest {
     analysisMetadataHolder.setBaseAnalysis(null);
     analysisMetadataHolder.setBranch(branch);
     String mergeFileUuid = "mergeFileUuid";
+    when(branch.getMergeBranchUuid()).thenReturn(Optional.of("mergeBranchUuid"));
 
     when(mergeBranchComponentUuids.getUuid(FILE.getKey())).thenReturn(mergeFileUuid);
     addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1), mergeFileUuid);
@@ -109,6 +111,7 @@ public class ScmInfoDbLoaderTest {
     analysisMetadataHolder.setBaseAnalysis(null);
     analysisMetadataHolder.setBranch(branch);
     String mergeFileUuid = "mergeFileUuid";
+    when(branch.getMergeBranchUuid()).thenReturn(Optional.of("mergeBranchUuid"));
 
     when(mergeBranchComponentUuids.getUuid(FILE.getKey())).thenReturn(mergeFileUuid);
     addFileSourceInDb("henry", DATE_1, "rev-1", computeSourceHash(1) + "dif", mergeFileUuid);
@@ -131,9 +134,11 @@ public class ScmInfoDbLoaderTest {
   }
 
   @Test
-  public void not_read_in_db_on_first_analysis() throws Exception {
+  public void not_read_in_db_on_first_analysis_and_no_merge_branch() throws Exception {
+    Branch branch = mock(Branch.class);
+    when(branch.getMergeBranchUuid()).thenReturn(Optional.empty());
     analysisMetadataHolder.setBaseAnalysis(null);
-    analysisMetadataHolder.setBranch(null);
+    analysisMetadataHolder.setBranch(branch);
 
     addFileSourceInReport(1);
 
index 11ad345a60890f50ef2f952200208985d376d6f2..0afa4664e2ba6ec4bc8a5e41acac458a18015b4d 100644 (file)
@@ -24,7 +24,6 @@ import com.tngtech.java.junit.dataprovider.DataProviderRunner;
 import com.tngtech.java.junit.dataprovider.UseDataProvider;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Optional;
 import javax.annotation.Nullable;
 import org.junit.Rule;
 import org.junit.Test;
@@ -229,11 +228,7 @@ public class BuildComponentTreeStepTest {
 
   @Test
   public void generate_keys_when_using_main_branch() {
-    Branch branch = mock(Branch.class);
-    when(branch.getName()).thenReturn("origin/master");
-    when(branch.isMain()).thenReturn(true);
-    when(branch.isLegacyFeature()).thenReturn(false);
-    when(branch.generateKey(any(ScannerReport.Component.class), any(ScannerReport.Component.class))).thenReturn("generated");
+    Branch branch = new DefaultBranchImpl();
     analysisMetadataHolder.setRootComponentRef(ROOT_REF)
       .setAnalysisDate(ANALYSIS_DATE)
       .setProject(new Project("U1", REPORT_PROJECT_KEY, REPORT_PROJECT_KEY))
@@ -246,10 +241,10 @@ public class BuildComponentTreeStepTest {
 
     underTest.execute();
 
-    verifyComponent(ROOT_REF, "generated", REPORT_PROJECT_KEY, null);
-    verifyComponent(MODULE_REF, "generated", REPORT_MODULE_KEY, null);
-    verifyComponent(DIR_REF_1, "generated", REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, null);
-    verifyComponent(FILE_1_REF, "generated", REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, null);
+    verifyComponent(ROOT_REF, REPORT_PROJECT_KEY, REPORT_PROJECT_KEY, null);
+    verifyComponent(MODULE_REF, REPORT_MODULE_KEY, REPORT_MODULE_KEY, null);
+    verifyComponent(DIR_REF_1, REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1, null);
+    verifyComponent(FILE_1_REF, REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1, null);
   }
 
   @Test
@@ -272,26 +267,6 @@ public class BuildComponentTreeStepTest {
     verifyComponent(FILE_1_REF, REPORT_MODULE_KEY + ":origin/feature:" + REPORT_FILE_KEY_1, null);
   }
 
-  @Test
-  public void compute_keys_when_no_branch() {
-    analysisMetadataHolder.setRootComponentRef(ROOT_REF)
-      .setAnalysisDate(ANALYSIS_DATE)
-      .setProject(new Project("U1", REPORT_PROJECT_KEY, REPORT_PROJECT_KEY))
-      .setBranch(null);
-    BuildComponentTreeStep underTest = new BuildComponentTreeStep(dbClient, reportReader, treeRootHolder, analysisMetadataHolder);
-    reportReader.putComponent(componentWithKey(ROOT_REF, PROJECT, REPORT_PROJECT_KEY, MODULE_REF));
-    reportReader.putComponent(componentWithKey(MODULE_REF, MODULE, REPORT_MODULE_KEY, DIR_REF_1));
-    reportReader.putComponent(componentWithPath(DIR_REF_1, DIRECTORY, REPORT_DIR_KEY_1, FILE_1_REF));
-    reportReader.putComponent(componentWithPath(FILE_1_REF, FILE, REPORT_FILE_KEY_1));
-
-    underTest.execute();
-
-    verifyComponent(ROOT_REF, REPORT_PROJECT_KEY);
-    verifyComponent(MODULE_REF, REPORT_MODULE_KEY);
-    verifyComponent(DIR_REF_1, REPORT_MODULE_KEY + ":" + REPORT_DIR_KEY_1);
-    verifyComponent(FILE_1_REF, REPORT_MODULE_KEY + ":" + REPORT_FILE_KEY_1);
-  }
-
   @Test
   public void compute_keys_and_uuids_on_project_having_module_and_directory() {
     setAnalysisMetadataHolder();
index c5e2801cd3a7d6587621c3af384d972d4339d95a..9fea5a5dd0e86aa8bc1f660c9fd08e0148e8a781 100644 (file)
@@ -88,7 +88,7 @@ public class QualityGateEventsStepTest {
   public void setUp() {
     when(metricRepository.getByKey(ALERT_STATUS_KEY)).thenReturn(alertStatusMetric);
     analysisMetadataHolder.setProject(new Project(PROJECT_COMPONENT.getUuid(), PROJECT_COMPONENT.getKey(), PROJECT_COMPONENT.getName()));
-    analysisMetadataHolder.setBranch(null);
+    analysisMetadataHolder.setBranch(mock(Branch.class));
     treeRootHolder.setRoot(PROJECT_COMPONENT);
   }
 
index c03e8826dc9b46e5bb16dab8a723dd8a37d62a72..09c708162a488afb10d7c1764ee71ac5ac7e7c74 100644 (file)
@@ -901,14 +901,14 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
   private ComponentDto prepareBranch(String branchName, Consumer<ComponentDto>... populators) {
     ComponentDto dto = db.components().insertPrivateProject(db.organizations().insert(), populators);
     analysisMetadataHolder.setProject(Project.copyOf(dto));
-    analysisMetadataHolder.setBranch(new BranchImpl(branchName));
+    analysisMetadataHolder.setBranch(new TestBranch(branchName));
     return dto;
   }
 
-  private static class BranchImpl implements Branch {
+  private static class TestBranch implements Branch {
     private final String name;
 
-    public BranchImpl(String name) {
+    public TestBranch(String name) {
       this.name = name;
     }
 
@@ -944,7 +944,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
 
     @Override
     public String generateKey(ScannerReport.Component module, @Nullable ScannerReport.Component fileOrDir) {
-      String moduleKey =  module.getKey();
+      String moduleKey = module.getKey();
       if (fileOrDir == null || isEmpty(fileOrDir.getPath())) {
         return moduleKey;
       }