]> source.dussan.org Git - sonarqube.git/commitdiff
remove usage of Guava Optional from ComponentDao
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 27 Sep 2018 09:04:14 +0000 (11:04 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 4 Oct 2018 13:25:24 +0000 (15:25 +0200)
37 files changed:
server/sonar-ce-common/src/main/java/org/sonar/ce/queue/CeQueueImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchPersisterImpl.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/LoadReportAnalysisMetadataHolderStep.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStep.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/filemove/FileMoveDetectionStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentDao.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebHooksImpl.java
server/sonar-server/src/main/java/org/sonar/server/ce/queue/ReportSubmitter.java
server/sonar-server/src/main/java/org/sonar/server/ce/ws/CancelAction.java
server/sonar-server/src/main/java/org/sonar/server/ce/ws/TaskAction.java
server/sonar-server/src/main/java/org/sonar/server/component/ComponentFinder.java
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/DuplicationsParser.java
server/sonar-server/src/main/java/org/sonar/server/duplication/ws/ShowResponseBuilder.java
server/sonar-server/src/main/java/org/sonar/server/issue/IssueUpdater.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/AssignAction.java
server/sonar-server/src/main/java/org/sonar/server/issue/ws/ChangelogAction.java
server/sonar-server/src/main/java/org/sonar/server/measure/ws/ComponentAction.java
server/sonar-server/src/main/java/org/sonar/server/project/ws/IndexAction.java
server/sonar-server/src/main/java/org/sonar/server/project/ws/UpdateKeyAction.java
server/sonar-server/src/main/java/org/sonar/server/projectanalysis/ws/CreateEventAction.java
server/sonar-server/src/main/java/org/sonar/server/property/ws/IndexAction.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/DeselectAction.java
server/sonar-server/src/main/java/org/sonar/server/qualitygate/ws/SelectAction.java
server/sonar-server/src/main/java/org/sonar/server/qualityprofile/ws/SearchAction.java
server/sonar-server/src/main/java/org/sonar/server/user/ServerUserSession.java
server/sonar-server/src/main/java/org/sonar/server/user/ws/CurrentAction.java
server/sonar-server/src/main/java/org/sonar/server/webhook/ws/CreateAction.java
server/sonar-server/src/main/java/org/sonar/server/webhook/ws/DeleteAction.java
server/sonar-server/src/main/java/org/sonar/server/webhook/ws/ListAction.java
server/sonar-server/src/main/java/org/sonar/server/webhook/ws/UpdateAction.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceTest.java
server/sonar-server/src/test/java/org/sonar/server/component/ComponentServiceUpdateKeyTest.java
server/sonar-server/src/test/java/org/sonar/server/project/ws/UpdateKeyActionTest.java
server/sonar-server/src/test/java/org/sonar/server/source/ws/ShowActionTest.java

index c11b41c29208f97ac95f8971a4f771e0222b3beb..940c48eed66c1c09e7f0ff447b9b2d21909e3341 100644 (file)
@@ -95,7 +95,7 @@ public class CeQueueImpl implements CeQueue {
       ComponentDto component = null;
       String componentUuid = taskDto.getComponentUuid();
       if (componentUuid != null) {
-        component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orNull();
+        component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orElse(null);
       }
       CeTask task = convertToTask(taskDto, submission.getCharacteristics(), component);
       return java.util.Optional.of(task);
index 622922c9e56b192fb91623021b12b75775d97adc..8af513738c01cc331046a6f2f5d0f14580e2728b 100644 (file)
 package org.sonar.ce.task.projectanalysis.component;
 
 import java.util.Date;
+import java.util.Optional;
 import javax.annotation.Nullable;
 import org.sonar.api.utils.System2;
+import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
+import org.sonar.ce.task.projectanalysis.analysis.Branch;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.protobuf.DbProjectBranches;
-import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
-import org.sonar.ce.task.projectanalysis.analysis.Branch;
 
 import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
 import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
@@ -51,7 +52,7 @@ public class BranchPersisterImpl implements BranchPersister {
     Branch branch = analysisMetadataHolder.getBranch();
     String branchUuid = treeRootHolder.getRoot().getUuid();
 
-    com.google.common.base.Optional<ComponentDto> branchComponentDtoOpt = dbClient.componentDao().selectByUuid(dbSession, branchUuid);
+    Optional<ComponentDto> branchComponentDtoOpt = dbClient.componentDao().selectByUuid(dbSession, branchUuid);
 
     ComponentDto branchComponentDto;
     if (branch.isMain()) {
@@ -59,7 +60,7 @@ public class BranchPersisterImpl implements BranchPersister {
       branchComponentDto = branchComponentDtoOpt.get();
     } else {
       // inserts new row in table projects if it's the first time branch is analyzed
-      branchComponentDto = branchComponentDtoOpt.or(() -> insertIntoProjectsTable(dbSession, branchUuid));
+      branchComponentDto = branchComponentDtoOpt.orElseGet(() -> insertIntoProjectsTable(dbSession, branchUuid));
     }
 
     // insert or update in table project_branches
index de73734d68a660e9608bd42bdb30773a8f37eee0..9a0c3b1592ec071222d6da0431754df6927cea69 100644 (file)
@@ -216,7 +216,7 @@ public class LoadReportAnalysisMetadataHolderStep implements ComputationStep {
 
   private ComponentDto toProject(String projectKey) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      com.google.common.base.Optional<ComponentDto> opt = dbClient.componentDao().selectByKey(dbSession, projectKey);
+      Optional<ComponentDto> opt = dbClient.componentDao().selectByKey(dbSession, projectKey);
       checkState(opt.isPresent(), "Project with key '%s' can't be found", projectKey);
       return opt.get();
     }
index ce0b6ecc83b08b461500558496682c851366630b..62fa61f94ae3232b1e6f3973f86a4b5eec36fdf4 100644 (file)
 package org.sonar.ce.task.projectanalysis.step;
 
 import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import org.sonar.api.utils.MessageException;
 import org.sonar.ce.task.projectanalysis.analysis.AnalysisMetadataHolder;
 import org.sonar.ce.task.projectanalysis.batch.BatchReportReader;
@@ -119,7 +119,7 @@ public class ValidateProjectStep implements ComputationStep {
 
     private void validateAnalysisDate(Optional<ComponentDto> baseProject) {
       if (baseProject.isPresent()) {
-        java.util.Optional<SnapshotDto> snapshotDto = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, baseProject.get().uuid());
+        Optional<SnapshotDto> snapshotDto = dbClient.snapshotDao().selectLastAnalysisByRootComponentUuid(session, baseProject.get().uuid());
         long currentAnalysisDate = analysisMetadataHolder.getAnalysisDate();
         Long lastAnalysisDate = snapshotDto.map(SnapshotDto::getCreatedAt).orElse(null);
         if (lastAnalysisDate != null && currentAnalysisDate <= lastAnalysisDate) {
index b607a26399e1b51ca59e1ba28e726be492337cad..69b34878d28629295091ef39419b3c6986885647 100644 (file)
@@ -571,7 +571,7 @@ public class FileMoveDetectionStepTest {
   @CheckForNull
   private FileSourceDto insertContentOfFileInDb(String key, @Nullable String[] content) {
     return dbTester.getDbClient().componentDao().selectByKey(dbTester.getSession(), key)
-      .transform(file -> {
+      .map(file -> {
         SourceLineHashesComputer linesHashesComputer = new SourceLineHashesComputer();
         if (content != null) {
           stream(content).forEach(linesHashesComputer::addLine);
@@ -584,7 +584,7 @@ public class FileMoveDetectionStepTest {
         dbTester.getDbClient().fileSourceDao().insert(dbTester.getSession(), fileSourceDto);
         dbTester.commit();
         return fileSourceDto;
-      }).orNull();
+      }).orElse(null);
   }
 
   private void setFilesInReport(Component... files) {
index 2c284e10b9ee894b7f9cab982e492764fd2df44d..8d8ad129fea21c51c34de4e3190abc8307d19481 100644 (file)
@@ -19,9 +19,9 @@
  */
 package org.sonar.ce.task.projectanalysis.step;
 
-import com.google.common.base.Optional;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Optional;
 import java.util.function.Consumer;
 import java.util.stream.Stream;
 import javax.annotation.Nullable;
@@ -54,7 +54,6 @@ import org.sonar.server.project.Project;
 import static org.apache.commons.lang.StringUtils.isEmpty;
 import static org.apache.commons.lang.StringUtils.trimToNull;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.assertj.guava.api.Assertions.assertThat;
 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
index 7e3edc896fa307a458f6088e9b53be8c989ea571..61c801947bccaea085330569e3cf435186240311 100644 (file)
@@ -93,7 +93,7 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue
         ComponentDto component = null;
         String componentUuid = taskDto.getComponentUuid();
         if (componentUuid != null) {
-          component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orNull();
+          component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orElse(null);
         }
         Map<String, String> characteristics = dbClient.ceTaskCharacteristicsDao().selectByTaskUuids(dbSession, singletonList(taskDto.getUuid())).stream()
           .collect(uniqueIndex(CeTaskCharacteristicDto::getKey, CeTaskCharacteristicDto::getValue));
index 1e531a1e63a76af60a74ac965322e79607fdc3ca..413ddf5dfe084dd018c12ec215d6aaec5bdb160c 100644 (file)
  */
 package org.sonar.db.component;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
 import com.google.common.collect.Ordering;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Stream;
 import javax.annotation.CheckForNull;
@@ -86,11 +86,11 @@ public class ComponentDao implements Dao {
   }
 
   public Optional<ComponentDto> selectById(DbSession session, long id) {
-    return Optional.fromNullable(mapper(session).selectById(id));
+    return Optional.ofNullable(mapper(session).selectById(id));
   }
 
   public Optional<ComponentDto> selectByUuid(DbSession session, String uuid) {
-    return Optional.fromNullable(mapper(session).selectByUuid(uuid));
+    return Optional.ofNullable(mapper(session).selectByUuid(uuid));
   }
 
   public ComponentDto selectOrFailByUuid(DbSession session, String uuid) {
@@ -258,15 +258,15 @@ public class ComponentDao implements Dao {
   }
 
   public Optional<ComponentDto> selectByKey(DbSession session, String key) {
-    return Optional.fromNullable(mapper(session).selectByKey(key));
+    return Optional.ofNullable(mapper(session).selectByKey(key));
   }
 
-  public java.util.Optional<ComponentDto> selectByKeyAndBranch(DbSession session, String key, String branch) {
-    return java.util.Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, generateBranchKey(key, branch), branch));
+  public Optional<ComponentDto> selectByKeyAndBranch(DbSession session, String key, String branch) {
+    return Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, generateBranchKey(key, branch), branch));
   }
 
-  public java.util.Optional<ComponentDto> selectByKeyAndPullRequest(DbSession session, String key, String pullRequestId) {
-    return java.util.Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, generatePullRequestKey(key, pullRequestId), pullRequestId));
+  public Optional<ComponentDto> selectByKeyAndPullRequest(DbSession session, String key, String pullRequestId) {
+    return Optional.ofNullable(mapper(session).selectByKeyAndBranchKey(key, generatePullRequestKey(key, pullRequestId), pullRequestId));
   }
 
   public List<UuidWithProjectUuidDto> selectAllViewsAndSubViews(DbSession session) {
@@ -366,13 +366,15 @@ public class ComponentDao implements Dao {
   }
 
   public void insert(DbSession session, Collection<ComponentDto> items) {
-    for (ComponentDto item : items) {
-      insert(session, item);
-    }
+    insert(session, items.stream());
+  }
+
+  private void insert(DbSession session, Stream<ComponentDto> items) {
+    items.forEach(item -> insert(session, item));
   }
 
   public void insert(DbSession session, ComponentDto item, ComponentDto... others) {
-    insert(session, Lists.asList(item, others));
+    insert(session, Stream.concat(Stream.of(item), Arrays.stream(others)));
   }
 
   public void update(DbSession session, ComponentUpdateDto component) {
index 650c82a000097a941ca84de9e3a48dae2b861ddb..dcc384e544dcb207bcbc7ccf2ed4e57d1f36b4d7 100644 (file)
@@ -19,7 +19,6 @@
  */
 package org.sonar.db.component;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import com.tngtech.java.junit.dataprovider.DataProvider;
 import com.tngtech.java.junit.dataprovider.DataProviderRunner;
@@ -29,6 +28,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Random;
 import java.util.Set;
 import java.util.function.Consumer;
@@ -68,7 +68,6 @@ import static org.apache.commons.lang.RandomStringUtils.randomAlphabetic;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.entry;
 import static org.assertj.core.api.Assertions.tuple;
-import static org.assertj.guava.api.Assertions.assertThat;
 import static org.sonar.api.resources.Qualifiers.APP;
 import static org.sonar.api.resources.Qualifiers.PROJECT;
 import static org.sonar.api.utils.DateUtils.parseDate;
@@ -136,7 +135,7 @@ public class ComponentDaoTest {
     assertThat(result.getCopyResourceUuid()).isNull();
     assertThat(result.isPrivate()).isTrue();
 
-    assertThat(underTest.selectByUuid(dbSession, "UNKNOWN")).isAbsent();
+    assertThat(underTest.selectByUuid(dbSession, "UNKNOWN")).isEmpty();
   }
 
   @Test
@@ -211,7 +210,7 @@ public class ComponentDaoTest {
     assertThat(result.language()).isEqualTo("java");
     assertThat(result.projectUuid()).isEqualTo(project.uuid());
 
-    assertThat(underTest.selectByKey(dbSession, "unknown")).isAbsent();
+    assertThat(underTest.selectByKey(dbSession, "unknown")).isEmpty();
   }
 
   @Test
@@ -393,7 +392,7 @@ public class ComponentDaoTest {
     ComponentDto project = db.components().insertPrivateProject();
 
     assertThat(underTest.selectById(dbSession, project.getId())).isPresent();
-    assertThat(underTest.selectById(dbSession, 0L)).isAbsent();
+    assertThat(underTest.selectById(dbSession, 0L)).isEmpty();
   }
 
   @Test
@@ -1437,7 +1436,7 @@ public class ComponentDaoTest {
     underTest.delete(dbSession, project1.getId());
     dbSession.commit();
 
-    assertThat(underTest.selectByKey(dbSession, "PROJECT_1")).isAbsent();
+    assertThat(underTest.selectByKey(dbSession, "PROJECT_1")).isEmpty();
     assertThat(underTest.selectByKey(dbSession, "PROJECT_2")).isPresent();
   }
 
index 26c432656f6bb663687785b79113d44d03488555..2548804f267e9df1559b3cf6f23e9a035063e795 100644 (file)
@@ -66,11 +66,11 @@ public class WebHooksImpl implements WebHooks {
   private Stream<WebhookDto> readWebHooksFrom(String projectUuid) {
     try (DbSession dbSession = dbClient.openSession(false)) {
 
-      Optional<ComponentDto> optionalComponentDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orNull());
+      Optional<ComponentDto> optionalComponentDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null));
       ComponentDto componentDto = checkStateWithOptional(optionalComponentDto, "the requested project '%s' was not found", projectUuid);
 
       if (componentDto.getMainBranchProjectUuid() != null && !componentDto.uuid().equals(componentDto.getMainBranchProjectUuid())) {
-        Optional<ComponentDto> mainBranchComponentDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, componentDto.getMainBranchProjectUuid()).orNull());
+        Optional<ComponentDto> mainBranchComponentDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, componentDto.getMainBranchProjectUuid()).orElse(null));
         componentDto = checkStateWithOptional(mainBranchComponentDto, "the requested project '%s' was not found", projectUuid);
       }
 
index 604db1297e79df4e0850848d607260194a71ccee..694149444864cbed7dda9872d0a249d5d3c1db76 100644 (file)
  */
 package org.sonar.server.ce.queue;
 
-import com.google.common.base.Optional;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import javax.annotation.Nullable;
 import org.sonar.api.resources.Qualifiers;
 import org.sonar.api.resources.Scopes;
@@ -82,7 +82,7 @@ public class ReportSubmitter {
       Optional<ComponentDto> component = dbClient.componentDao().selectByKey(dbSession, effectiveProjectKey);
       validateProject(dbSession, component, projectKey);
       ensureOrganizationIsConsistent(component, organizationDto);
-      ComponentDto project = component.or(() -> createProject(dbSession, organizationDto, projectKey, deprecatedBranch, projectName));
+      ComponentDto project = component.orElseGet(() -> createProject(dbSession, organizationDto, projectKey, deprecatedBranch, projectName));
       checkScanPermission(project);
       return submitReport(dbSession, reportInput, project, characteristics);
     }
index 596eb6f47cef955b2d5172b7cc491467d09b67fc..21b86b86f1367faf51060ec51a8c5cee5e46f77f 100644 (file)
@@ -92,7 +92,7 @@ public class CancelAction implements CeWsAction {
     if (componentUuid == null) {
       throw insufficientPrivilegesException();
     }
-    com.google.common.base.Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
+    Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
     if (!component.isPresent()) {
       throw insufficientPrivilegesException();
     }
index 08267268aecb2cdd403cdf5c7ea0a920dfd15998..0d1305b62166d0c83b4f253fadca35760818a4dc 100644 (file)
@@ -95,12 +95,12 @@ public class TaskAction implements CeWsAction {
       Ce.TaskResponse.Builder wsTaskResponse = Ce.TaskResponse.newBuilder();
       Optional<CeQueueDto> queueDto = dbClient.ceQueueDao().selectByUuid(dbSession, taskUuid);
       if (queueDto.isPresent()) {
-        com.google.common.base.Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
+        Optional<ComponentDto> component = loadComponent(dbSession, queueDto.get().getComponentUuid());
         checkPermission(component);
         wsTaskResponse.setTask(wsTaskFormatter.formatQueue(dbSession, queueDto.get()));
       } else {
         CeActivityDto ceActivityDto = WsUtils.checkFoundWithOptional(dbClient.ceActivityDao().selectByUuid(dbSession, taskUuid), "No activity found for task '%s'", taskUuid);
-        com.google.common.base.Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
+        Optional<ComponentDto> component = loadComponent(dbSession, ceActivityDto.getComponentUuid());
         checkPermission(component);
         Set<AdditionalField> additionalFields = AdditionalField.getFromRequest(wsRequest);
         maskErrorStacktrace(ceActivityDto, additionalFields);
@@ -111,14 +111,14 @@ public class TaskAction implements CeWsAction {
     }
   }
 
-  private com.google.common.base.Optional<ComponentDto> loadComponent(DbSession dbSession, @Nullable String projectUuid) {
+  private Optional<ComponentDto> loadComponent(DbSession dbSession, @Nullable String projectUuid) {
     if (projectUuid == null) {
-      return com.google.common.base.Optional.absent();
+      return Optional.empty();
     }
     return dbClient.componentDao().selectByUuid(dbSession, projectUuid);
   }
 
-  private void checkPermission(com.google.common.base.Optional<ComponentDto> component) {
+  private void checkPermission(Optional<ComponentDto> component) {
     if (component.isPresent()) {
       String orgUuid = component.get().getOrganizationUuid();
       if (!userSession.hasPermission(OrganizationPermission.ADMINISTER, orgUuid) &&
index 333f6ad0ab0d35a0dfb33efd10962af66f4f4525..54f408731a1afe0fd818892e41d4c81255ee9f12 100644 (file)
@@ -19,8 +19,8 @@
  */
 package org.sonar.server.component;
 
-import com.google.common.base.Optional;
 import java.util.Collection;
+import java.util.Optional;
 import java.util.Set;
 import javax.annotation.Nullable;
 import org.sonar.api.resources.Qualifiers;
@@ -129,7 +129,7 @@ public class ComponentFinder {
 
   public OrganizationDto getOrganization(DbSession dbSession, ComponentDto component) {
     String organizationUuid = component.getOrganizationUuid();
-    java.util.Optional<OrganizationDto> organizationDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid);
+    Optional<OrganizationDto> organizationDto = dbClient.organizationDao().selectByUuid(dbSession, organizationUuid);
     return checkFoundWithOptional(organizationDto, "Organization with uuid '%s' not found", organizationUuid);
   }
 
@@ -137,7 +137,7 @@ public class ComponentFinder {
    * Components of the main branch won't be found
    */
   public ComponentDto getByKeyAndBranch(DbSession dbSession, String key, String branch) {
-    java.util.Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndBranch(dbSession, key, branch);
+    Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndBranch(dbSession, key, branch);
     if (componentDto.isPresent() && componentDto.get().isEnabled()) {
       return componentDto.get();
     }
@@ -145,7 +145,7 @@ public class ComponentFinder {
   }
 
   public ComponentDto getByKeyAndPullRequest(DbSession dbSession, String key, String pullRequest) {
-    java.util.Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndPullRequest(dbSession, key, pullRequest);
+    Optional<ComponentDto> componentDto = dbClient.componentDao().selectByKeyAndPullRequest(dbSession, key, pullRequest);
     if (componentDto.isPresent() && componentDto.get().isEnabled()) {
       return componentDto.get();
     }
index 1b9fb9908fe24830cee0da2319424ee543551a6b..e56b873797e72a9d44e063f6c04d8d847cc0cec2 100644 (file)
 package org.sonar.server.duplication.ws;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
 import java.io.Serializable;
 import java.io.StringReader;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
 import javax.xml.stream.XMLInputFactory;
@@ -90,9 +90,9 @@ public class DuplicationsParser {
     if (component == null) {
       Optional<ComponentDto> componentDtoOptional;
       if (branch != null) {
-        componentDtoOptional = Optional.fromNullable(componentDao.selectByKeyAndBranch(session, componentKey, branch).orElseGet(null));
+        componentDtoOptional = Optional.ofNullable(componentDao.selectByKeyAndBranch(session, componentKey, branch).orElseGet(null));
       } else if (pullRequest != null) {
-        componentDtoOptional = Optional.fromNullable(componentDao.selectByKeyAndPullRequest(session, componentKey, pullRequest).orElseGet(null));
+        componentDtoOptional = Optional.ofNullable(componentDao.selectByKeyAndPullRequest(session, componentKey, pullRequest).orElseGet(null));
       } else {
         componentDtoOptional = componentDao.selectByKey(session, componentKey);
       }
index f6050bc65272eee625be857e490083e6b7910667..7f792ca70d770be59ce5ffad8fad8d8b9c461f99 100644 (file)
@@ -20,9 +20,9 @@
 package org.sonar.server.duplication.ws;
 
 import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Optional;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import javax.annotation.Nullable;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
index 9f96db62e23d17f65a771313c8a5b2cdcd285f22..d7e0ca2e95b7678929b09954bd00bc3762f628e4 100644 (file)
@@ -50,7 +50,7 @@ public class IssueUpdater {
   private final IssueChangePostProcessor issueChangePostProcessor;
 
   public IssueUpdater(DbClient dbClient, WebIssueStorage issueStorage, NotificationManager notificationService,
-                      IssueChangePostProcessor issueChangePostProcessor) {
+    IssueChangePostProcessor issueChangePostProcessor) {
     this.dbClient = dbClient;
     this.issueStorage = issueStorage;
     this.notificationService = notificationService;
@@ -112,7 +112,7 @@ public class IssueUpdater {
   private ComponentDto getComponent(DbSession dbSession, DefaultIssue issue, @Nullable String componentUuid) {
     String issueKey = issue.key();
     checkState(componentUuid != null, "Issue '%s' has no component", issueKey);
-    ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orNull();
+    ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, componentUuid).orElse(null);
     checkState(component != null, "Component uuid '%s' for issue key '%s' cannot be found", componentUuid, issueKey);
     return component;
   }
index a44ea87e12ace451ef5f63b58adc56dd99f107e3..4dca280fecd955637154f0b5d6e1c1c42462ab0e 100644 (file)
@@ -148,7 +148,7 @@ public class AssignAction implements IssuesWsAction {
 
   private void checkMembership(DbSession dbSession, IssueDto issueDto, UserDto user) {
     String projectUuid = requireNonNull(issueDto.getProjectUuid());
-    ComponentDto project = Optional.ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orNull())
+    ComponentDto project = Optional.ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null))
       .orElseThrow(() -> new IllegalStateException(format("Unknown project %s", projectUuid)));
     OrganizationDto organizationDto = dbClient.organizationDao().selectByUuid(dbSession, project.getOrganizationUuid())
       .orElseThrow(() -> new IllegalStateException(format("Unknown organizationMember %s", project.getOrganizationUuid())));
index 655bed2a98d5df702b3a2ad64d889cd1fbaefe17..15098897b0c1265e62589f5df3562a5a130abb30 100644 (file)
  */
 package org.sonar.server.issue.ws;
 
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.io.Resources;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import java.util.function.Consumer;
 import java.util.function.Function;
@@ -177,7 +177,7 @@ public class ChangelogAction implements IssuesWsAction {
     private boolean isMember(DbSession dbSession, IssueDto issue) {
       Optional<ComponentDto> project = dbClient.componentDao().selectByUuid(dbSession, issue.getProjectUuid());
       checkState(project.isPresent(), "Cannot find the project with uuid %s from issue.id %s", issue.getProjectUuid(), issue.getId());
-      java.util.Optional<OrganizationDto> organization = dbClient.organizationDao().selectByUuid(dbSession, project.get().getOrganizationUuid());
+      Optional<OrganizationDto> organization = dbClient.organizationDao().selectByUuid(dbSession, project.get().getOrganizationUuid());
       checkState(organization.isPresent(), "Cannot find the organization with uuid %s from issue.id %s", project.get().getOrganizationUuid(), issue.getId());
       return userSession.hasMembership(organization.get());
     }
index f6257345fadea69e6763e6f56ff610ccab58f50f..7ca9a245334f08f448524ce8b2775387a25d6e9b 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.server.measure.ws;
 
 import com.google.common.base.Joiner;
-import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableSortedSet;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
@@ -29,6 +28,7 @@ import java.util.HashMap;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nullable;
@@ -176,7 +176,7 @@ public class ComponentAction implements MeasuresWsAction {
 
   private Optional<ComponentDto> getReferenceComponent(DbSession dbSession, ComponentDto component) {
     if (component.getCopyResourceUuid() == null) {
-      return Optional.absent();
+      return Optional.empty();
     }
 
     return dbClient.componentDao().selectByUuid(dbSession, component.getCopyResourceUuid());
index e936fd5b6e01f5c2d07d786c18159085379d20e2..e42019715cd1228137e4ce2628c8f400e9d81956 100644 (file)
@@ -125,9 +125,9 @@ public class IndexAction implements ProjectsWsAction {
   private Optional<ComponentDto> getProjectByKeyOrId(DbSession dbSession, String component) {
     try {
       Long componentId = Long.parseLong(component);
-      return ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orNull());
+      return ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orElse(null));
     } catch (NumberFormatException e) {
-      return ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orNull());
+      return ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orElse(null));
     }
   }
 
index 16bd63ab8376f5797be5cf558e90551d0d12b8a4..6e78a7f5dc57cd4879e0a08fef47b376be33d688 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.project.ws;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
 import org.sonar.api.server.ws.Change;
 import org.sonar.api.server.ws.Request;
 import org.sonar.api.server.ws.Response;
index 3f2046c8ffffdae55b91d3b1d323dbcc1b40fdbd..d9affb813bd381fe2c8cebbe52ec3a20a4c5d97c 100644 (file)
@@ -140,7 +140,7 @@ public class CreateEventAction implements ProjectAnalysesWsAction {
   }
 
   private ComponentDto getProjectOrApplication(DbSession dbSession, SnapshotDto analysis) {
-    ComponentDto project = dbClient.componentDao().selectByUuid(dbSession, analysis.getComponentUuid()).orNull();
+    ComponentDto project = dbClient.componentDao().selectByUuid(dbSession, analysis.getComponentUuid()).orElse(null);
     checkState(project != null, "Project of analysis '%s' is not found", analysis.getUuid());
     checkArgument(ALLOWED_QUALIFIERS.contains(project.qualifier()) && Scopes.PROJECT.equals(project.scope()),
       "An event must be created on a project or an application");
index e741ed28bf6f9f0a1dca49a0dd495c8e99e630fa..7af3bd74d13e88504d80153a063c5076e6c16aaf 100644 (file)
@@ -121,9 +121,9 @@ public class IndexAction implements WsAction {
   private Optional<ComponentDto> loadComponent(DbSession dbSession, String component) {
     try {
       Long componentId = Long.parseLong(component);
-      return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orNull());
+      return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, componentId).orElse(null));
     } catch (NumberFormatException e) {
-      return Optional.ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orNull());
+      return Optional.ofNullable(dbClient.componentDao().selectByKey(dbSession, component).orElse(null));
     }
   }
 
index 3240159cff73093e9092665bf3a6ec5ccd58f3c4..44247cf4140aaa6418a193ede8458c4cc9e8beb1 100644 (file)
@@ -106,7 +106,7 @@ public class DeselectAction implements QualityGatesWsAction {
 
     try {
       long dbId = Long.parseLong(projectId);
-      return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orNull());
+      return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orElse(null));
     } catch (NumberFormatException e) {
       return Optional.empty();
     }
index 94606de76d6e097b0c803fd17a6c005c5d7e9cff..fae72d0ad4513f20cbaa37495fce8460a3a8cdef 100644 (file)
@@ -118,7 +118,7 @@ public class SelectAction implements QualityGatesWsAction {
 
     try {
       long dbId = Long.parseLong(projectId);
-      return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orNull());
+      return Optional.ofNullable(dbClient.componentDao().selectById(dbSession, dbId).orElse(null));
     } catch (NumberFormatException e) {
       return Optional.empty();
     }
index 0a6ce961f5f75f8540448f44a46d675343cf2ded..6714fb217e5d57d5be7f5b00465410958e83c890 100644 (file)
@@ -185,7 +185,7 @@ public class SearchAction implements QProfileWsAction {
     if (project.isRoot()) {
       return project;
     }
-    ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, project.projectUuid()).orNull();
+    ComponentDto component = dbClient.componentDao().selectByUuid(dbSession, project.projectUuid()).orElse(null);
     checkState(component != null, "Project uuid of component uuid '%s' does not exist", project.uuid());
     return component;
   }
index 9ab2cb3c9544b8e82fd3858d8e97b0de0eae7018..693d4fe353cf9d4e35437d1075f4beb7c15fafd6 100644 (file)
@@ -167,7 +167,7 @@ public class ServerUserSession extends AbstractUserSession {
       return of(projectUuid);
     }
     try (DbSession dbSession = dbClient.openSession(false)) {
-      com.google.common.base.Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
+      Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, componentUuid);
       if (!component.isPresent()) {
         return Optional.empty();
       }
@@ -190,7 +190,7 @@ public class ServerUserSession extends AbstractUserSession {
 
   private Set<String> loadProjectPermissions(String projectUuid) {
     try (DbSession dbSession = dbClient.openSession(false)) {
-      com.google.common.base.Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, projectUuid);
+      Optional<ComponentDto> component = dbClient.componentDao().selectByUuid(dbSession, projectUuid);
       if (!component.isPresent()) {
         return Collections.emptySet();
       }
index d6bc1c92651375504c5cc036e7c213ee457c814e..796195825f8ac11ad3c24c6e11098a5c8d14c4c7 100644 (file)
@@ -164,7 +164,7 @@ public class CurrentAction implements UsersWsAction {
   }
 
   private Optional<CurrentWsResponse.Homepage> projectHomepage(DbSession dbSession, UserDto user) {
-    Optional<ComponentDto> projectOptional = ofNullable(dbClient.componentDao().selectByUuid(dbSession, of(user.getHomepageParameter()).orElse(EMPTY)).orNull());
+    Optional<ComponentDto> projectOptional = ofNullable(dbClient.componentDao().selectByUuid(dbSession, of(user.getHomepageParameter()).orElse(EMPTY)).orElse(null));
     if (shouldCleanProjectHomepage(projectOptional)) {
       cleanUserHomepageInDb(dbSession, user);
       return empty();
@@ -182,7 +182,7 @@ public class CurrentAction implements UsersWsAction {
   }
 
   private Optional<CurrentWsResponse.Homepage> applicationAndPortfolioHomepage(DbSession dbSession, UserDto user) {
-    Optional<ComponentDto> componentOptional = ofNullable(dbClient.componentDao().selectByUuid(dbSession, of(user.getHomepageParameter()).orElse(EMPTY)).orNull());
+    Optional<ComponentDto> componentOptional = ofNullable(dbClient.componentDao().selectByUuid(dbSession, of(user.getHomepageParameter()).orElse(EMPTY)).orElse(null));
     if (shouldCleanApplicationOrPortfolioHomepage(componentOptional)) {
       cleanUserHomepageInDb(dbSession, user);
       return empty();
index dc584ac28cc18ea501b823f6d1d70d2ed34bfa54..03028383907106dd0bc4c7f17640a3d4443636e1 100644 (file)
@@ -138,7 +138,7 @@ public class CreateAction implements WebhooksWsAction {
 
       ComponentDto projectDto = null;
       if (isNotBlank(projectKey)) {
-        Optional<ComponentDto> dtoOptional = ofNullable(dbClient.componentDao().selectByKey(dbSession, projectKey).orNull());
+        Optional<ComponentDto> dtoOptional = ofNullable(dbClient.componentDao().selectByKey(dbSession, projectKey).orElse(null));
         ComponentDto componentDto = checkFoundWithOptional(dtoOptional, "No project with key '%s'", projectKey);
         webhookSupport.checkThatProjectBelongsToOrganization(componentDto, organizationDto, "Project '%s' does not belong to organisation '%s'", projectKey, organizationKey);
         webhookSupport.checkPermission(componentDto);
index 988f43eb65779f2ee19bf07cf52320c33698ed3b..235c3e8a1b89a0dae802084bca85142c2c3583cf 100644 (file)
@@ -91,7 +91,7 @@ public class DeleteAction implements WebhooksWsAction {
 
       String projectUuid = webhookDto.getProjectUuid();
       if (projectUuid != null) {
-        Optional<ComponentDto> optionalDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orNull());
+        Optional<ComponentDto> optionalDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null));
         ComponentDto componentDto = checkStateWithOptional(optionalDto, "the requested project '%s' was not found", projectUuid);
         webhookSupport.checkPermission(componentDto);
         deleteWebhook(dbSession, webhookDto);
index cc8f70ab27cbf14e2a672ab0db08553b46de4abf..42d2542f952446204981de4863cd64e5db338512 100644 (file)
@@ -119,7 +119,7 @@ public class ListAction implements WebhooksWsAction {
 
     if (isNotBlank(projectKey)) {
 
-      Optional<ComponentDto> optional = ofNullable(dbClient.componentDao().selectByKey(dbSession, projectKey).orNull());
+      Optional<ComponentDto> optional = ofNullable(dbClient.componentDao().selectByKey(dbSession, projectKey).orElse(null));
       ComponentDto componentDto = checkFoundWithOptional(optional, "project %s does not exist", projectKey);
       webhookSupport.checkPermission(componentDto);
       webhookSupport.checkThatProjectBelongsToOrganization(componentDto, organizationDto, "Project '%s' does not belong to organisation '%s'", projectKey, organizationKey);
index 79e552d4561bd64b73c24d8717e41138c5044170..c74a1f8f4f30eca634eab698ab38b6d6768f0e0c 100644 (file)
@@ -113,7 +113,7 @@ public class UpdateAction implements WebhooksWsAction {
 
       String projectUuid = webhookDto.getProjectUuid();
       if (projectUuid != null) {
-        Optional<ComponentDto> optionalDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orNull());
+        Optional<ComponentDto> optionalDto = ofNullable(dbClient.componentDao().selectByUuid(dbSession, projectUuid).orElse(null));
         ComponentDto componentDto = checkStateWithOptional(optionalDto, "the requested project '%s' was not found", projectUuid);
         webhookSupport.checkPermission(componentDto);
         updateWebhook(dbSession, webhookDto, name, url);
index 420f1c049d436776a19c20f289e85bd88922c0f9..01cf4144d73914a054233e489e0ab8f000d6c3bb 100644 (file)
@@ -33,7 +33,7 @@ import org.sonar.server.es.TestProjectIndexers;
 import org.sonar.server.project.ProjectLifeCycleListeners;
 import org.sonar.server.tester.UserSessionRule;
 
-import static org.assertj.guava.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newModuleDto;
@@ -73,12 +73,8 @@ public class ComponentServiceTest {
   }
 
   private void assertComponentKeyUpdated(String oldKey, String newKey) {
-    assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isAbsent();
+    assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isEmpty();
     assertThat(dbClient.componentDao().selectByKey(dbSession, newKey)).isPresent();
   }
 
-  private void assertComponentKeyNotUpdated(String key) {
-    assertThat(dbClient.componentDao().selectByKey(dbSession, key)).isPresent();
-  }
-
 }
index 08443427b215664437ad5b522fce26f06489e0e0..a9f3a20494d9dce6c079f24a1613f847b503251b 100644 (file)
@@ -41,7 +41,7 @@ import org.sonar.server.project.RekeyedProject;
 import org.sonar.server.tester.UserSessionRule;
 
 import static java.util.Collections.emptyList;
-import static org.assertj.guava.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
@@ -78,17 +78,17 @@ public class ComponentServiceUpdateKeyTest {
     dbSession.commit();
 
     // Check project key has been updated
-    assertThat(db.getDbClient().componentDao().selectByKey(dbSession, project.getDbKey())).isAbsent();
+    assertThat(db.getDbClient().componentDao().selectByKey(dbSession, project.getDbKey())).isEmpty();
     assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root")).isNotNull();
 
     // Check file key has been updated
-    assertThat(db.getDbClient().componentDao().selectByKey(dbSession, file.getDbKey())).isAbsent();
+    assertThat(db.getDbClient().componentDao().selectByKey(dbSession, file.getDbKey())).isEmpty();
     assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root:src/File.xoo")).isNotNull();
     assertThat(db.getDbClient().componentDao().selectByKey(dbSession, "sample2:root:src/InactiveFile.xoo")).isNotNull();
 
-    assertThat(dbClient.componentDao().selectByKey(dbSession, inactiveFile.getDbKey())).isAbsent();
+    assertThat(dbClient.componentDao().selectByKey(dbSession, inactiveFile.getDbKey())).isEmpty();
 
-    org.assertj.core.api.Assertions.assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
+    assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
   }
 
   @Test
@@ -108,7 +108,7 @@ public class ComponentServiceUpdateKeyTest {
     assertComponentKeyHasBeenUpdated(file.getDbKey(), "sample:root2:module:src/File.xoo");
 
     // do not index the module but the project
-    org.assertj.core.api.Assertions.assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
+    assertThat(projectIndexers.hasBeenCalled(project.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
   }
 
   @Test
@@ -122,7 +122,7 @@ public class ComponentServiceUpdateKeyTest {
     dbSession.commit();
 
     assertComponentKeyHasBeenUpdated(provisionedProject.getDbKey(), "provisionedProject2");
-    org.assertj.core.api.Assertions.assertThat(projectIndexers.hasBeenCalled(provisionedProject.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
+    assertThat(projectIndexers.hasBeenCalled(provisionedProject.uuid(), ProjectIndexer.Cause.PROJECT_KEY_UPDATE)).isTrue();
   }
 
   @Test
@@ -219,7 +219,7 @@ public class ComponentServiceUpdateKeyTest {
   }
 
   private void assertComponentKeyUpdated(String oldKey, String newKey) {
-    assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isAbsent();
+    assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isEmpty();
     assertThat(dbClient.componentDao().selectByKey(dbSession, newKey)).isPresent();
   }
 
@@ -233,7 +233,7 @@ public class ComponentServiceUpdateKeyTest {
   }
 
   private void assertComponentKeyHasBeenUpdated(String oldKey, String newKey) {
-    assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isAbsent();
+    assertThat(dbClient.componentDao().selectByKey(dbSession, oldKey)).isEmpty();
     assertThat(dbClient.componentDao().selectByKey(dbSession, newKey)).isPresent();
   }
 
index f397bba193e93cb908b8f0298a875a68952f386b..a99209ae8e7002deaa5045e97f9271bb04460691 100644 (file)
@@ -19,7 +19,7 @@
  */
 package org.sonar.server.project.ws;
 
-import com.google.common.base.Optional;
+import java.util.Optional;
 import javax.annotation.Nullable;
 import org.junit.Rule;
 import org.junit.Test;
index fee0c08eed8023c7bf03d4f99778e4a2c4e90b48..27037f1e4eadabcf63d30050d46b4588091cdd2c 100644 (file)
@@ -82,7 +82,7 @@ public class ShowActionTest {
   public void show_source() throws Exception {
     String fileKey = "src/Foo.java";
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
-    when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
+    when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
     when(sourceService.getLinesAsHtml(eq(session), eq(file.uuid()), anyInt(), anyInt())).thenReturn(Optional.of(newArrayList(
       "/*",
       " * Header",
@@ -99,7 +99,7 @@ public class ShowActionTest {
   public void show_source_with_from_and_to_params() throws Exception {
     String fileKey = "src/Foo.java";
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
-    when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
+    when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
     when(sourceService.getLinesAsHtml(session, file.uuid(), 3, 5)).thenReturn(Optional.of(newArrayList(
       " */",
       "",
@@ -116,7 +116,7 @@ public class ShowActionTest {
   public void show_source_accept_from_less_than_one() throws Exception {
     String fileKey = "src/Foo.java";
     userSessionRule.addProjectPermission(UserRole.CODEVIEWER, project);
-    when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
+    when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
     when(sourceService.getLinesAsHtml(session, file.uuid(), 1, 5)).thenReturn(Optional.of(newArrayList(
       " */",
       "",
@@ -133,7 +133,7 @@ public class ShowActionTest {
   @Test(expected = ForbiddenException.class)
   public void require_code_viewer() throws Exception {
     String fileKey = "src/Foo.java";
-    when(componentDao.selectByKey(session, fileKey)).thenReturn(com.google.common.base.Optional.of(file));
+    when(componentDao.selectByKey(session, fileKey)).thenReturn(Optional.of(file));
     tester.newGetRequest("api/sources", "show").setParam("key", fileKey).execute();
   }
 }