diff options
author | Duarte Meneses <duarte.meneses@sonarsource.com> | 2019-12-09 09:34:43 -0600 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-12-10 20:46:09 +0100 |
commit | d1fd889554bccbb50122550899dbb66b90b04f78 (patch) | |
tree | 9cad838366292ee79b77ac3513403f7489b06355 /server/sonar-server-common | |
parent | f86a1094588e4e47b3abf612891af0431653cd0e (diff) | |
download | sonarqube-d1fd889554bccbb50122550899dbb66b90b04f78.tar.gz sonarqube-d1fd889554bccbb50122550899dbb66b90b04f78.zip |
Fix code quality issues and reduce dependency on Guava
Diffstat (limited to 'server/sonar-server-common')
28 files changed, 54 insertions, 68 deletions
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinition.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinition.java index 09005233a0e..1a8b92e2976 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinition.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinition.java @@ -19,7 +19,7 @@ */ package org.sonar.server.es; -import com.google.common.collect.Maps; +import java.util.HashMap; import java.util.Map; import org.sonar.api.server.ServerSide; import org.sonar.server.es.newindex.NewAuthorizedIndex; @@ -33,7 +33,7 @@ import static com.google.common.base.Preconditions.checkArgument; public interface IndexDefinition { class IndexDefinitionContext { - private final Map<String, NewIndex> byKey = Maps.newHashMap(); + private final Map<String, NewIndex> byKey = new HashMap<>(); public NewRegularIndex create(Index index, SettingsConfiguration settingsConfiguration) { String indexName = index.getName(); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java index 2465e70cbd2..29ab3d874a8 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java @@ -49,15 +49,15 @@ class IndexDefinitionHash { index.getAttributes()); } - private static String of(String str, Map<?,?>... maps) { + private static String of(String str, Map<?, ?>... maps) { StringBuilder sb = new StringBuilder(str); - for (Map<?,?> map : maps) { + for (Map<?, ?> map : maps) { appendMap(sb, map); } return DigestUtils.sha256Hex(sb.toString()); } - private static void appendMap(StringBuilder sb, Map<?,?> attributes) { + private static void appendMap(StringBuilder sb, Map<?, ?> attributes) { for (Object entry : sort(attributes).entrySet()) { sb.append(((Map.Entry) entry).getKey()); sb.append(DELIMITER); @@ -74,13 +74,13 @@ class IndexDefinitionHash { } else if (value instanceof IndexType) { sb.append(((IndexType) value).format()); } else { - sb.append(String.valueOf(value)); + sb.append(value); } } - private static SortedMap<?,?> sort(Map<?,?> map) { + private static SortedMap<?, ?> sort(Map<?, ?> map) { if (map instanceof ImmutableSortedMap) { - return (ImmutableSortedMap<?,?>) map; + return (ImmutableSortedMap<?, ?>) map; } return ImmutableSortedMap.copyOf(map); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java index ee54f4a6d9f..1b410e8c77f 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/index/IssueIteratorForSingleChunk.java @@ -22,11 +22,11 @@ package org.sonar.server.issue.index; import com.google.common.base.CharMatcher; import com.google.common.base.Splitter; import com.google.common.collect.Iterators; -import com.google.common.collect.Maps; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; import java.util.stream.IntStream; @@ -190,7 +190,7 @@ class IssueIteratorForSingleChunk implements IssueIterator { @Override protected IssueDoc read(ResultSet rs) throws SQLException { - IssueDoc doc = new IssueDoc(Maps.newHashMapWithExpectedSize(30)); + IssueDoc doc = new IssueDoc(new HashMap<>(30)); String key = rs.getString(1); diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java index 646979ecbcc..400aa3fa3c6 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/AbstractNewIssuesEmailTemplate.java @@ -35,6 +35,7 @@ import org.sonar.core.i18n.I18n; import org.sonar.server.issue.notification.NewIssuesStatistics.Metric; import static com.google.common.base.Preconditions.checkNotNull; +import static java.nio.charset.StandardCharsets.UTF_8; /** * Base class to create emails for new issues @@ -65,7 +66,7 @@ public abstract class AbstractNewIssuesEmailTemplate implements EmailTemplate { public static String encode(String toEncode) { try { - return URLEncoder.encode(toEncode, "UTF-8"); + return URLEncoder.encode(toEncode, UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Encoding not supported", e); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssueChangesEmailTemplate.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssueChangesEmailTemplate.java index 2ef310f5964..f2aa43a65da 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssueChangesEmailTemplate.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssueChangesEmailTemplate.java @@ -41,6 +41,7 @@ import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Proj import org.sonar.server.issue.notification.IssuesChangesNotificationBuilder.Rule; import static java.net.URLEncoder.encode; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.sonar.core.util.stream.MoreCollectors.index; public abstract class IssueChangesEmailTemplate implements EmailTemplate { @@ -200,7 +201,7 @@ public abstract class IssueChangesEmailTemplate implements EmailTemplate { private static String urlEncode(String str) { try { - return encode(str, "UTF-8"); + return encode(str, UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilder.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilder.java index a0fadc8fd92..c894b33867f 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilder.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationBuilder.java @@ -371,7 +371,7 @@ public class IssuesChangesNotificationBuilder { protected final long date; private Change(long date) { - this.date = requireNonNull(date, "date can't be null"); + this.date = date; } public long getDate() { diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/notification/NotificationDispatcherMetadata.java b/server/sonar-server-common/src/main/java/org/sonar/server/notification/NotificationDispatcherMetadata.java index 6b225d9e367..19d6f000f9f 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/notification/NotificationDispatcherMetadata.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/notification/NotificationDispatcherMetadata.java @@ -19,7 +19,7 @@ */ package org.sonar.server.notification; -import com.google.common.collect.Maps; +import java.util.HashMap; import java.util.Map; import org.sonar.api.ce.ComputeEngineSide; import org.sonar.api.server.ServerSide; @@ -43,7 +43,7 @@ public final class NotificationDispatcherMetadata { private NotificationDispatcherMetadata(String dispatcherKey) { this.dispatcherKey = dispatcherKey; - this.properties = Maps.newHashMap(); + this.properties = new HashMap<>(); } /** diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java index d75627e3291..c34aa929763 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/rule/index/RuleExtensionDoc.java @@ -19,7 +19,7 @@ */ package org.sonar.server.rule.index; -import com.google.common.collect.Maps; +import java.util.HashMap; import java.util.Map; import java.util.Set; import org.apache.commons.lang.builder.ReflectionToStringBuilder; @@ -36,7 +36,7 @@ public class RuleExtensionDoc extends BaseDoc { } public RuleExtensionDoc() { - super(TYPE_RULE_EXTENSION, Maps.newHashMapWithExpectedSize(4)); + super(TYPE_RULE_EXTENSION, new HashMap<>(4)); } @Override diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java index ed435fadfa7..5bcecedff3a 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/user/index/UserDoc.java @@ -19,7 +19,7 @@ */ package org.sonar.server.user.index; -import com.google.common.collect.Maps; +import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Nullable; @@ -35,7 +35,7 @@ public class UserDoc extends BaseDoc { } public UserDoc() { - this(Maps.newHashMap()); + this(new HashMap<>()); } @Override diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewDoc.java index bff2c49ac2b..db9d0e0f33e 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewDoc.java @@ -19,7 +19,7 @@ */ package org.sonar.server.view.index; -import com.google.common.collect.Maps; +import java.util.HashMap; import java.util.List; import java.util.Map; import org.sonar.server.es.BaseDoc; @@ -33,7 +33,7 @@ public class ViewDoc extends BaseDoc { } public ViewDoc() { - super(TYPE_VIEW, Maps.newHashMap()); + super(TYPE_VIEW, new HashMap<>()); } @Override diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewIndexer.java b/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewIndexer.java index 5a7c581ac84..2dc241e6880 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewIndexer.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/view/index/ViewIndexer.java @@ -21,6 +21,7 @@ package org.sonar.server.view.index; import com.google.common.collect.ImmutableSet; import java.util.Collection; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -40,7 +41,6 @@ import org.sonar.server.es.IndexingResult; import org.sonar.server.es.OneToOneResilientIndexingListener; import org.sonar.server.es.ResilientIndexer; -import static com.google.common.collect.Maps.newHashMap; import static org.sonar.core.util.stream.MoreCollectors.toHashSet; import static org.sonar.server.view.index.ViewIndexDefinition.TYPE_VIEW; @@ -62,7 +62,7 @@ public class ViewIndexer implements ResilientIndexer { @Override public void indexOnStartup(Set<IndexType> uninitializedIndexTypes) { try (DbSession dbSession = dbClient.openSession(false)) { - Map<String, String> viewAndProjectViewUuidMap = newHashMap(); + Map<String, String> viewAndProjectViewUuidMap = new HashMap<>(); for (UuidWithProjectUuidDto uuidWithProjectUuidDto : dbClient.componentDao().selectAllViewsAndSubViews(dbSession)) { viewAndProjectViewUuidMap.put(uuidWithProjectUuidDto.getUuid(), uuidWithProjectUuidDto.getProjectUuid()); } @@ -78,7 +78,7 @@ public class ViewIndexer implements ResilientIndexer { */ public void index(String rootViewUuid) { try (DbSession dbSession = dbClient.openSession(false)) { - Map<String, String> viewAndProjectViewUuidMap = newHashMap(); + Map<String, String> viewAndProjectViewUuidMap = new HashMap<>(); for (ComponentDto viewOrSubView : dbClient.componentDao().selectEnabledDescendantModules(dbSession, rootViewUuid)) { viewAndProjectViewUuidMap.put(viewOrSubView.uuid(), viewOrSubView.projectUuid()); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java index 774b98ccd8a..f436837c6cb 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/webhook/WebhookPayloadFactoryImpl.java @@ -36,6 +36,7 @@ import org.sonar.server.qualitygate.EvaluatedCondition; import org.sonar.server.qualitygate.EvaluatedQualityGate; import static java.lang.String.format; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.sonar.core.config.CorePropertyDefinitions.SONAR_ANALYSIS; @ServerSide @@ -164,7 +165,7 @@ public class WebhookPayloadFactoryImpl implements WebhookPayloadFactory { private static String encode(String toEncode) { try { - return URLEncoder.encode(toEncode, "UTF-8"); + return URLEncoder.encode(toEncode, UTF_8.name()); } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Encoding not supported", e); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/OneToManyResilientIndexingListenerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/OneToManyResilientIndexingListenerTest.java index 8bceb9261e4..3e6ea8f7b4d 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/OneToManyResilientIndexingListenerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/OneToManyResilientIndexingListenerTest.java @@ -112,7 +112,7 @@ public class OneToManyResilientIndexingListenerTest { try (DbSession otherSession = db.getDbClient().openSession(false)) { List<String> uuidsInDb = db.getDbClient().esQueueDao().selectForRecovery(otherSession, Long.MAX_VALUE, 10) .stream().map(EsQueueDto::getUuid).collect(toList()); - String expectedUuids[] = Arrays.stream(expected).map(EsQueueDto::getUuid).toArray(String[]::new); + String[] expectedUuids = Arrays.stream(expected).map(EsQueueDto::getUuid).toArray(String[]::new); assertThat(uuidsInDb).containsExactlyInAnyOrder(expectedUuids); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/OneToOneResilientIndexingListenerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/OneToOneResilientIndexingListenerTest.java index c46a0ad3732..1cd9569c373 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/OneToOneResilientIndexingListenerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/OneToOneResilientIndexingListenerTest.java @@ -107,7 +107,7 @@ public class OneToOneResilientIndexingListenerTest { try (DbSession otherSession = db.getDbClient().openSession(false)) { List<String> uuidsInDb = db.getDbClient().esQueueDao().selectForRecovery(otherSession, Long.MAX_VALUE, 10) .stream().map(EsQueueDto::getUuid).collect(toList()); - String expectedUuids[] = Arrays.stream(expected).map(EsQueueDto::getUuid).toArray(String[]::new); + String[] expectedUuids = Arrays.stream(expected).map(EsQueueDto::getUuid).toArray(String[]::new); assertThat(uuidsInDb).containsExactlyInAnyOrder(expectedUuids); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/es/SortingTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/es/SortingTest.java index 7b17b13bf87..56c74591f5a 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/es/SortingTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/es/SortingTest.java @@ -47,7 +47,7 @@ public class SortingTest { } @Test - public void ascending_sort_on_single_field() throws Exception { + public void ascending_sort_on_single_field() { Sorting sorting = new Sorting(); sorting.add("updatedAt"); @@ -57,7 +57,7 @@ public class SortingTest { } @Test - public void descending_sort_on_single_field() throws Exception { + public void descending_sort_on_single_field() { Sorting sorting = new Sorting(); sorting.add("updatedAt"); @@ -67,7 +67,7 @@ public class SortingTest { } @Test - public void ascending_sort_on_single_field_with_missing_in_last_position() throws Exception { + public void ascending_sort_on_single_field_with_missing_in_last_position() { Sorting sorting = new Sorting(); sorting.add("updatedAt").missingLast(); @@ -77,7 +77,7 @@ public class SortingTest { } @Test - public void descending_sort_on_single_field_with_missing_in_last_position() throws Exception { + public void descending_sort_on_single_field_with_missing_in_last_position() { Sorting sorting = new Sorting(); sorting.add("updatedAt").missingLast(); @@ -87,7 +87,7 @@ public class SortingTest { } @Test - public void sort_on_multiple_fields() throws Exception { + public void sort_on_multiple_fields() { // asc => file asc, line asc, severity desc, key asc Sorting sorting = new Sorting(); sorting.add("fileLine", "file"); diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationHandlerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationHandlerTest.java index 9f51b5b233b..e658991e580 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationHandlerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/ChangesOnMyIssueNotificationHandlerTest.java @@ -447,8 +447,7 @@ public class ChangesOnMyIssueNotificationHandlerTest { } private static IssuesChangesNotification newNotification(@Nullable String projectKey, @Nullable String assignee, @Nullable String changeAuthor) { - IssuesChangesNotification notification = mock(IssuesChangesNotification.class); - return notification; + return mock(IssuesChangesNotification.class); } private static NotificationManager.EmailRecipient emailRecipientOf(String login) { diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java index ec1fc186f39..9ac507b85fc 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/MyNewIssuesEmailTemplateTest.java @@ -53,7 +53,7 @@ public class MyNewIssuesEmailTemplateTest { private MyNewIssuesEmailTemplate underTest = new MyNewIssuesEmailTemplate(new EmailSettings(settings.asConfig(), server), i18n); @Before - public void setUp() throws Exception { + public void setUp() { when(server.getPublicRootUrl()).thenReturn("http://nemo.sonarsource.org"); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java index df611026d05..7650eb90a26 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/notification/NewIssuesEmailTemplateTest.java @@ -54,7 +54,7 @@ public class NewIssuesEmailTemplateTest { private NewIssuesEmailTemplate template = new NewIssuesEmailTemplate(new EmailSettings(settings.asConfig(), server), i18n); @Before - public void setUp() throws Exception { + public void setUp() { when(server.getPublicRootUrl()).thenReturn("http://nemo.sonarsource.org"); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowTest.java index 60c6596b710..68b15254840 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/issue/workflow/IssueWorkflowTest.java @@ -19,7 +19,6 @@ */ package org.sonar.server.issue.workflow; -import com.google.common.base.Function; import com.google.common.collect.Collections2; import com.tngtech.java.junit.dataprovider.DataProvider; import com.tngtech.java.junit.dataprovider.DataProviderRunner; @@ -473,11 +472,6 @@ public class IssueWorkflowTest { } private Collection<String> keys(List<Transition> transitions) { - return Collections2.transform(transitions, new Function<Transition, String>() { - @Override - public String apply(@Nullable Transition transition) { - return transition.key(); - } - }); + return Collections2.transform(transitions, Transition::key); } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/property/InternalPropertiesImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/property/InternalPropertiesImplTest.java index 849a0d70d22..f891369cf1e 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/property/InternalPropertiesImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/property/InternalPropertiesImplTest.java @@ -47,7 +47,7 @@ public class InternalPropertiesImplTest { private InternalPropertiesImpl underTest = new InternalPropertiesImpl(dbClient); @Before - public void setUp() throws Exception { + public void setUp() { when(dbClient.openSession(false)).thenReturn(dbSession); when(dbClient.internalPropertiesDao()).thenReturn(internalPropertiesDao); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/notification/QGChangeEmailTemplateTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/notification/QGChangeEmailTemplateTest.java index 212f49b3699..03aedec2284 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/notification/QGChangeEmailTemplateTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualitygate/notification/QGChangeEmailTemplateTest.java @@ -196,7 +196,7 @@ public class QGChangeEmailTemplateTest { } private Notification createNotification(String alertName, String alertText, String alertLevel, String isNewAlert) { - Notification notification = new Notification("alerts") + return new Notification("alerts") .setFieldValue("projectName", "Foo") .setFieldValue("projectKey", "org.sonar.foo:foo") .setFieldValue("projectId", "45") @@ -205,7 +205,6 @@ public class QGChangeEmailTemplateTest { .setFieldValue("alertText", alertText) .setFieldValue("alertLevel", alertLevel) .setFieldValue("isNewAlert", isNewAlert); - return notification; } } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java index 060f0e290e3..d491b47943f 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/qualityprofile/index/ActiveRuleIndexerTest.java @@ -58,7 +58,6 @@ public class ActiveRuleIndexerTest { private ActiveRuleIndexer underTest = new ActiveRuleIndexer(db.getDbClient(), es.client()); private RuleDefinitionDto rule1; private RuleDefinitionDto rule2; - private OrganizationDto org; private QProfileDto profile1; private QProfileDto profile2; @@ -66,7 +65,7 @@ public class ActiveRuleIndexerTest { public void before() { rule1 = db.rules().insert(); rule2 = db.rules().insert(); - org = db.organizations().insert(); + OrganizationDto org = db.organizations().insert(); profile1 = db.qualityProfiles().insert(org); profile2 = db.qualityProfiles().insert(org); } diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java index b3f95151083..1aab8c4f366 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/setting/ThreadLocalSettingsTest.java @@ -375,7 +375,7 @@ public class ThreadLocalSettingsTest { captor.verifyValue(settings, expectedValue); } - private class CacheCaptorThread extends Thread { + private static class CacheCaptorThread extends Thread { private final CountDownLatch latch = new CountDownLatch(1); private ThreadLocalSettings settings; private String value; diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/util/AbstractStoppableExecutorServiceTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/util/AbstractStoppableExecutorServiceTest.java index 637eda5e533..35fac76f8b0 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/util/AbstractStoppableExecutorServiceTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/util/AbstractStoppableExecutorServiceTest.java @@ -35,20 +35,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; public class AbstractStoppableExecutorServiceTest { - private static final Callable<String> SOME_CALLABLE = new Callable<String>() { - @Override - public String call() { - return null; - } - }; - private static final Runnable SOME_RUNNABLE = new Runnable() { - @Override - public void run() { + private static final Callable<String> SOME_CALLABLE = () -> null; + private static final Runnable SOME_RUNNABLE = () -> { - } }; private static final String SOME_STRING = "some string"; - private static final long SOME_LONG = 100l; + private static final long SOME_LONG = 100L; private static final int TIMEOUT = 5; private static final TimeUnit TIMEOUT_UNIT = TimeUnit.SECONDS; diff --git a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java index b33aec78e8f..09cf223f94c 100644 --- a/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java +++ b/server/sonar-server-common/src/test/java/org/sonar/server/webhook/WebhookPayloadFactoryImplTest.java @@ -49,7 +49,7 @@ public class WebhookPayloadFactoryImplTest { private WebhookPayloadFactory underTest = new WebhookPayloadFactoryImpl(server, system2); @Before - public void setUp() throws Exception { + public void setUp() { when(server.getPublicRootUrl()).thenReturn("http://foo"); when(system2.now()).thenReturn(1_500_999L); } diff --git a/server/sonar-server-common/src/testFixtures/java/org/elasticsearch/transport/MockTcpTransport.java b/server/sonar-server-common/src/testFixtures/java/org/elasticsearch/transport/MockTcpTransport.java index b5d89ef054d..3ab2dd12797 100644 --- a/server/sonar-server-common/src/testFixtures/java/org/elasticsearch/transport/MockTcpTransport.java +++ b/server/sonar-server-common/src/testFixtures/java/org/elasticsearch/transport/MockTcpTransport.java @@ -199,7 +199,7 @@ public class MockTcpTransport extends TcpTransport { configureSocket(socket); success = true; } finally { - if (success == false) { + if (!success) { IOUtils.close(socket); } } @@ -233,7 +233,7 @@ public class MockTcpTransport extends TcpTransport { } // make sure we maintain at least the types that are supported by this profile even if we only use a single channel for them. builder.addConnections(1, allTypesWithConnection.toArray(new TransportRequestOptions.Type[0])); - if (allTypesWithoutConnection.isEmpty() == false) { + if (!allTypesWithoutConnection.isEmpty()) { builder.addConnections(0, allTypesWithoutConnection.toArray(new TransportRequestOptions.Type[0])); } builder.setHandshakeTimeout(connectionProfile.getHandshakeTimeout()); @@ -479,7 +479,7 @@ public class MockTcpTransport extends TcpTransport { super.doStart(); success = true; } finally { - if (success == false) { + if (!success) { doStop(); } } diff --git a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/FakeDoc.java b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/FakeDoc.java index d199ed9323a..01fa5a56611 100644 --- a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/FakeDoc.java +++ b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/es/FakeDoc.java @@ -19,14 +19,14 @@ */ package org.sonar.server.es; -import com.google.common.collect.Maps; +import java.util.HashMap; import static org.sonar.server.es.newindex.FakeIndexDefinition.INT_FIELD; import static org.sonar.server.es.newindex.FakeIndexDefinition.TYPE_FAKE; public class FakeDoc extends BaseDoc { public FakeDoc() { - super(TYPE_FAKE, Maps.newHashMap()); + super(TYPE_FAKE, new HashMap<>()); } @Override diff --git a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java index c63f12e950c..d50bd557c38 100644 --- a/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java +++ b/server/sonar-server-common/src/testFixtures/java/org/sonar/server/issue/IssueDocTesting.java @@ -19,8 +19,8 @@ */ package org.sonar.server.issue; -import com.google.common.collect.Maps; import java.util.Date; +import java.util.HashMap; import org.sonar.api.resources.Scopes; import org.sonar.api.rule.Severity; import org.sonar.api.rules.RuleType; @@ -54,7 +54,7 @@ public class IssueDocTesting { } public static IssueDoc newDoc() { - IssueDoc doc = new IssueDoc(Maps.newHashMap()); + IssueDoc doc = new IssueDoc(new HashMap<>()); doc.setKey(Uuids.createFast()); doc.setRuleId(nextInt(1000)); doc.setType(RuleType.CODE_SMELL); |