From ca8d160e00e48c957e7fda1268089bee411a0187 Mon Sep 17 00:00:00 2001 From: Pierre Guillot <50145663+pierre-guillot-sonarsource@users.noreply.github.com> Date: Wed, 25 Nov 2020 16:03:57 +0100 Subject: [PATCH] remove code smells --- .../java/org/sonar/auth/gitlab/GitLabSettings.java | 3 ++- .../src/main/java/org/sonar/auth/gitlab/GsonGroup.java | 10 ++++++---- .../test/java/org/sonar/ce/queue/CeQueueImplTest.java | 8 ++++---- .../test/java/org/sonar/db/alm/pat/AlmPatDaoTest.java | 6 +++--- .../version/v84/common/AddUuidColumnToTable.java | 3 ++- .../db/migration/version/v84/common/DropIdColumn.java | 2 +- .../version/v84/common/DropPrimaryKeyOnIdColumn.java | 2 +- .../version/v84/common/MakeUuidColumnNotNullable.java | 2 +- 8 files changed, 20 insertions(+), 16 deletions(-) diff --git a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java index 860d7e89fae..62d8310cff4 100644 --- a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java +++ b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GitLabSettings.java @@ -120,7 +120,8 @@ public class GitLabSettings { PropertyDefinition.builder(GITLAB_AUTH_SYNC_USER_GROUPS) .deprecatedKey("sonar.auth.gitlab.sync_user_groups") .name("Synchronize user groups") - .description("For each GitLab group he belongs to, the user will be associated to a group with the same name (if it exists) in SonarQube. If enabled, the GitLab Oauth2 application will need to provide the api scope") + .description("For each GitLab group he belongs to, the user will be associated to a group with the same name (if it exists) in SonarQube." + + " If enabled, the GitLab Oauth2 application will need to provide the api scope") .category(CATEGORY) .subCategory(SUBCATEGORY) .type(PropertyType.BOOLEAN) diff --git a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GsonGroup.java b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GsonGroup.java index a89743075fc..b5b70c5a13e 100644 --- a/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GsonGroup.java +++ b/server/sonar-auth-gitlab/src/main/java/org/sonar/auth/gitlab/GsonGroup.java @@ -20,6 +20,7 @@ package org.sonar.auth.gitlab; import com.google.gson.Gson; +import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; import java.lang.reflect.Type; import java.util.Collection; @@ -30,19 +31,20 @@ import java.util.List; */ public class GsonGroup { - private String full_path; + @SerializedName("full_path") + private String fullPath; public GsonGroup() { // http://stackoverflow.com/a/18645370/229031 this(""); } - GsonGroup(String full_path) { - this.full_path = full_path; + GsonGroup(String fullPath) { + this.fullPath = fullPath; } String getFullPath() { - return full_path; + return fullPath; } static List parse(String json) { diff --git a/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java b/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java index 1bc242c5702..b2bdccb22a1 100644 --- a/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java +++ b/server/sonar-ce-common/src/test/java/org/sonar/ce/queue/CeQueueImplTest.java @@ -389,7 +389,7 @@ public class CeQueueImplTest { underTest.cancel(db.getSession(), queueDto); Optional activity = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid()); - assertThat(activity.isPresent()).isTrue(); + assertThat(activity).isPresent(); assertThat(activity.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED); } @@ -420,7 +420,7 @@ public class CeQueueImplTest { Optional ceActivityPending1 = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), pendingTask2.getUuid()); assertThat(ceActivityPending1.get().getStatus()).isEqualTo(CeActivityDto.Status.CANCELED); Optional ceActivityPending2 = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), inProgressTask.getUuid()); - assertThat(ceActivityPending2.isPresent()).isFalse(); + assertThat(ceActivityPending2).isNotPresent(); } @Test @@ -485,7 +485,7 @@ public class CeQueueImplTest { underTest.fail(db.getSession(), queueDto, "TIMEOUT", "Failed on timeout"); Optional activity = db.getDbClient().ceActivityDao().selectByUuid(db.getSession(), task.getUuid()); - assertThat(activity.isPresent()).isTrue(); + assertThat(activity).isPresent(); assertThat(activity.get().getStatus()).isEqualTo(CeActivityDto.Status.FAILED); assertThat(activity.get().getErrorType()).isEqualTo("TIMEOUT"); assertThat(activity.get().getErrorMessage()).isEqualTo("Failed on timeout"); @@ -550,7 +550,7 @@ public class CeQueueImplTest { private void verifyCeQueueDtoForTaskSubmit(CeTaskSubmit taskSubmit) { Optional queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), taskSubmit.getUuid()); - assertThat(queueDto.isPresent()).isTrue(); + assertThat(queueDto).isPresent(); assertThat(queueDto.get().getTaskType()).isEqualTo(taskSubmit.getType()); Optional component = taskSubmit.getComponent(); if (component.isPresent()) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoTest.java index a215bcaa73f..81bfbcab31a 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/alm/pat/AlmPatDaoTest.java @@ -121,7 +121,7 @@ public class AlmPatDaoTest { underTest.delete(dbSession, almPat); - assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse(); + assertThat(underTest.selectByUuid(dbSession, almPat.getUuid())).isNotPresent(); } @Test @@ -134,7 +134,7 @@ public class AlmPatDaoTest { underTest.deleteByUser(dbSession, userDto); - assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse(); + assertThat(underTest.selectByUuid(dbSession, almPat.getUuid())).isNotPresent(); } @Test @@ -147,7 +147,7 @@ public class AlmPatDaoTest { underTest.deleteByAlmSetting(dbSession, almSettingDto); - assertThat(underTest.selectByUuid(dbSession, almPat.getUuid()).isPresent()).isFalse(); + assertThat(underTest.selectByUuid(dbSession, almPat.getUuid())).isNotPresent(); } } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/AddUuidColumnToTable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/AddUuidColumnToTable.java index 534ce422958..de9f2e2b72f 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/AddUuidColumnToTable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/AddUuidColumnToTable.java @@ -28,6 +28,7 @@ import org.sonar.server.platform.db.migration.step.DdlChange; import static org.sonar.server.platform.db.migration.def.VarcharColumnDef.newVarcharColumnDefBuilder; public abstract class AddUuidColumnToTable extends DdlChange { + private static final VarcharColumnDef uuidColumnDefinition = newVarcharColumnDefBuilder() .setColumnName("uuid") .setIsNullable(true) @@ -36,7 +37,7 @@ public abstract class AddUuidColumnToTable extends DdlChange { .build(); private String tableName; - public AddUuidColumnToTable(Database db, String tableName) { + protected AddUuidColumnToTable(Database db, String tableName) { super(db); this.tableName = tableName; } diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/DropIdColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/DropIdColumn.java index af5360a3964..e32f600b43a 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/DropIdColumn.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/DropIdColumn.java @@ -28,7 +28,7 @@ public abstract class DropIdColumn extends DdlChange { private Database db; private String tableName; - public DropIdColumn(Database db, String tableName) { + protected DropIdColumn(Database db, String tableName) { super(db); this.db = db; this.tableName = tableName; diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/DropPrimaryKeyOnIdColumn.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/DropPrimaryKeyOnIdColumn.java index d2446360995..ccb17dba7dc 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/DropPrimaryKeyOnIdColumn.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/DropPrimaryKeyOnIdColumn.java @@ -28,7 +28,7 @@ public abstract class DropPrimaryKeyOnIdColumn extends DdlChange { private final DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator; private String tableName; - public DropPrimaryKeyOnIdColumn(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator, String tableName) { + protected DropPrimaryKeyOnIdColumn(Database db, DropPrimaryKeySqlGenerator dropPrimaryKeySqlGenerator, String tableName) { super(db); this.dropPrimaryKeySqlGenerator = dropPrimaryKeySqlGenerator; this.tableName = tableName; diff --git a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/MakeUuidColumnNotNullable.java b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/MakeUuidColumnNotNullable.java index fd89f1c0ad8..f4e8e3e90ed 100644 --- a/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/MakeUuidColumnNotNullable.java +++ b/server/sonar-db-migration/src/main/java/org/sonar/server/platform/db/migration/version/v84/common/MakeUuidColumnNotNullable.java @@ -37,7 +37,7 @@ public abstract class MakeUuidColumnNotNullable extends DdlChange { private String tableName; - public MakeUuidColumnNotNullable(Database db, String tableName) { + protected MakeUuidColumnNotNullable(Database db, String tableName) { super(db); this.tableName = tableName; } -- 2.39.5