From 60098df151efa8203affe6ba047a6ea32947d4f0 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Wed, 3 Jun 2015 12:22:16 +0200 Subject: [PATCH] SONAR-6370 fix quality flaws --- .../process/MinimumViableSystemTest.java | 7 +-- .../email/EmailNotificationChannel.java | 2 +- .../server/plugins/ws/InstallAction.java | 5 +- .../server/plugins/ws/InstalledAction.java | 13 ++--- .../server/issue/IssuesFinderSortTest.java | 49 +++++++++-------- .../email/EmailNotificationChannelTest.java | 45 ++++++++-------- .../rule/DefaultRuleFinderMediumTest.java | 46 ++++++++-------- .../org/sonar/core/platform/PluginLoader.java | 6 +-- .../internal/DefaultFilePredicatesTest.java | 2 +- .../org/sonar/api/utils/DateUtilsTest.java | 53 +++++++++---------- 10 files changed, 109 insertions(+), 119 deletions(-) diff --git a/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java b/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java index dc2bdf2c4a6..ca2d7f2ce95 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/MinimumViableSystemTest.java @@ -26,6 +26,7 @@ import org.junit.rules.TemporaryFolder; import java.io.File; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; public class MinimumViableSystemTest { @@ -61,7 +62,7 @@ public class MinimumViableSystemTest { mve.checkJavaVersion("1.9"); fail(); } catch (MessageException e) { - Assertions.assertThat(e).hasMessage("Supported versions of Java are 1.6, 1.7 and 1.8. Got 1.9."); + assertThat(e).hasMessage("Supported versions of Java are 1.6, 1.7 and 1.8. Got 1.9."); } } @@ -76,7 +77,7 @@ public class MinimumViableSystemTest { mve.checkJavaOptions(); fail(); } catch (MessageException e) { - Assertions.assertThat(e).hasMessage("JVM option '" + key + "' must be set to 'true'. Got 'false'"); + assertThat(e).hasMessage("JVM option '" + key + "' must be set to 'true'. Got 'false'"); } System.setProperty(key, "true"); @@ -96,7 +97,7 @@ public class MinimumViableSystemTest { mve.checkWritableDir(dir.getAbsolutePath()); fail(); } catch (IllegalStateException e) { - Assertions.assertThat(e).hasMessage("Temp directory is not writable: " + dir.getAbsolutePath()); + assertThat(e).hasMessage("Temp directory is not writable: " + dir.getAbsolutePath()); } } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/notifications/email/EmailNotificationChannel.java b/server/sonar-server/src/main/java/org/sonar/server/notifications/email/EmailNotificationChannel.java index 20303871339..3b96270736b 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/notifications/email/EmailNotificationChannel.java +++ b/server/sonar-server/src/main/java/org/sonar/server/notifications/email/EmailNotificationChannel.java @@ -163,7 +163,7 @@ public class EmailNotificationChannel extends NotificationChannel { } // Set general information email.setCharset("UTF-8"); - String from = StringUtils.isBlank(emailMessage.getFrom()) ? FROM_NAME_DEFAULT : emailMessage.getFrom() + " (SonarQube)"; + String from = StringUtils.isBlank(emailMessage.getFrom()) ? FROM_NAME_DEFAULT : (emailMessage.getFrom() + " (SonarQube)"); email.setFrom(configuration.getFrom(), from); email.addTo(emailMessage.getTo(), " "); String subject = StringUtils.defaultIfBlank(StringUtils.trimToEmpty(configuration.getPrefix()) + " ", "") diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java index e69f4d61b1c..e629620df2e 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstallAction.java @@ -21,6 +21,7 @@ package org.sonar.server.plugins.ws; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import javax.annotation.Nullable; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -30,8 +31,6 @@ import org.sonar.server.plugins.UpdateCenterMatrixFactory; import org.sonar.server.user.UserSession; import org.sonar.updatecenter.common.PluginUpdate; -import javax.annotation.Nullable; - import static java.lang.String.format; /** @@ -47,7 +46,7 @@ public class InstallAction implements PluginsWsAction { private final UserSession userSession; public InstallAction(UpdateCenterMatrixFactory updateCenterFactory, - PluginDownloader pluginDownloader, UserSession userSession) { + PluginDownloader pluginDownloader, UserSession userSession) { this.updateCenterFactory = updateCenterFactory; this.pluginDownloader = pluginDownloader; this.userSession = userSession; diff --git a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java index 97946e070be..37cc7436ec4 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/plugins/ws/InstalledAction.java @@ -19,9 +19,9 @@ */ package org.sonar.server.plugins.ws; -import com.google.common.base.Predicate; -import com.google.common.collect.ImmutableSortedSet; import com.google.common.io.Resources; +import java.util.Collection; +import java.util.SortedSet; import org.sonar.api.server.ws.Request; import org.sonar.api.server.ws.Response; import org.sonar.api.server.ws.WebService; @@ -29,13 +29,7 @@ import org.sonar.api.utils.text.JsonWriter; import org.sonar.core.platform.PluginInfo; import org.sonar.server.plugins.ServerPluginRepository; -import javax.annotation.Nullable; - -import java.util.Collection; -import java.util.SortedSet; - import static com.google.common.collect.ImmutableSortedSet.copyOf; -import static com.google.common.collect.Iterables.filter; import static org.sonar.server.plugins.ws.PluginWSCommons.NAME_KEY_PLUGIN_METADATA_COMPARATOR; /** @@ -47,8 +41,7 @@ public class InstalledAction implements PluginsWsAction { private final ServerPluginRepository pluginRepository; private final PluginWSCommons pluginWSCommons; - public InstalledAction(ServerPluginRepository pluginRepository, - PluginWSCommons pluginWSCommons) { + public InstalledAction(ServerPluginRepository pluginRepository, PluginWSCommons pluginWSCommons) { this.pluginRepository = pluginRepository; this.pluginWSCommons = pluginWSCommons; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/IssuesFinderSortTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/IssuesFinderSortTest.java index f9ffcdf429c..80ede6a36f0 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/IssuesFinderSortTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/IssuesFinderSortTest.java @@ -23,7 +23,6 @@ package org.sonar.server.issue; import java.util.Date; import java.util.List; import org.apache.commons.lang.time.DateUtils; -import org.assertj.core.api.Assertions; import org.junit.Rule; import org.junit.Test; import org.sonar.core.issue.db.IssueDto; @@ -70,10 +69,10 @@ public class IssuesFinderSortTest { List result = newArrayList(issuesFinderSort.sort()); - Assertions.assertThat(result).hasSize(3); - Assertions.assertThat(result.get(0).getStatus()).isEqualTo("REOPENED"); - Assertions.assertThat(result.get(1).getStatus()).isEqualTo("OPEN"); - Assertions.assertThat(result.get(2).getStatus()).isEqualTo("CLOSED"); + assertThat(result).hasSize(3); + assertThat(result.get(0).getStatus()).isEqualTo("REOPENED"); + assertThat(result.get(1).getStatus()).isEqualTo("OPEN"); + assertThat(result.get(2).getStatus()).isEqualTo("CLOSED"); } @Test @@ -88,10 +87,10 @@ public class IssuesFinderSortTest { List result = newArrayList(issuesFinderSort.sort()); - Assertions.assertThat(result).hasSize(3); - Assertions.assertThat(result.get(0).getSeverity()).isEqualTo("INFO"); - Assertions.assertThat(result.get(1).getSeverity()).isEqualTo("MAJOR"); - Assertions.assertThat(result.get(2).getSeverity()).isEqualTo("BLOCKER"); + assertThat(result).hasSize(3); + assertThat(result.get(0).getSeverity()).isEqualTo("INFO"); + assertThat(result.get(1).getSeverity()).isEqualTo("MAJOR"); + assertThat(result.get(2).getSeverity()).isEqualTo("BLOCKER"); } @Test @@ -106,10 +105,10 @@ public class IssuesFinderSortTest { List result = newArrayList(issuesFinderSort.sort()); - Assertions.assertThat(result).hasSize(3); - Assertions.assertThat(result.get(0).getSeverity()).isEqualTo("BLOCKER"); - Assertions.assertThat(result.get(1).getSeverity()).isEqualTo("MAJOR"); - Assertions.assertThat(result.get(2).getSeverity()).isEqualTo("INFO"); + assertThat(result).hasSize(3); + assertThat(result.get(0).getSeverity()).isEqualTo("BLOCKER"); + assertThat(result.get(1).getSeverity()).isEqualTo("MAJOR"); + assertThat(result.get(2).getSeverity()).isEqualTo("INFO"); } @Test @@ -128,10 +127,10 @@ public class IssuesFinderSortTest { List result = newArrayList(issuesFinderSort.sort()); - Assertions.assertThat(result).hasSize(3); - Assertions.assertThat(result.get(0).getIssueCreationDate()).isEqualTo(date3); - Assertions.assertThat(result.get(1).getIssueCreationDate()).isEqualTo(date2); - Assertions.assertThat(result.get(2).getIssueCreationDate()).isEqualTo(date1); + assertThat(result).hasSize(3); + assertThat(result.get(0).getIssueCreationDate()).isEqualTo(date3); + assertThat(result.get(1).getIssueCreationDate()).isEqualTo(date2); + assertThat(result.get(2).getIssueCreationDate()).isEqualTo(date1); } @Test @@ -150,10 +149,10 @@ public class IssuesFinderSortTest { List result = newArrayList(issuesFinderSort.sort()); - Assertions.assertThat(result).hasSize(3); - Assertions.assertThat(result.get(0).getIssueUpdateDate()).isEqualTo(date3); - Assertions.assertThat(result.get(1).getIssueUpdateDate()).isEqualTo(date2); - Assertions.assertThat(result.get(2).getIssueUpdateDate()).isEqualTo(date1); + assertThat(result).hasSize(3); + assertThat(result.get(0).getIssueUpdateDate()).isEqualTo(date3); + assertThat(result.get(1).getIssueUpdateDate()).isEqualTo(date2); + assertThat(result.get(2).getIssueUpdateDate()).isEqualTo(date1); } @Test @@ -172,10 +171,10 @@ public class IssuesFinderSortTest { List result = newArrayList(issuesFinderSort.sort()); - Assertions.assertThat(result).hasSize(3); - Assertions.assertThat(result.get(0).getIssueCloseDate()).isEqualTo(date3); - Assertions.assertThat(result.get(1).getIssueCloseDate()).isEqualTo(date2); - Assertions.assertThat(result.get(2).getIssueCloseDate()).isEqualTo(date1); + assertThat(result).hasSize(3); + assertThat(result.get(0).getIssueCloseDate()).isEqualTo(date3); + assertThat(result.get(1).getIssueCloseDate()).isEqualTo(date2); + assertThat(result.get(2).getIssueCloseDate()).isEqualTo(date1); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/notifications/email/EmailNotificationChannelTest.java b/server/sonar-server/src/test/java/org/sonar/server/notifications/email/EmailNotificationChannelTest.java index d3e2144fd08..3c5e94587af 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notifications/email/EmailNotificationChannelTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notifications/email/EmailNotificationChannelTest.java @@ -24,7 +24,6 @@ import java.net.ServerSocket; import java.util.List; import javax.mail.internet.MimeMessage; import org.apache.commons.mail.EmailException; -import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -86,10 +85,10 @@ public class EmailNotificationChannelTest { assertThat(messages).hasSize(1); MimeMessage email = messages.get(0).getMimeMessage(); - Assertions.assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); - Assertions.assertThat(email.getHeader("From", ",")).isEqualTo("SonarQube "); - Assertions.assertThat(email.getHeader("To", null)).isEqualTo(""); - Assertions.assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Test Message from SonarQube"); + assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); + assertThat(email.getHeader("From", ",")).isEqualTo("SonarQube "); + assertThat(email.getHeader("To", null)).isEqualTo(""); + assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Test Message from SonarQube"); assertThat((String) email.getContent()).startsWith("This is a test message from SonarQube."); } @@ -113,7 +112,7 @@ public class EmailNotificationChannelTest { .setSubject("Foo") .setMessage("Bar"); channel.deliver(emailMessage); - Assertions.assertThat(server.getMessages()).isEmpty(); + assertThat(server.getMessages()).isEmpty(); } @Test @@ -132,17 +131,17 @@ public class EmailNotificationChannelTest { MimeMessage email = messages.get(0).getMimeMessage(); - Assertions.assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); + assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); - Assertions.assertThat(email.getHeader("In-Reply-To", null)).isEqualTo(""); - Assertions.assertThat(email.getHeader("References", null)).isEqualTo(""); + assertThat(email.getHeader("In-Reply-To", null)).isEqualTo(""); + assertThat(email.getHeader("References", null)).isEqualTo(""); - Assertions.assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube "); - Assertions.assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); + assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube "); + assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); - Assertions.assertThat(email.getHeader("From", ",")).isEqualTo("\"Full Username (SonarQube)\" "); - Assertions.assertThat(email.getHeader("To", null)).isEqualTo(""); - Assertions.assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Review #3"); + assertThat(email.getHeader("From", ",")).isEqualTo("\"Full Username (SonarQube)\" "); + assertThat(email.getHeader("To", null)).isEqualTo(""); + assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Review #3"); assertThat((String) email.getContent()).startsWith("I'll take care of this violation."); } @@ -160,17 +159,17 @@ public class EmailNotificationChannelTest { MimeMessage email = messages.get(0).getMimeMessage(); - Assertions.assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); + assertThat(email.getHeader("Content-Type", null)).isEqualTo("text/plain; charset=UTF-8"); - Assertions.assertThat(email.getHeader("In-Reply-To", null)).isNull(); - Assertions.assertThat(email.getHeader("References", null)).isNull(); + assertThat(email.getHeader("In-Reply-To", null)).isNull(); + assertThat(email.getHeader("References", null)).isNull(); - Assertions.assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube "); - Assertions.assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); + assertThat(email.getHeader("List-ID", null)).isEqualTo("SonarQube "); + assertThat(email.getHeader("List-Archive", null)).isEqualTo("http://nemo.sonarsource.org"); - Assertions.assertThat(email.getHeader("From", null)).isEqualTo("SonarQube "); - Assertions.assertThat(email.getHeader("To", null)).isEqualTo(""); - Assertions.assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Foo"); + assertThat(email.getHeader("From", null)).isEqualTo("SonarQube "); + assertThat(email.getHeader("To", null)).isEqualTo(""); + assertThat(email.getHeader("Subject", null)).isEqualTo("[SONARQUBE] Foo"); assertThat((String) email.getContent()).startsWith("Bar"); } @@ -198,7 +197,7 @@ public class EmailNotificationChannelTest { fail("An SSL exception was expected a a proof that STARTTLS is enabled"); } catch (EmailException e) { // We don't have a SSL certificate so we are expecting a SSL error - Assertions.assertThat(e.getCause().getMessage()).isEqualTo("Could not convert socket to TLS"); + assertThat(e.getCause().getMessage()).isEqualTo("Could not convert socket to TLS"); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java b/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java index ff3138efd8b..3d5939bdd16 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/rule/DefaultRuleFinderMediumTest.java @@ -19,8 +19,12 @@ */ package org.sonar.server.rule; -import org.assertj.core.api.Assertions; -import org.junit.*; +import java.util.Collections; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; import org.sonar.api.rule.RuleKey; import org.sonar.api.rule.RuleStatus; import org.sonar.api.rules.Rule; @@ -29,8 +33,6 @@ import org.sonar.core.persistence.DbSession; import org.sonar.core.rule.RuleDto; import org.sonar.server.db.DbClient; import org.sonar.server.tester.ServerTester; - -import java.util.Collections; import org.sonar.server.tester.UserSessionRule; import static com.google.common.collect.Lists.newArrayList; @@ -92,7 +94,7 @@ public class DefaultRuleFinderMediumTest { .setSeverity(2) .setStatus(RuleStatus.READY), RuleTesting.newManualRule("Manual_Rule").setName("Manual Rule") - ); + ); session.commit(); session.close(); } @@ -106,39 +108,39 @@ public class DefaultRuleFinderMediumTest { public void should_success_finder_wrap() { // has Id - Assertions.assertThat(finder.findById(1).getId()).isEqualTo(1); + assertThat(finder.findById(1).getId()).isEqualTo(1); // should_find_by_id - Assertions.assertThat(finder.findById(3).getConfigKey()).isEqualTo("Checker/Treewalker/AnnotationUseStyleCheck"); + assertThat(finder.findById(3).getConfigKey()).isEqualTo("Checker/Treewalker/AnnotationUseStyleCheck"); // should_not_find_disabled_rule_by_id - Assertions.assertThat(finder.findById(2)).isNull(); + assertThat(finder.findById(2)).isNull(); // should_find_by_ids assertThat(finder.findByIds(newArrayList(2, 3))).hasSize(2); // should_find_by_key Rule rule = finder.findByKey("checkstyle", "com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck"); - Assertions.assertThat(rule).isNotNull(); - Assertions.assertThat(rule.getKey()).isEqualTo(("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck")); - Assertions.assertThat(rule.isEnabled()).isTrue(); + assertThat(rule).isNotNull(); + assertThat(rule.getKey()).isEqualTo(("com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck")); + assertThat(rule.isEnabled()).isTrue(); // find_should_return_null_if_no_results - Assertions.assertThat(finder.findByKey("checkstyle", "unknown")).isNull(); - Assertions.assertThat(finder.find(RuleQuery.create().withRepositoryKey("checkstyle").withConfigKey("unknown"))).isNull(); + assertThat(finder.findByKey("checkstyle", "unknown")).isNull(); + assertThat(finder.find(RuleQuery.create().withRepositoryKey("checkstyle").withConfigKey("unknown"))).isNull(); // find_repository_rules - Assertions.assertThat(finder.findAll(RuleQuery.create().withRepositoryKey("checkstyle"))).hasSize(2); + assertThat(finder.findAll(RuleQuery.create().withRepositoryKey("checkstyle"))).hasSize(2); // find_all_enabled - Assertions.assertThat(finder.findAll(RuleQuery.create())).extracting("id").containsOnly(1, 3, 4, 5); - Assertions.assertThat(finder.findAll(RuleQuery.create())).hasSize(4); + assertThat(finder.findAll(RuleQuery.create())).extracting("id").containsOnly(1, 3, 4, 5); + assertThat(finder.findAll(RuleQuery.create())).hasSize(4); // do_not_find_disabled_rules - Assertions.assertThat(finder.findByKey("checkstyle", "DisabledCheck")).isNull(); + assertThat(finder.findByKey("checkstyle", "DisabledCheck")).isNull(); // do_not_find_unknown_rules - Assertions.assertThat(finder.findAll(RuleQuery.create().withRepositoryKey("unknown_repository"))).isEmpty(); + assertThat(finder.findAll(RuleQuery.create().withRepositoryKey("unknown_repository"))).isEmpty(); // should_find_by_ids_empty tester.clearDbAndIndexes(); @@ -170,17 +172,17 @@ public class DefaultRuleFinderMediumTest { @Test public void find_all_not_include_removed_rule() { // find rule with id 2 is REMOVED - Assertions.assertThat(finder.findAll(RuleQuery.create())).extracting("id").containsOnly(1, 3, 4, 5); + assertThat(finder.findAll(RuleQuery.create())).extracting("id").containsOnly(1, 3, 4, 5); } @Test public void find_manual_rule() { // find by id - Assertions.assertThat(finder.findById(5)).isNotNull(); + assertThat(finder.findById(5)).isNotNull(); // find by key Rule rule = finder.findByKey("manual", "Manual_Rule"); - Assertions.assertThat(rule).isNotNull(); - Assertions.assertThat(rule.isEnabled()).isTrue(); + assertThat(rule).isNotNull(); + assertThat(rule.isEnabled()).isTrue(); } } diff --git a/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java b/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java index 1012c8ca438..f5f96814066 100644 --- a/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java +++ b/sonar-core/src/main/java/org/sonar/core/platform/PluginLoader.java @@ -94,7 +94,7 @@ public class PluginLoader { if (Strings.isNullOrEmpty(info.getBasePlugin())) { def.setSelfFirstStrategy(info.isUseChildFirstClassLoader()); Version minSqVersion = info.getMinimalSqVersion(); - boolean compatibilityMode = (minSqVersion != null && minSqVersion.compareToIgnoreQualifier(COMPATIBILITY_MODE_MAX_VERSION) < 0); + boolean compatibilityMode = minSqVersion != null && minSqVersion.compareToIgnoreQualifier(COMPATIBILITY_MODE_MAX_VERSION) < 0; def.setCompatibilityMode(compatibilityMode); if (compatibilityMode) { Loggers.get(getClass()).info("API compatibility mode is enabled on plugin {} [{}] " + @@ -112,8 +112,8 @@ public class PluginLoader { * @return the instances grouped by plugin key * @throws IllegalStateException if at least one plugin can't be correctly loaded */ - @VisibleForTesting - Map instantiatePluginClasses(Map classloaders) { + @VisibleForTesting + Map instantiatePluginClasses(Map classloaders) { // instantiate plugins Map instancesByPluginKey = new HashMap<>(); for (Map.Entry entry : classloaders.entrySet()) { diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java index 1877b74831c..794b8e7b615 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/fs/internal/DefaultFilePredicatesTest.java @@ -54,7 +54,7 @@ public class DefaultFilePredicatesTest { @Test public void all() { - Assertions.assertThat(predicates.all().apply(javaFile)).isTrue(); + assertThat(predicates.all().apply(javaFile)).isTrue(); } @Test diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java index ca4052f33e3..d737f3c0779 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java @@ -19,18 +19,15 @@ */ package org.sonar.api.utils; -import org.assertj.core.api.Assertions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - import java.util.ArrayList; import java.util.Date; import java.util.List; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; -import static org.hamcrest.Matchers.*; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Fail.fail; public class DateUtilsTest { @@ -40,7 +37,7 @@ public class DateUtilsTest { @Test public void parseDate_valid_format() { Date date = DateUtils.parseDate("2010-05-18"); - assertThat(date.getDate(), is(18)); + assertThat(date.getDate()).isEqualTo(18); } @Test @@ -51,9 +48,9 @@ public class DateUtilsTest { @Test public void parseDateQuietly() { - assertNull(DateUtils.parseDateQuietly("2010/05/18")); + assertThat(DateUtils.parseDateQuietly("2010/05/18")).isNull(); Date date = DateUtils.parseDateQuietly("2010-05-18"); - assertThat(date.getDate(), is(18)); + assertThat(date.getDate()).isEqualTo(18); } @Test @@ -65,7 +62,7 @@ public class DateUtilsTest { @Test public void parseDateTime_valid_format() { Date date = DateUtils.parseDateTime("2010-05-18T15:50:45+0100"); - assertThat(date.getMinutes(), is(50)); + assertThat(date.getMinutes()).isEqualTo(50); } @Test @@ -82,42 +79,42 @@ public class DateUtilsTest { @Test public void parseDateTimeQuietly() { - assertNull(DateUtils.parseDateTimeQuietly("2010/05/18 10:55")); + assertThat(DateUtils.parseDateTimeQuietly("2010/05/18 10:55")).isNull(); Date date = DateUtils.parseDateTimeQuietly("2010-05-18T15:50:45+0100"); - assertThat(date.getMinutes(), is(50)); + assertThat(date.getMinutes()).isEqualTo(50); } @Test public void shouldFormatDate() { - assertThat(DateUtils.formatDate(new Date()), startsWith("20")); - assertThat(DateUtils.formatDate(new Date()).length(), is(10)); + assertThat(DateUtils.formatDate(new Date())).startsWith("20"); + assertThat(DateUtils.formatDate(new Date()).length()).isEqualTo(10); } @Test public void shouldFormatDateTime() { - assertThat(DateUtils.formatDateTime(new Date()), startsWith("20")); - assertThat(DateUtils.formatDateTime(new Date()).length(), greaterThan(20)); + assertThat(DateUtils.formatDateTime(new Date())).startsWith("20"); + assertThat(DateUtils.formatDateTime(new Date()).length()).isGreaterThan(20); } @Test public void format_date_time_null_safe() { - Assertions.assertThat(DateUtils.formatDateTimeNullSafe(new Date())).startsWith("20"); - Assertions.assertThat(DateUtils.formatDateTimeNullSafe(new Date()).length()).isGreaterThan(20); - Assertions.assertThat(DateUtils.formatDateTimeNullSafe(null)).isEmpty(); + assertThat(DateUtils.formatDateTimeNullSafe(new Date())).startsWith("20"); + assertThat(DateUtils.formatDateTimeNullSafe(new Date()).length()).isGreaterThan(20); + assertThat(DateUtils.formatDateTimeNullSafe(null)).isEmpty(); } @Test public void long_to_date() { Date date = new Date(); - Assertions.assertThat(DateUtils.longToDate(date.getTime())).isEqualTo(date); - Assertions.assertThat(DateUtils.longToDate(null)).isNull(); + assertThat(DateUtils.longToDate(date.getTime())).isEqualTo(date); + assertThat(DateUtils.longToDate(null)).isNull(); } @Test public void date_to_long() { Date date = new Date(); - Assertions.assertThat(DateUtils.dateToLong(date)).isEqualTo(date.getTime()); - Assertions.assertThat(DateUtils.dateToLong(null)).isEqualTo(null); + assertThat(DateUtils.dateToLong(date)).isEqualTo(date.getTime()); + assertThat(DateUtils.dateToLong(null)).isEqualTo(null); } /** @@ -155,7 +152,7 @@ public class DateUtilsTest { while (i < 1000 && !interrupted()) { String formatted = format.format(now); Thread.yield(); - assertEquals(now, format.parse(formatted)); + assertThat(now).isEqualTo(format.parse(formatted)); ++i; } } catch (Exception e) { @@ -193,7 +190,7 @@ public class DateUtilsTest { } } - assertThat(throwables.size(), is(0)); - assertThat(counter[0], greaterThanOrEqualTo(threads.length)); + assertThat(throwables).isEmpty(); + assertThat(counter[0]).isGreaterThanOrEqualTo(threads.length); } } -- 2.39.5