diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-19 13:07:11 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-02-19 13:07:11 +0100 |
commit | 4dcf22377c7823584f0d9d7dbb85641980245fd8 (patch) | |
tree | 28594d8d59c4f64deb7e3aa6f06f48b0e737cdb1 | |
parent | c3ae1aa643eb9edb168016bfadfbab3af9024962 (diff) | |
download | sonarqube-4dcf22377c7823584f0d9d7dbb85641980245fd8.tar.gz sonarqube-4dcf22377c7823584f0d9d7dbb85641980245fd8.zip |
Clean-up sonar-testing-harness dependencies
and decrease usages of Hamcrest
40 files changed, 634 insertions, 514 deletions
diff --git a/server/sonar-ce/pom.xml b/server/sonar-ce/pom.xml index 8aafdcdfb6f..f3254d6489d 100644 --- a/server/sonar-ce/pom.xml +++ b/server/sonar-ce/pom.xml @@ -34,8 +34,23 @@ <!-- unit tests --> <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>sonar-testing-harness</artifactId> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.tngtech.java</groupId> + <artifactId>junit-dataprovider</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> <dependency> diff --git a/server/sonar-db-core/pom.xml b/server/sonar-db-core/pom.xml index 9db00b7555c..fbb6022b1af 100644 --- a/server/sonar-db-core/pom.xml +++ b/server/sonar-db-core/pom.xml @@ -77,24 +77,28 @@ <!-- tests --> <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>sonar-testing-harness</artifactId> + <groupId>junit</groupId> + <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>com.google.code.bean-matchers</groupId> - <artifactId>bean-matchers</artifactId> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>org.simpleframework</groupId> - <artifactId>simple</artifactId> - <version>4.1.21</version> + <groupId>org.dbunit</groupId> + <artifactId>dbunit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>sonar-testing-harness</artifactId> <scope>test</scope> </dependency> diff --git a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseCheckerTest.java b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseCheckerTest.java index ebe2e86e4ba..79b8fabe357 100644 --- a/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseCheckerTest.java +++ b/server/sonar-db-core/src/test/java/org/sonar/db/DatabaseCheckerTest.java @@ -31,7 +31,6 @@ import org.sonar.db.dialect.MySql; import org.sonar.db.dialect.Oracle; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.is; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -120,14 +119,16 @@ public class DatabaseCheckerTest { @Test public void fail_if_cant_get_db_version() throws Exception { SQLException sqlException = new SQLException(); - expectedException.expect(RuntimeException.class); - expectedException.expectCause(is(sqlException)); - Database db = mock(Database.class, Mockito.RETURNS_DEEP_STUBS); when(db.getDialect()).thenReturn(new MySql()); when(db.getDataSource().getConnection().getMetaData()).thenThrow(sqlException); - new DatabaseChecker(db).start(); + try { + new DatabaseChecker(db).start(); + fail(); + } catch (RuntimeException e) { + assertThat(e.getCause()).isSameAs(sqlException); + } } private Database mockDb(Dialect dialect, int dbMajorVersion, int dbMinorVersion, String driverVersion) throws SQLException { diff --git a/server/sonar-db-dao/pom.xml b/server/sonar-db-dao/pom.xml index 549c13ad181..50ed677660a 100644 --- a/server/sonar-db-dao/pom.xml +++ b/server/sonar-db-dao/pom.xml @@ -34,6 +34,37 @@ <!-- tests --> <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <!-- TODO to be removed --> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-all</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-guava</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.tngtech.java</groupId> + <artifactId>junit-dataprovider</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>sonar-testing-harness</artifactId> <scope>test</scope> diff --git a/server/sonar-db-migration/pom.xml b/server/sonar-db-migration/pom.xml index 14d0b4f4c78..f5142d072b4 100644 --- a/server/sonar-db-migration/pom.xml +++ b/server/sonar-db-migration/pom.xml @@ -30,6 +30,26 @@ <!-- tests --> <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.tngtech.java</groupId> + <artifactId>junit-dataprovider</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>sonar-testing-harness</artifactId> <scope>test</scope> @@ -51,7 +71,6 @@ <artifactId>h2</artifactId> <scope>test</scope> </dependency> - </dependencies> <build> diff --git a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java index 6dde912920c..6c1c95acbe7 100644 --- a/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java +++ b/server/sonar-db-migration/src/test/java/org/sonar/server/platform/db/migration/step/MigrationStepsExecutorImplTest.java @@ -25,10 +25,8 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.stream.Stream; -import org.hamcrest.Matchers; import org.junit.Rule; import org.junit.Test; -import org.junit.rules.ExpectedException; import org.sonar.api.utils.log.LogTester; import org.sonar.api.utils.log.LoggerLevel; import org.sonar.server.platform.db.migration.engine.MigrationContainer; @@ -43,8 +41,6 @@ import static org.mockito.Mockito.mock; public class MigrationStepsExecutorImplTest { @Rule public LogTester logTester = new LogTester(); - @Rule - public ExpectedException expectedException = ExpectedException.none(); private MigrationContainer migrationContainer = new SimpleMigrationContainer(); private MigrationHistory migrationHistor = mock(MigrationHistory.class); @@ -149,11 +145,14 @@ public class MigrationStepsExecutorImplTest { registeredStepOf(1, MigrationStep2.class), registeredStepOf(2, RuntimeExceptionFailingMigrationStep.class), registeredStepOf(3, MigrationStep3.class)); - expectedException.expect(MigrationStepExecutionException.class); - expectedException.expectMessage("Execution of migration step #2 '2-RuntimeExceptionFailingMigrationStep' failed"); - expectedException.expectCause(Matchers.sameInstance(RuntimeExceptionFailingMigrationStep.THROWN_EXCEPTION)); - underTest.execute(steps); + try { + underTest.execute(steps); + fail("should throw MigrationStepExecutionException"); + } catch (MigrationStepExecutionException e) { + assertThat(e).hasMessage("Execution of migration step #2 '2-RuntimeExceptionFailingMigrationStep' failed"); + assertThat(e.getCause()).isSameAs(RuntimeExceptionFailingMigrationStep.THROWN_EXCEPTION); + } } private static RegisteredMigrationStep registeredStepOf(int migrationNumber, Class<? extends MigrationStep> migrationStep1Class) { diff --git a/server/sonar-process-monitor/pom.xml b/server/sonar-process-monitor/pom.xml index 884022fa636..8a065325ba2 100644 --- a/server/sonar-process-monitor/pom.xml +++ b/server/sonar-process-monitor/pom.xml @@ -45,8 +45,18 @@ </dependency> <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>sonar-testing-harness</artifactId> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> <dependency> diff --git a/server/sonar-process/pom.xml b/server/sonar-process/pom.xml index 96d9b3c04ca..41ed5df2020 100644 --- a/server/sonar-process/pom.xml +++ b/server/sonar-process/pom.xml @@ -51,6 +51,16 @@ </dependency> <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.tngtech.java</groupId> + <artifactId>junit-dataprovider</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>sonar-testing-harness</artifactId> <scope>test</scope> diff --git a/server/sonar-process/src/test/java/org/sonar/process/EncryptionTest.java b/server/sonar-process/src/test/java/org/sonar/process/EncryptionTest.java index 99b4876520d..ca1086466e3 100644 --- a/server/sonar-process/src/test/java/org/sonar/process/EncryptionTest.java +++ b/server/sonar-process/src/test/java/org/sonar/process/EncryptionTest.java @@ -21,38 +21,38 @@ package org.sonar.process; import org.junit.Test; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; + public class EncryptionTest { @Test public void isEncrypted() { Encryption encryption = new Encryption(null); - assertThat(encryption.isEncrypted("{aes}ADASDASAD"), is(true)); - assertThat(encryption.isEncrypted("{b64}ADASDASAD"), is(true)); - assertThat(encryption.isEncrypted("{abc}ADASDASAD"), is(true)); + assertThat(encryption.isEncrypted("{aes}ADASDASAD")).isTrue(); + assertThat(encryption.isEncrypted("{b64}ADASDASAD")).isTrue(); + assertThat(encryption.isEncrypted("{abc}ADASDASAD")).isTrue(); - assertThat(encryption.isEncrypted("{}"), is(false)); - assertThat(encryption.isEncrypted("{foo"), is(false)); - assertThat(encryption.isEncrypted("foo{aes}"), is(false)); + assertThat(encryption.isEncrypted("{}")).isFalse(); + assertThat(encryption.isEncrypted("{foo")).isFalse(); + assertThat(encryption.isEncrypted("foo{aes}")).isFalse(); } @Test public void decrypt() { Encryption encryption = new Encryption(null); - assertThat(encryption.decrypt("{b64}Zm9v"), is("foo")); + assertThat(encryption.decrypt("{b64}Zm9v")).isEqualTo("foo"); } @Test public void decrypt_unknown_algorithm() { Encryption encryption = new Encryption(null); - assertThat(encryption.decrypt("{xxx}Zm9v"), is("{xxx}Zm9v")); + assertThat(encryption.decrypt("{xxx}Zm9v")).isEqualTo("{xxx}Zm9v"); } @Test public void decrypt_uncrypted_text() { Encryption encryption = new Encryption(null); - assertThat(encryption.decrypt("foo"), is("foo")); + assertThat(encryption.decrypt("foo")).isEqualTo("foo"); } } diff --git a/server/sonar-search/pom.xml b/server/sonar-search/pom.xml index 37e176b293f..3b633757f20 100644 --- a/server/sonar-search/pom.xml +++ b/server/sonar-search/pom.xml @@ -54,8 +54,13 @@ <scope>test</scope> </dependency> <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>sonar-testing-harness</artifactId> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/server/sonar-server/pom.xml b/server/sonar-server/pom.xml index 69f66f0a1c7..bb1b64f3053 100644 --- a/server/sonar-server/pom.xml +++ b/server/sonar-server/pom.xml @@ -187,6 +187,32 @@ <!-- unit tests --> <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-guava</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <!-- TODO to be removed --> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-all</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>sonar-db-testing</artifactId> <type>pom</type> @@ -203,6 +229,11 @@ <scope>test</scope> </dependency> <dependency> + <groupId>com.tngtech.java</groupId> + <artifactId>junit-dataprovider</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>com.github.kevinsawicki</groupId> <artifactId>http-request</artifactId> <scope>test</scope> diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationChannelTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationChannelTest.java index d1f466711ec..6e426d7042c 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationChannelTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationChannelTest.java @@ -19,23 +19,22 @@ */ package org.sonar.server.notification; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; - import org.junit.Test; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; +import static org.assertj.core.api.Assertions.assertThat; + public class NotificationChannelTest { @Test public void defaultMethods() { NotificationChannel channel = new FakeNotificationChannel(); - assertThat(channel.getKey(), is("FakeNotificationChannel")); - assertThat(channel.toString(), is("FakeNotificationChannel")); + assertThat(channel.getKey()).isEqualTo("FakeNotificationChannel"); + assertThat(channel.toString()).isEqualTo("FakeNotificationChannel"); } - class FakeNotificationChannel extends NotificationChannel { + private class FakeNotificationChannel extends NotificationChannel { @Override public void deliver(Notification notification, String username) { } diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/CompatibilityRealmTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/CompatibilityRealmTest.java index eb8ed87820b..95f0dc4e54d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/CompatibilityRealmTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/CompatibilityRealmTest.java @@ -22,8 +22,7 @@ package org.sonar.server.user; import org.junit.Test; import org.sonar.api.security.LoginPasswordAuthenticator; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -35,8 +34,8 @@ public class CompatibilityRealmTest { CompatibilityRealm realm = new CompatibilityRealm(authenticator); realm.init(); verify(authenticator).init(); - assertThat(realm.getLoginPasswordAuthenticator(), is(authenticator)); - assertThat(realm.getName(), is("CompatibilityRealm[" + authenticator.getClass().getName() + "]")); + assertThat(realm.getLoginPasswordAuthenticator()).isSameAs(authenticator); + assertThat(realm.getName()).isEqualTo("CompatibilityRealm[" + authenticator.getClass().getName() + "]"); } } diff --git a/sonar-application/pom.xml b/sonar-application/pom.xml index 30c86e48d1a..24965e8cd3b 100644 --- a/sonar-application/pom.xml +++ b/sonar-application/pom.xml @@ -154,18 +154,18 @@ <!-- unit tests --> <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>sonar-testing-harness</artifactId> + <groupId>junit</groupId> + <artifactId>junit</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> <scope>test</scope> </dependency> <dependency> - <groupId>com.github.kevinsawicki</groupId> - <artifactId>http-request</artifactId> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/sonar-core/pom.xml b/sonar-core/pom.xml index 7f7f817bd5a..81b868c6576 100644 --- a/sonar-core/pom.xml +++ b/sonar-core/pom.xml @@ -82,6 +82,26 @@ <!-- tests --> <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.tngtech.java</groupId> + <artifactId>junit-dataprovider</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>sonar-testing-harness</artifactId> <scope>test</scope> diff --git a/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java b/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java index 65319c55858..c30ab6bf991 100644 --- a/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java +++ b/sonar-core/src/test/java/org/sonar/core/i18n/RuleI18nManagerTest.java @@ -20,12 +20,9 @@ package org.sonar.core.i18n; import java.util.Locale; -import org.hamcrest.core.Is; import org.junit.Test; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; @@ -67,7 +64,7 @@ public class RuleI18nManagerTest { RuleI18nManager ruleI18n = new RuleI18nManager(i18n); String description = ruleI18n.getDescription("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck", Locale.ENGLISH); - assertThat(description, is("Description")); + assertThat(description).isEqualTo("Description"); verify(i18n).messageFromFile(Locale.ENGLISH, "rules/checkstyle/com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.html", propertyKeyForName); verifyNoMoreInteractions(i18n); @@ -84,7 +81,7 @@ public class RuleI18nManagerTest { RuleI18nManager ruleI18n = new RuleI18nManager(i18n); String description = ruleI18n.getDescription("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck", Locale.ENGLISH); - assertThat(description, is("Description")); + assertThat(description).isEqualTo("Description"); verify(i18n).messageFromFile(Locale.ENGLISH, "rules/checkstyle/com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.html", propertyKeyForName); verify(i18n).messageFromFile(Locale.ENGLISH, "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.html", propertyKeyForName); @@ -96,21 +93,21 @@ public class RuleI18nManagerTest { DefaultI18n i18n = mock(DefaultI18n.class); RuleI18nManager ruleI18n = new RuleI18nManager(i18n); - assertThat(ruleI18n.getDescription("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck", Locale.ENGLISH), nullValue()); + assertThat(ruleI18n.getDescription("checkstyle", "com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck", Locale.ENGLISH)).isNull(); } @Test public void shouldBeRuleKey() { - assertThat(RuleI18nManager.isRuleProperty("rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name"), Is.is(true)); - assertThat(RuleI18nManager.isRuleProperty("rule.pmd.Header.name"), Is.is(true)); + assertThat(RuleI18nManager.isRuleProperty("rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.name")).isTrue(); + assertThat(RuleI18nManager.isRuleProperty("rule.pmd.Header.name")).isTrue(); } @Test public void shouldNotBeRuleKey() { // this is the parameter "name" - assertThat(RuleI18nManager.isRuleProperty("rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.param.name"), Is.is(false)); - assertThat(RuleI18nManager.isRuleProperty("by"), Is.is(false)); - assertThat(RuleI18nManager.isRuleProperty("something.else"), Is.is(false)); - assertThat(RuleI18nManager.isRuleProperty("checkstyle.page.name"), Is.is(false)); + assertThat(RuleI18nManager.isRuleProperty("rule.checkstyle.com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck.param.name")).isFalse(); + assertThat(RuleI18nManager.isRuleProperty("by")).isFalse(); + assertThat(RuleI18nManager.isRuleProperty("something.else")).isFalse(); + assertThat(RuleI18nManager.isRuleProperty("checkstyle.page.name")).isFalse(); } } diff --git a/sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java b/sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java index 73230684be1..d15ae533cf6 100644 --- a/sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/stream/CollectorsTest.java @@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -39,7 +40,6 @@ import org.junit.rules.ExpectedException; import static java.util.function.Function.identity; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; -import static org.assertj.guava.api.Assertions.assertThat; import static org.sonar.core.util.stream.Collectors.index; import static org.sonar.core.util.stream.Collectors.join; import static org.sonar.core.util.stream.Collectors.toArrayList; @@ -343,8 +343,8 @@ public class CollectorsTest { @Test public void index_empty_stream_returns_empty_map() { - assertThat(Collections.<MyObj>emptyList().stream().collect(index(MyObj::getId))).isEmpty(); - assertThat(Collections.<MyObj>emptyList().stream().collect(index(MyObj::getId, MyObj::getText))).isEmpty(); + assertThat(Collections.<MyObj>emptyList().stream().collect(index(MyObj::getId)).size()).isEqualTo(0); + assertThat(Collections.<MyObj>emptyList().stream().collect(index(MyObj::getId, MyObj::getText)).size()).isEqualTo(0); } @Test @@ -414,16 +414,22 @@ public class CollectorsTest { public void index_returns_multimap() { Multimap<Integer, MyObj> multimap = LIST.stream().collect(index(MyObj::getId)); - assertThat(multimap).hasSize(3); - assertThat(multimap).contains(entry(1, MY_OBJ_1_A), entry(2, MY_OBJ_2_B), entry(3, MY_OBJ_3_C)); + assertThat(multimap.size()).isEqualTo(3); + Map<Integer, Collection<MyObj>> map = multimap.asMap(); + assertThat(map.get(1)).containsOnly(MY_OBJ_1_A); + assertThat(map.get(2)).containsOnly(MY_OBJ_2_B); + assertThat(map.get(3)).containsOnly(MY_OBJ_3_C); } @Test public void index_with_valueFunction_returns_multimap() { Multimap<Integer, String> multimap = LIST.stream().collect(index(MyObj::getId, MyObj::getText)); - assertThat(multimap).hasSize(3); - assertThat(multimap).contains(entry(1, "A"), entry(2, "B"), entry(3, "C")); + assertThat(multimap.size()).isEqualTo(3); + Map<Integer, Collection<String>> map = multimap.asMap(); + assertThat(map.get(1)).containsOnly("A"); + assertThat(map.get(2)).containsOnly("B"); + assertThat(map.get(3)).containsOnly("C"); } @Test diff --git a/sonar-markdown/pom.xml b/sonar-markdown/pom.xml index 32847c94671..f4efd8ce9aa 100644 --- a/sonar-markdown/pom.xml +++ b/sonar-markdown/pom.xml @@ -31,8 +31,13 @@ <scope>test</scope> </dependency> <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>sonar-testing-harness</artifactId> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> <scope>test</scope> </dependency> </dependencies> diff --git a/sonar-plugin-api/pom.xml b/sonar-plugin-api/pom.xml index 5d03eee3eed..ee8f9a32bca 100644 --- a/sonar-plugin-api/pom.xml +++ b/sonar-plugin-api/pom.xml @@ -153,6 +153,21 @@ <!-- unit tests --> <dependency> + <groupId>com.tngtech.java</groupId> + <artifactId>junit-dataprovider</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>sonar-testing-harness</artifactId> <scope>test</scope> @@ -162,11 +177,6 @@ <artifactId>xmlunit</artifactId> <scope>test</scope> </dependency> - <dependency> - <groupId>org.dbunit</groupId> - <artifactId>dbunit</artifactId> - <scope>test</scope> - </dependency> </dependencies> <build> diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectReactorTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectReactorTest.java index 59dc089097e..f53b24b6368 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectReactorTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/bootstrap/ProjectReactorTest.java @@ -21,8 +21,7 @@ package org.sonar.api.batch.bootstrap; import org.junit.Test; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class ProjectReactorTest { @@ -33,8 +32,8 @@ public class ProjectReactorTest { root.addSubProject(child); ProjectReactor reactor = new ProjectReactor(root); - assertThat(reactor.getProjects().size(), is(2)); - assertThat(reactor.getRoot(), is(root)); + assertThat(reactor.getProjects()).hasSize(2); + assertThat(reactor.getRoot()).isSameAs(root); } @Test(expected = IllegalArgumentException.class) diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java index 0c88bcbe30b..7af64f93cbc 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/AesCipherTest.java @@ -21,7 +21,6 @@ package org.sonar.api.config; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang.StringUtils; -import org.hamcrest.Matchers; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -33,10 +32,7 @@ import java.net.URL; import java.security.InvalidKeyException; import java.security.Key; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; public class AesCipherTest { @@ -50,8 +46,8 @@ public class AesCipherTest { String key = cipher.generateRandomSecretKey(); - assertThat(StringUtils.isNotBlank(key), is(true)); - assertThat(Base64.isArrayByteBase64(key.getBytes()), is(true)); + assertThat(StringUtils.isNotBlank(key)).isTrue(); + assertThat(Base64.isArrayByteBase64(key.getBytes())).isTrue(); } @Test @@ -60,8 +56,8 @@ public class AesCipherTest { String encryptedText = cipher.encrypt("this is a secret"); - assertThat(StringUtils.isNotBlank(encryptedText), is(true)); - assertThat(Base64.isArrayByteBase64(encryptedText.getBytes()), is(true)); + assertThat(StringUtils.isNotBlank(encryptedText)).isTrue(); + assertThat(Base64.isArrayByteBase64(encryptedText.getBytes())).isTrue(); } @Test @@ -82,7 +78,7 @@ public class AesCipherTest { // the following value has been encrypted with the key /org/sonar/api/config/AesCipherTest/aes_secret_key.txt String clearText = cipher.decrypt("9mx5Zq4JVyjeChTcVjEide4kWCwusFl7P2dSVXtg9IY="); - assertThat(clearText, is("this is a secret")); + assertThat(clearText).isEqualTo("this is a secret"); } @Test @@ -95,7 +91,7 @@ public class AesCipherTest { fail(); } catch (RuntimeException e) { - assertThat(e.getCause(), instanceOf(InvalidKeyException.class)); + assertThat(e.getCause()).isInstanceOf(InvalidKeyException.class); } } @@ -110,7 +106,7 @@ public class AesCipherTest { fail(); } catch (RuntimeException e) { - assertThat(e.getCause(), instanceOf(BadPaddingException.class)); + assertThat(e.getCause()).isInstanceOf(BadPaddingException.class); } } @@ -118,7 +114,7 @@ public class AesCipherTest { public void encryptThenDecrypt() throws Exception { AesCipher cipher = new AesCipher(pathToSecretKey()); - assertThat(cipher.decrypt(cipher.encrypt("foo")), is("foo")); + assertThat(cipher.decrypt(cipher.encrypt("foo"))).isEqualTo("foo"); } @Test @@ -127,16 +123,16 @@ public class AesCipherTest { String path = cipher.getPathToSecretKey(); - assertThat(StringUtils.isNotBlank(path), is(true)); - assertThat(new File(path).getName(), is("sonar-secret.txt")); + assertThat(StringUtils.isNotBlank(path)).isTrue(); + assertThat(new File(path).getName()).isEqualTo("sonar-secret.txt"); } @Test public void loadSecretKeyFromFile() throws Exception { AesCipher cipher = new AesCipher(null); Key secretKey = cipher.loadSecretFileFromFile(pathToSecretKey()); - assertThat(secretKey.getAlgorithm(), is("AES")); - assertThat(secretKey.getEncoded().length, greaterThan(10)); + assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); + assertThat(secretKey.getEncoded().length).isGreaterThan(10); } @Test @@ -147,8 +143,8 @@ public class AesCipherTest { Key secretKey = cipher.loadSecretFileFromFile(path); - assertThat(secretKey.getAlgorithm(), is("AES")); - assertThat(secretKey.getEncoded().length, greaterThan(10)); + assertThat(secretKey.getAlgorithm()).isEqualTo("AES"); + assertThat(secretKey.getEncoded().length).isGreaterThan(10); } @Test @@ -171,14 +167,14 @@ public class AesCipherTest { public void hasSecretKey() throws Exception { AesCipher cipher = new AesCipher(pathToSecretKey()); - assertThat(cipher.hasSecretKey(), Matchers.is(true)); + assertThat(cipher.hasSecretKey()).isTrue(); } @Test public void doesNotHaveSecretKey() { AesCipher cipher = new AesCipher("/my/twitter/id/is/SimonBrandhof"); - assertThat(cipher.hasSecretKey(), Matchers.is(false)); + assertThat(cipher.hasSecretKey()).isFalse(); } private String pathToSecretKey() throws Exception { diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/EncryptionTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/EncryptionTest.java index 9f94f8fc6cb..feb2f97c942 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/EncryptionTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/EncryptionTest.java @@ -21,44 +21,43 @@ package org.sonar.api.config; import org.junit.Test; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class EncryptionTest { @Test public void isEncrypted() { Encryption encryption = new Encryption(null); - assertThat(encryption.isEncrypted("{aes}ADASDASAD"), is(true)); - assertThat(encryption.isEncrypted("{b64}ADASDASAD"), is(true)); - assertThat(encryption.isEncrypted("{abc}ADASDASAD"), is(true)); + assertThat(encryption.isEncrypted("{aes}ADASDASAD")).isTrue(); + assertThat(encryption.isEncrypted("{b64}ADASDASAD")).isTrue(); + assertThat(encryption.isEncrypted("{abc}ADASDASAD")).isTrue(); - assertThat(encryption.isEncrypted("{}"), is(false)); - assertThat(encryption.isEncrypted("{foo"), is(false)); - assertThat(encryption.isEncrypted("foo{aes}"), is(false)); + assertThat(encryption.isEncrypted("{}")).isFalse(); + assertThat(encryption.isEncrypted("{foo")).isFalse(); + assertThat(encryption.isEncrypted("foo{aes}")).isFalse(); } @Test public void scramble() { Encryption encryption = new Encryption(null); - assertThat(encryption.scramble("foo"), is("{b64}Zm9v")); + assertThat(encryption.scramble("foo")).isEqualTo("{b64}Zm9v"); } @Test public void decrypt() { Encryption encryption = new Encryption(null); - assertThat(encryption.decrypt("{b64}Zm9v"), is("foo")); + assertThat(encryption.decrypt("{b64}Zm9v")).isEqualTo("foo"); } @Test public void decrypt_unknown_algorithm() { Encryption encryption = new Encryption(null); - assertThat(encryption.decrypt("{xxx}Zm9v"), is("{xxx}Zm9v")); + assertThat(encryption.decrypt("{xxx}Zm9v")).isEqualTo("{xxx}Zm9v"); } @Test public void decrypt_uncrypted_text() { Encryption encryption = new Encryption(null); - assertThat(encryption.decrypt("foo"), is("foo")); + assertThat(encryption.decrypt("foo")).isEqualTo("foo"); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/CountDistributionBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/CountDistributionBuilderTest.java index baed14aeb51..86bb8f19943 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/CountDistributionBuilderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/CountDistributionBuilderTest.java @@ -21,8 +21,7 @@ package org.sonar.api.measures; import org.junit.Test; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -31,26 +30,26 @@ public class CountDistributionBuilderTest { public void buildDistribution() { CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION); Measure measure = builder - .add("foo") - .add("bar") - .add("foo") - .add("hello") - .build(); + .add("foo") + .add("bar") + .add("foo") + .add("hello") + .build(); - assertThat(measure.getData(), is("bar=1;foo=2;hello=1")); + assertThat(measure.getData()).isEqualTo("bar=1;foo=2;hello=1"); } @Test public void addZeroValues() { CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION); Measure measure = builder - .addZero("foo") - .add("bar") - .add("foo") - .addZero("hello") - .build(); + .addZero("foo") + .add("bar") + .add("foo") + .addZero("hello") + .build(); - assertThat(measure.getData(), is("bar=1;foo=1;hello=0")); + assertThat(measure.getData()).isEqualTo("bar=1;foo=1;hello=0"); } @Test @@ -60,12 +59,12 @@ public class CountDistributionBuilderTest { CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION); Measure measure = builder - .add("bar") - .add("foo") - .add(measureToAdd) - .build(); + .add("bar") + .add("foo") + .add(measureToAdd) + .build(); - assertThat(measure.getData(), is("bar=1;foo=4;hello=5;none=0")); + assertThat(measure.getData()).isEqualTo("bar=1;foo=4;hello=5;none=0"); } @Test @@ -75,12 +74,12 @@ public class CountDistributionBuilderTest { CountDistributionBuilder builder = new CountDistributionBuilder(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION); Measure measure = builder - .add(10) - .add(measureToAdd) - .add(1) - .build(); + .add(10) + .add(measureToAdd) + .add(1) + .build(); - assertThat(measure.getData(), is("1=4;3=2;10=6")); + assertThat(measure.getData()).isEqualTo("1=4;3=2;10=6"); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/MeasureUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/MeasureUtilsTest.java index d92ce7503f8..9a999743cd4 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/MeasureUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/MeasureUtilsTest.java @@ -19,98 +19,94 @@ */ package org.sonar.api.measures; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; - import java.util.Arrays; import java.util.Collection; import java.util.List; - import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class MeasureUtilsTest { @Test public void getValue() { - assertThat(MeasureUtils.getValue(null, 3.0), is(3.0)); - assertThat(MeasureUtils.getValue(new Measure(), 3.0), is(3.0)); - assertThat(MeasureUtils.getValue(new Measure(CoreMetrics.LINES, 2.0), 3.0), is(2.0)); - assertThat(MeasureUtils.getValue(new Measure(CoreMetrics.LINES, "data"), 3.0), is(3.0)); + assertThat(MeasureUtils.getValue(null, 3.0)).isEqualTo(3.0); + assertThat(MeasureUtils.getValue(new Measure(), 3.0)).isEqualTo(3.0); + assertThat(MeasureUtils.getValue(new Measure(CoreMetrics.LINES, 2.0), 3.0)).isEqualTo(2.0); + assertThat(MeasureUtils.getValue(new Measure(CoreMetrics.LINES, "data"), 3.0)).isEqualTo(3.0); } @Test public void sumNone() { - assertThat(MeasureUtils.sum(true), is(0d)); - assertNull(MeasureUtils.sum(false)); + assertThat(MeasureUtils.sum(true)).isEqualTo(0d); + assertThat(MeasureUtils.sum(false)).isNull(); } @Test public void shouldNotFailIfDataMeasures() { - assertThat(MeasureUtils.sum(true, new Measure(CoreMetrics.ALERT_STATUS, "foo"), new Measure(CoreMetrics.LINES, 50.0)), is(50d)); + assertThat(MeasureUtils.sum(true, new Measure(CoreMetrics.ALERT_STATUS, "foo"), new Measure(CoreMetrics.LINES, 50.0))).isEqualTo(50d); } @Test public void sumNumericMeasures() { - assertThat(MeasureUtils.sum(true, new Measure(CoreMetrics.LINES, 80.0), new Measure(CoreMetrics.LINES, 50.0)), is(130d)); - assertThat(MeasureUtils.sum(true, Arrays.asList(new Measure(CoreMetrics.LINES, 80.0), new Measure(CoreMetrics.LINES, 50.0))), is(130d)); + assertThat(MeasureUtils.sum(true, new Measure(CoreMetrics.LINES, 80.0), new Measure(CoreMetrics.LINES, 50.0))).isEqualTo(130d); + assertThat(MeasureUtils.sum(true, Arrays.asList(new Measure(CoreMetrics.LINES, 80.0), new Measure(CoreMetrics.LINES, 50.0)))).isEqualTo(130d); } @Test public void sumNullMeasures() { - assertThat(MeasureUtils.sum(true), is(0.0)); - assertThat(MeasureUtils.sum(true, (Collection<Measure>) null), is(0.0)); - assertThat(MeasureUtils.sum(false), nullValue()); - assertThat(MeasureUtils.sum(true, new Measure(CoreMetrics.LINES, 80.0), null, null, new Measure(CoreMetrics.LINES, 50.0)), is(130d)); + assertThat(MeasureUtils.sum(true)).isEqualTo(0.0); + assertThat(MeasureUtils.sum(true, (Collection<Measure>) null)).isEqualTo(0.0); + assertThat(MeasureUtils.sum(false)).isNull(); + assertThat(MeasureUtils.sum(true, new Measure(CoreMetrics.LINES, 80.0), null, null, new Measure(CoreMetrics.LINES, 50.0))).isEqualTo(130d); } @Test public void hasValue() { - assertThat(MeasureUtils.hasValue(null), is(false)); - assertThat(MeasureUtils.hasValue(new Measure(CoreMetrics.CLASSES, (Double) null)), is(false)); - assertThat(MeasureUtils.hasValue(new Measure(CoreMetrics.CLASSES, 3.2)), is(true)); + assertThat(MeasureUtils.hasValue(null)).isFalse(); + assertThat(MeasureUtils.hasValue(new Measure(CoreMetrics.CLASSES, (Double) null))).isFalse(); + assertThat(MeasureUtils.hasValue(new Measure(CoreMetrics.CLASSES, 3.2))).isTrue(); } @Test public void hasData() { - assertThat(MeasureUtils.hasData(null), is(false)); - assertThat(MeasureUtils.hasData(new Measure(CoreMetrics.CLASSES, 3.5)), is(false)); - assertThat(MeasureUtils.hasData(new Measure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, (String) null)), is(false)); - assertThat(MeasureUtils.hasData(new Measure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, "")), is(false)); - assertThat(MeasureUtils.hasData(new Measure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, "1=10;2=20")), is(true)); + assertThat(MeasureUtils.hasData(null)).isFalse(); + assertThat(MeasureUtils.hasData(new Measure(CoreMetrics.CLASSES, 3.5))).isFalse(); + assertThat(MeasureUtils.hasData(new Measure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, (String) null))).isFalse(); + assertThat(MeasureUtils.hasData(new Measure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, ""))).isFalse(); + assertThat(MeasureUtils.hasData(new Measure(CoreMetrics.FUNCTION_COMPLEXITY_DISTRIBUTION, "1=10;2=20"))).isTrue(); } @Test public void shouldHaveValues() { - assertThat(MeasureUtils.haveValues(), is(false)); - assertThat(MeasureUtils.haveValues(null, null), is(false)); - assertThat(MeasureUtils.haveValues(new Measure(CoreMetrics.CLASSES, (Double) null)), is(false)); - assertThat(MeasureUtils.haveValues(new Measure(CoreMetrics.CLASSES, 3.2)), is(true)); - assertThat(MeasureUtils.haveValues(new Measure(CoreMetrics.CLASSES, 3.2), new Measure(CoreMetrics.COMPLEXITY, "foo")), is(false)); - assertThat(MeasureUtils.haveValues(new Measure(CoreMetrics.CLASSES, 3.2), new Measure(CoreMetrics.COMPLEXITY, 2.5)), is(true)); + assertThat(MeasureUtils.haveValues()).isFalse(); + assertThat(MeasureUtils.haveValues(null, null)).isFalse(); + assertThat(MeasureUtils.haveValues(new Measure(CoreMetrics.CLASSES, (Double) null))).isFalse(); + assertThat(MeasureUtils.haveValues(new Measure(CoreMetrics.CLASSES, 3.2))).isTrue(); + assertThat(MeasureUtils.haveValues(new Measure(CoreMetrics.CLASSES, 3.2), new Measure(CoreMetrics.COMPLEXITY, "foo"))).isFalse(); + assertThat(MeasureUtils.haveValues(new Measure(CoreMetrics.CLASSES, 3.2), new Measure(CoreMetrics.COMPLEXITY, 2.5))).isTrue(); } @Test public void shouldGetVariation() { - assertThat(MeasureUtils.getVariation(null, 2, 3.14), is(3.14)); - assertThat(MeasureUtils.getVariation(null, 2), nullValue()); + assertThat(MeasureUtils.getVariation(null, 2, 3.14)).isEqualTo(3.14); + assertThat(MeasureUtils.getVariation(null, 2)).isNull(); - assertThat(MeasureUtils.getVariation(new Measure(), 2, 3.14), is(3.14)); - assertThat(MeasureUtils.getVariation(new Measure(), 2), nullValue()); + assertThat(MeasureUtils.getVariation(new Measure(), 2, 3.14)).isEqualTo(3.14); + assertThat(MeasureUtils.getVariation(new Measure(), 2)).isNull(); - assertThat(MeasureUtils.getVariation(new Measure().setVariation2(1.618), 2, 3.14), is(1.618)); + assertThat(MeasureUtils.getVariation(new Measure().setVariation2(1.618), 2, 3.14)).isEqualTo(1.618); } @Test public void shouldGetVariationAsLong() { - assertThat(MeasureUtils.getVariationAsLong(null, 2, 3L), is(3L)); - assertThat(MeasureUtils.getVariationAsLong(null, 2), nullValue()); + assertThat(MeasureUtils.getVariationAsLong(null, 2, 3L)).isEqualTo(3L); + assertThat(MeasureUtils.getVariationAsLong(null, 2)).isNull(); - assertThat(MeasureUtils.getVariationAsLong(new Measure(), 2, 3L), is(3L)); - assertThat(MeasureUtils.getVariationAsLong(new Measure(), 2), nullValue()); + assertThat(MeasureUtils.getVariationAsLong(new Measure(), 2, 3L)).isEqualTo(3L); + assertThat(MeasureUtils.getVariationAsLong(new Measure(), 2)).isNull(); - assertThat(MeasureUtils.getVariationAsLong(new Measure().setVariation2(222.0), 2, 3L), is(222L)); + assertThat(MeasureUtils.getVariationAsLong(new Measure().setVariation2(222.0), 2, 3L)).isEqualTo(222L); } @Test @@ -119,9 +115,9 @@ public class MeasureUtilsTest { Measure measure2 = new Measure(CoreMetrics.NEW_VIOLATIONS).setVariation1(1.0).setVariation2(2.0).setVariation3(3.0); List<Measure> children = Arrays.asList(measure1, measure2); - assertThat(MeasureUtils.sumOnVariation(true, 1, children), is(2d)); - assertThat(MeasureUtils.sumOnVariation(true, 2, children), is(3d)); - assertThat(MeasureUtils.sumOnVariation(true, 3, children), is(6d)); + assertThat(MeasureUtils.sumOnVariation(true, 1, children)).isEqualTo(2d); + assertThat(MeasureUtils.sumOnVariation(true, 2, children)).isEqualTo(3d); + assertThat(MeasureUtils.sumOnVariation(true, 3, children)).isEqualTo(6d); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/PersistenceModeTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/PersistenceModeTest.java index 9fe10030e25..acd894cfed4 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/PersistenceModeTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/PersistenceModeTest.java @@ -19,23 +19,23 @@ */ package org.sonar.api.measures; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class PersistenceModeTest { @Test public void useMemory() { - assertThat(PersistenceMode.MEMORY.useMemory(), is(true)); - assertThat(PersistenceMode.DATABASE.useMemory(), is(false)); - assertThat(PersistenceMode.FULL.useMemory(), is(true)); + assertThat(PersistenceMode.MEMORY.useMemory()).isTrue(); + assertThat(PersistenceMode.DATABASE.useMemory()).isFalse(); + assertThat(PersistenceMode.FULL.useMemory()).isTrue(); } @Test public void useDatabase() { - assertThat(PersistenceMode.MEMORY.useDatabase(), is(false)); - assertThat(PersistenceMode.DATABASE.useDatabase(), is(true)); - assertThat(PersistenceMode.FULL.useDatabase(), is(true)); + assertThat(PersistenceMode.MEMORY.useDatabase()).isFalse(); + assertThat(PersistenceMode.DATABASE.useDatabase()).isTrue(); + assertThat(PersistenceMode.FULL.useDatabase()).isTrue(); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/measures/PropertiesBuilderTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/measures/PropertiesBuilderTest.java index c827c4b47a7..89c57127bf2 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/measures/PropertiesBuilderTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/measures/PropertiesBuilderTest.java @@ -19,64 +19,59 @@ */ package org.sonar.api.measures; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class PropertiesBuilderTest { @Test public void buildMeasure() { PropertiesBuilder<Integer, Integer> builder = new PropertiesBuilder<>(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION); Measure measure = builder - .add(1, 30) - .add(2, 27) - .add(4, 50) - .build(); - assertNotNull(measure); - assertThat(measure.getData(), is("1=30;2=27;4=50")); + .add(1, 30) + .add(2, 27) + .add(4, 50) + .build(); + assertThat(measure.getData()).isEqualTo("1=30;2=27;4=50"); } @Test public void sortKeys() { PropertiesBuilder<String, String> builder = new PropertiesBuilder<>(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION); Measure measure = builder - .add("foo", "fooooo") - .add("bar", "baaaaar") - .add("hello", "world") - .build(); - assertNotNull(measure); - assertThat(measure.getData(), is("bar=baaaaar;foo=fooooo;hello=world")); + .add("foo", "fooooo") + .add("bar", "baaaaar") + .add("hello", "world") + .build(); + assertThat(measure.getData()).isEqualTo("bar=baaaaar;foo=fooooo;hello=world"); } @Test public void valueIsOptional() { PropertiesBuilder<String, String> builder = new PropertiesBuilder<>(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION); Measure measure = builder - .add("foo", null) - .add("bar", "bar") - .add("hello", "world") - .build(); - assertNotNull(measure); - assertThat(measure.getData(), is("bar=bar;foo=;hello=world")); + .add("foo", null) + .add("bar", "bar") + .add("hello", "world") + .build(); + assertThat(measure.getData()).isEqualTo("bar=bar;foo=;hello=world"); } @Test public void clearBeforeBuildingOtherMeasure() { PropertiesBuilder<String, String> builder = new PropertiesBuilder<>(CoreMetrics.CLASS_COMPLEXITY_DISTRIBUTION); builder - .add("foo", "foo") - .add("bar", "bar") - .add("hello", "world") - .build(); + .add("foo", "foo") + .add("bar", "bar") + .add("hello", "world") + .build(); builder.clear(); Measure measure = builder - .add("1", "1") - .add("2", "2") - .add("foo", "other") - .build(); - assertNotNull(measure); - assertThat(measure.getData(), is("1=1;2=2;foo=other")); + .add("1", "1") + .add("2", "2") + .add("foo", "other") + .build(); + assertThat(measure.getData()).isEqualTo("1=1;2=2;foo=other"); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java index 45fac83881d..72b8d761132 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/profiles/AnnotationProfileParserTest.java @@ -30,10 +30,7 @@ import org.sonar.api.utils.ValidationMessages; import org.sonar.check.BelongsToProfile; import org.sonar.check.Priority; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -50,12 +47,12 @@ public class AnnotationProfileParserTest { }); ValidationMessages messages = ValidationMessages.create(); - RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class> newArrayList(FakeRule.class), messages); + RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class), messages); - assertThat(profile.getName(), is("Foo way")); - assertThat(profile.getLanguage(), is("java")); - assertThat(profile.getActiveRule("squid", "fake").getSeverity(), is(RulePriority.BLOCKER)); - assertThat(messages.hasErrors(), is(false)); + assertThat(profile.getName()).isEqualTo("Foo way"); + assertThat(profile.getLanguage()).isEqualTo("java"); + assertThat(profile.getActiveRule("squid", "fake").getSeverity()).isEqualTo(RulePriority.BLOCKER); + assertThat(messages.hasErrors()).isFalse(); } @Test @@ -68,10 +65,10 @@ public class AnnotationProfileParserTest { }); ValidationMessages messages = ValidationMessages.create(); - RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class> newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages); + RulesProfile profile = new AnnotationProfileParser(ruleFinder).parse("squid", "Foo way", "java", Lists.<Class>newArrayList(FakeRule.class, RuleOnOtherProfile.class), messages); - assertNotNull(profile.getActiveRule("squid", "fake")); - assertNull(profile.getActiveRule("squid", "other")); + assertThat(profile.getActiveRule("squid", "fake")).isNotNull(); + assertThat(profile.getActiveRule("squid", "other")).isNull(); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/QualifiersTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/QualifiersTest.java index 250ec56468e..112d1818408 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/QualifiersTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/QualifiersTest.java @@ -22,27 +22,26 @@ package org.sonar.api.resources; import org.junit.Test; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class QualifiersTest { @Test public void testRootView() { View root = View.createRootView(); - assertThat(Qualifiers.isView(root, true), is(true)); - assertThat(Qualifiers.isView(root, false), is(true)); - assertThat(Qualifiers.isProject(root, true), is(false)); - assertThat(Qualifiers.isProject(root, false), is(false)); + assertThat(Qualifiers.isView(root, true)).isTrue(); + assertThat(Qualifiers.isView(root, false)).isTrue(); + assertThat(Qualifiers.isProject(root, true)).isFalse(); + assertThat(Qualifiers.isProject(root, false)).isFalse(); } @Test public void testSubView() { View subview = View.createSubView(); - assertThat(Qualifiers.isView(subview, true), is(true)); - assertThat(Qualifiers.isView(subview, false), is(false)); - assertThat(Qualifiers.isProject(subview, true), is(false)); - assertThat(Qualifiers.isProject(subview, false), is(false)); + assertThat(Qualifiers.isView(subview, true)).isTrue(); + assertThat(Qualifiers.isView(subview, false)).isFalse(); + assertThat(Qualifiers.isProject(subview, true)).isFalse(); + assertThat(Qualifiers.isProject(subview, false)).isFalse(); } @Test @@ -51,10 +50,10 @@ public class QualifiersTest { ProjectDefinition moduleDef = ProjectDefinition.create(); rootDef.addSubProject(moduleDef); Resource root = new Project(rootDef); - assertThat(Qualifiers.isView(root, true), is(false)); - assertThat(Qualifiers.isView(root, false), is(false)); - assertThat(Qualifiers.isProject(root, true), is(true)); - assertThat(Qualifiers.isProject(root, false), is(true)); + assertThat(Qualifiers.isView(root, true)).isFalse(); + assertThat(Qualifiers.isView(root, false)).isFalse(); + assertThat(Qualifiers.isProject(root, true)).isTrue(); + assertThat(Qualifiers.isProject(root, false)).isTrue(); } @Test @@ -63,10 +62,10 @@ public class QualifiersTest { ProjectDefinition moduleDef = ProjectDefinition.create(); rootDef.addSubProject(moduleDef); Resource sub = new Project(moduleDef); - assertThat(Qualifiers.isView(sub, true), is(false)); - assertThat(Qualifiers.isView(sub, false), is(false)); - assertThat(Qualifiers.isProject(sub, true), is(true)); - assertThat(Qualifiers.isProject(sub, false), is(false)); + assertThat(Qualifiers.isView(sub, true)).isFalse(); + assertThat(Qualifiers.isView(sub, false)).isFalse(); + assertThat(Qualifiers.isProject(sub, true)).isTrue(); + assertThat(Qualifiers.isProject(sub, false)).isFalse(); } private static class View extends Resource { diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTreeTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTreeTest.java index bea44bfea68..e38a0257905 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTreeTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ResourceTypeTreeTest.java @@ -21,64 +21,59 @@ package org.sonar.api.resources; import org.junit.Test; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.sonar.api.resources.ResourceTypesTest.qualifiers; public class ResourceTypeTreeTest { private final ResourceTypeTree tree = ResourceTypeTree.builder() - .addType(ResourceType.builder("TRK").build()) - .addType(ResourceType.builder("DIR").build()) - .addType(ResourceType.builder("FIL").build()) - .addType(ResourceType.builder("UTS").build()) - .addRelations("TRK", "DIR") - .addRelations("DIR", "FIL") - .addRelations("DIR", "UTS") - .build(); + .addType(ResourceType.builder("TRK").build()) + .addType(ResourceType.builder("DIR").build()) + .addType(ResourceType.builder("FIL").build()) + .addType(ResourceType.builder("UTS").build()) + .addRelations("TRK", "DIR") + .addRelations("DIR", "FIL") + .addRelations("DIR", "UTS") + .build(); @Test public void getTypes() { - assertThat(tree.getTypes().size(), is(4)); - assertThat(qualifiers(tree.getTypes()), hasItems("TRK", "DIR", "FIL", "UTS")); + assertThat(tree.getTypes()).hasSize(4); + assertThat(qualifiers(tree.getTypes())).containsOnly("TRK", "DIR", "FIL", "UTS"); } @Test public void getChildren() { - assertThat(tree.getChildren("TRK").size(), is(1)); - assertThat(tree.getChildren("TRK"), hasItems("DIR")); + assertThat(tree.getChildren("TRK")).containsOnly("DIR"); - assertThat(tree.getChildren("DIR").size(), is(2)); - assertThat(tree.getChildren("DIR"), hasItems("FIL", "UTS")); + assertThat(tree.getChildren("DIR")).containsOnly("FIL", "UTS"); - assertThat(tree.getChildren("FIL").size(), is(0)); + assertThat(tree.getChildren("FIL")).isEmpty(); } @Test public void getRoot() { - assertThat(tree.getRootType(), is(ResourceType.builder("TRK").build())); + assertThat(tree.getRootType()).isEqualTo(ResourceType.builder("TRK").build()); } @Test public void getLeaves() { - assertThat(tree.getLeaves().size(), is(2)); - assertThat(tree.getLeaves(), hasItems("FIL", "UTS")); + assertThat(tree.getLeaves()).containsOnly("FIL", "UTS"); } @Test(expected = IllegalArgumentException.class) public void forbidNullRelation() { ResourceTypeTree.builder() - .addType(ResourceType.builder("TRK").build()) - .addType(ResourceType.builder("DIR").build()) - .addRelations("DIR" /* missing child */) - .build(); + .addType(ResourceType.builder("TRK").build()) + .addType(ResourceType.builder("DIR").build()) + .addRelations("DIR" /* missing child */) + .build(); } @Test(expected = IllegalArgumentException.class) public void forbidDuplicatedType() { ResourceTypeTree.builder() - .addType(ResourceType.builder("TRK").build()) - .addType(ResourceType.builder("TRK").build()) - .build(); + .addType(ResourceType.builder("TRK").build()) + .addType(ResourceType.builder("TRK").build()) + .build(); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java index ac934548de2..662781e95c6 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/resources/ScopesTest.java @@ -22,60 +22,59 @@ package org.sonar.api.resources; import org.junit.Test; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class ScopesTest { @Test public void testProject() { Project resource = new Project(ProjectDefinition.create()); - assertThat(Scopes.isProject(resource), is(true)); - assertThat(Scopes.isDirectory(resource), is(false)); - assertThat(Scopes.isFile(resource), is(false)); - assertThat(Scopes.isBlockUnit(resource), is(false)); - assertThat(Scopes.isProgramUnit(resource), is(false)); + assertThat(Scopes.isProject(resource)).isTrue(); + assertThat(Scopes.isDirectory(resource)).isFalse(); + assertThat(Scopes.isFile(resource)).isFalse(); + assertThat(Scopes.isBlockUnit(resource)).isFalse(); + assertThat(Scopes.isProgramUnit(resource)).isFalse(); } @Test public void testDirectory() { Resource resource = Directory.create("org/foo"); - assertThat(Scopes.isProject(resource), is(false)); - assertThat(Scopes.isDirectory(resource), is(true)); - assertThat(Scopes.isFile(resource), is(false)); - assertThat(Scopes.isBlockUnit(resource), is(false)); - assertThat(Scopes.isProgramUnit(resource), is(false)); + assertThat(Scopes.isProject(resource)).isFalse(); + assertThat(Scopes.isDirectory(resource)).isTrue(); + assertThat(Scopes.isFile(resource)).isFalse(); + assertThat(Scopes.isBlockUnit(resource)).isFalse(); + assertThat(Scopes.isProgramUnit(resource)).isFalse(); } @Test public void testFile() { Resource resource = File.create("org/foo/Bar.java"); - assertThat(Scopes.isProject(resource), is(false)); - assertThat(Scopes.isDirectory(resource), is(false)); - assertThat(Scopes.isFile(resource), is(true)); - assertThat(Scopes.isBlockUnit(resource), is(false)); - assertThat(Scopes.isProgramUnit(resource), is(false)); + assertThat(Scopes.isProject(resource)).isFalse(); + assertThat(Scopes.isDirectory(resource)).isFalse(); + assertThat(Scopes.isFile(resource)).isTrue(); + assertThat(Scopes.isBlockUnit(resource)).isFalse(); + assertThat(Scopes.isProgramUnit(resource)).isFalse(); } @Test public void shouldBeHigherThan() { - assertThat(Scopes.isHigherThan(Scopes.PROJECT, Scopes.PROJECT), is(false)); - assertThat(Scopes.isHigherThan(Scopes.PROJECT, Scopes.DIRECTORY), is(true)); - assertThat(Scopes.isHigherThan(Scopes.PROJECT, Scopes.BLOCK_UNIT), is(true)); + assertThat(Scopes.isHigherThan(Scopes.PROJECT, Scopes.PROJECT)).isFalse(); + assertThat(Scopes.isHigherThan(Scopes.PROJECT, Scopes.DIRECTORY)).isTrue(); + assertThat(Scopes.isHigherThan(Scopes.PROJECT, Scopes.BLOCK_UNIT)).isTrue(); - assertThat(Scopes.isHigherThan(Scopes.FILE, Scopes.FILE), is(false)); - assertThat(Scopes.isHigherThan(Scopes.FILE, Scopes.DIRECTORY), is(false)); - assertThat(Scopes.isHigherThan(Scopes.FILE, Scopes.BLOCK_UNIT), is(true)); + assertThat(Scopes.isHigherThan(Scopes.FILE, Scopes.FILE)).isFalse(); + assertThat(Scopes.isHigherThan(Scopes.FILE, Scopes.DIRECTORY)).isFalse(); + assertThat(Scopes.isHigherThan(Scopes.FILE, Scopes.BLOCK_UNIT)).isTrue(); } @Test public void shouldBeHigherThanOrEquals() { - assertThat(Scopes.isHigherThanOrEquals(Scopes.PROJECT, Scopes.PROJECT), is(true)); - assertThat(Scopes.isHigherThanOrEquals(Scopes.PROJECT, Scopes.DIRECTORY), is(true)); - assertThat(Scopes.isHigherThanOrEquals(Scopes.PROJECT, Scopes.BLOCK_UNIT), is(true)); + assertThat(Scopes.isHigherThanOrEquals(Scopes.PROJECT, Scopes.PROJECT)).isTrue(); + assertThat(Scopes.isHigherThanOrEquals(Scopes.PROJECT, Scopes.DIRECTORY)).isTrue(); + assertThat(Scopes.isHigherThanOrEquals(Scopes.PROJECT, Scopes.BLOCK_UNIT)).isTrue(); - assertThat(Scopes.isHigherThanOrEquals(Scopes.FILE, Scopes.FILE), is(true)); - assertThat(Scopes.isHigherThanOrEquals(Scopes.FILE, Scopes.DIRECTORY), is(false)); - assertThat(Scopes.isHigherThanOrEquals(Scopes.FILE, Scopes.BLOCK_UNIT), is(true)); + assertThat(Scopes.isHigherThanOrEquals(Scopes.FILE, Scopes.FILE)).isTrue(); + assertThat(Scopes.isHigherThanOrEquals(Scopes.FILE, Scopes.DIRECTORY)).isFalse(); + assertThat(Scopes.isHigherThanOrEquals(Scopes.FILE, Scopes.BLOCK_UNIT)).isTrue(); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/AnnotationUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/AnnotationUtilsTest.java index 0435da87541..011d91b0415 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/AnnotationUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/AnnotationUtilsTest.java @@ -26,49 +26,47 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsNull.nullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class AnnotationUtilsTest { @Test public void getClassAnnotation() { FakeAnnotation annotation = AnnotationUtils.getAnnotation(new SuperClass(), FakeAnnotation.class); - assertThat(annotation.value(), is("foo")); + assertThat(annotation.value()).isEqualTo("foo"); } @Test public void getClassAnnotationWithDeprecatedMethod() { FakeAnnotation annotation = AnnotationUtils.getClassAnnotation(new SuperClass(), FakeAnnotation.class); - assertThat(annotation.value(), is("foo")); + assertThat(annotation.value()).isEqualTo("foo"); } @Test public void searchClassAnnotationInSuperClass() { FakeAnnotation annotation = AnnotationUtils.getAnnotation(new ChildClass(), FakeAnnotation.class); - assertThat(annotation.value(), is("foo")); + assertThat(annotation.value()).isEqualTo("foo"); } @Test public void searchClassAnnotationInInterface() { FakeAnnotation annotation = AnnotationUtils.getAnnotation(new ImplementedClass(), FakeAnnotation.class); - assertThat(annotation.value(), is("foo")); + assertThat(annotation.value()).isEqualTo("foo"); } @Test public void noClassAnnotation() { FakeAnnotation annotation = AnnotationUtils.getAnnotation("a string", FakeAnnotation.class); - assertThat(annotation, nullValue()); + assertThat(annotation).isNull(); } @Test public void shouldAcceptClasses() { FakeAnnotation annotation = AnnotationUtils.getAnnotation(SuperClass.class, FakeAnnotation.class); - assertThat(annotation.value(), is("foo")); + assertThat(annotation.value()).isEqualTo("foo"); annotation = AnnotationUtils.getAnnotation(ChildClass.class, FakeAnnotation.class); - assertThat(annotation.value(), is("foo")); + assertThat(annotation.value()).isEqualTo("foo"); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/LocalizedMessagesTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/LocalizedMessagesTest.java index ecbf13b00f6..50f2a0c209c 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/LocalizedMessagesTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/LocalizedMessagesTest.java @@ -30,9 +30,7 @@ import java.util.List; import java.util.Locale; import java.util.MissingResourceException; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import static org.junit.matchers.JUnitMatchers.hasItems; +import static org.assertj.core.api.Assertions.assertThat; public class LocalizedMessagesTest { private static final Locale DEFAULT_LOCALE = Locale.getDefault(); @@ -51,26 +49,26 @@ public class LocalizedMessagesTest { public void mergeBundles() { LocalizedMessages messages = new LocalizedMessages(Locale.ENGLISH, "Test", "PluginFoo"); - assertThat(messages.getString("test.one"), is("One")); - assertThat(messages.getString("test.two"), is("Two")); - assertThat(messages.getString("foo.hello"), is("Hello")); + assertThat(messages.getString("test.one")).isEqualTo("One"); + assertThat(messages.getString("test.two")).isEqualTo("Two"); + assertThat(messages.getString("foo.hello")).isEqualTo("Hello"); } @Test public void mergeBundlesByLocale() { LocalizedMessages messages = new LocalizedMessages(Locale.FRENCH, "Test", "PluginFoo"); - assertThat(messages.getString("test.one"), is("Un")); - assertThat(messages.getString("test.two"), is("Deux")); - assertThat(messages.getString("foo.hello"), is("Hello"));// not in french, use the default locale + assertThat(messages.getString("test.one")).isEqualTo("Un"); + assertThat(messages.getString("test.two")).isEqualTo("Deux"); + assertThat(messages.getString("foo.hello")).isEqualTo("Hello");// not in french, use the default locale } @Test public void useDefaultWhenMissingLocale() { LocalizedMessages messages = new LocalizedMessages(Locale.JAPANESE, "Test", "PluginFoo"); - assertThat(messages.getString("test.one"), is("One")); - assertThat(messages.getString("foo.hello"), is("Hello")); + assertThat(messages.getString("test.one")).isEqualTo("One"); + assertThat(messages.getString("foo.hello")).isEqualTo("Hello"); } @Test(expected = MissingResourceException.class) @@ -82,29 +80,29 @@ public class LocalizedMessagesTest { @Test public void format() { LocalizedMessages messages = new LocalizedMessages(Locale.ENGLISH, "Test", "PluginFoo"); - assertThat(messages.format("test.one"), is("One")); + assertThat(messages.format("test.one")).isEqualTo("One"); } @Test public void formatNeverFails() { LocalizedMessages messages = new LocalizedMessages(Locale.ENGLISH, "Test", "PluginFoo"); - assertThat(messages.format("unknown"), is("unknown")); + assertThat(messages.format("unknown")).isEqualTo("unknown"); } @Test public void formatParameters() { LocalizedMessages messages = new LocalizedMessages(Locale.ENGLISH, "Test", "PluginFoo"); - assertThat(messages.format("with.string.params", "inspection", "rock"), is("Continuous inspection will rock !")); - assertThat(messages.format("with.string.params", "rock", "inspection"), is("Continuous rock will inspection !")); + assertThat(messages.format("with.string.params", "inspection", "rock")).isEqualTo("Continuous inspection will rock !"); + assertThat(messages.format("with.string.params", "rock", "inspection")).isEqualTo("Continuous rock will inspection !"); } @Test public void getKeys() { LocalizedMessages messages = new LocalizedMessages(Locale.ENGLISH, "Test", "PluginFoo"); - assertThat(toList(messages.getKeys()), hasItems("test.one", "test.two", "foo.hello")); + assertThat(toList(messages.getKeys())).contains("test.one", "test.two", "foo.hello"); LocalizedMessages spanishMessages = new LocalizedMessages(new Locale("es"), "Test", "PluginFoo"); - assertThat(toList(spanishMessages.getKeys()), hasItems("test.one", "only.in.spanish")); + assertThat(toList(spanishMessages.getKeys())).contains("test.one", "only.in.spanish"); } private List<String> toList(Enumeration<String> enumeration) { diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ParsingUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ParsingUtilsTest.java index 877380a98d3..1b4556a6a8d 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/ParsingUtilsTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/ParsingUtilsTest.java @@ -19,28 +19,27 @@ */ package org.sonar.api.utils; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; -import org.junit.Test; - import java.text.ParseException; import java.util.Locale; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; public class ParsingUtilsTest { @Test public void scaleValue() { - assertThat(ParsingUtils.scaleValue(23.3333333), is(23.33)); - assertThat(ParsingUtils.scaleValue(23.777777), is(23.78)); + assertThat(ParsingUtils.scaleValue(23.3333333)).isEqualTo(23.33); + assertThat(ParsingUtils.scaleValue(23.777777)).isEqualTo(23.78); - assertThat(ParsingUtils.scaleValue(23.3333333, 0), is(23.0)); - assertThat(ParsingUtils.scaleValue(23.777777, 0), is(24.0)); + assertThat(ParsingUtils.scaleValue(23.3333333, 0)).isEqualTo(23.0); + assertThat(ParsingUtils.scaleValue(23.777777, 0)).isEqualTo(24.0); } @Test public void parseString() throws ParseException { - assertThat(ParsingUtils.parseNumber("23.12", Locale.ENGLISH), is(23.12)); - assertThat(ParsingUtils.parseNumber("12345.67", Locale.ENGLISH), is(12345.67)); - assertThat(ParsingUtils.parseNumber("12345,67", Locale.FRENCH), is(12345.67)); + assertThat(ParsingUtils.parseNumber("23.12", Locale.ENGLISH)).isEqualTo(23.12); + assertThat(ParsingUtils.parseNumber("12345.67", Locale.ENGLISH)).isEqualTo(12345.67); + assertThat(ParsingUtils.parseNumber("12345,67", Locale.FRENCH)).isEqualTo(12345.67); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java index dbf0744f1cc..f12e28dc7e6 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/WildcardPatternTest.java @@ -19,13 +19,10 @@ */ package org.sonar.api.utils; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; - import org.junit.Test; +import static org.assertj.core.api.Assertions.assertThat; + public class WildcardPatternTest { private boolean match(String pattern, String value, String separator) { @@ -38,88 +35,88 @@ public class WildcardPatternTest { @Test public void examples() { - assertTrue(match("org/T?st.java", "org/Test.java")); - assertTrue(match("org/T?st.java", "org/Tost.java")); + assertThat(match("org/T?st.java", "org/Test.java")).isTrue(); + assertThat(match("org/T?st.java", "org/Tost.java")).isTrue(); - assertTrue(match("org/*.java", "org/Foo.java")); - assertTrue(match("org/*.java", "org/Bar.java")); + assertThat(match("org/*.java", "org/Foo.java")).isTrue(); + assertThat(match("org/*.java", "org/Bar.java")).isTrue(); - assertTrue(match("org/**", "org/Foo.java")); - assertTrue(match("org/**", "org/foo/bar.jsp")); + assertThat(match("org/**", "org/Foo.java")).isTrue(); + assertThat(match("org/**", "org/foo/bar.jsp")).isTrue(); - assertTrue(match("org/**/Test.java", "org/Test.java")); - assertTrue(match("org/**/Test.java", "org/foo/Test.java")); - assertTrue(match("org/**/Test.java", "org/foo/bar/Test.java")); + assertThat(match("org/**/Test.java", "org/Test.java")).isTrue(); + assertThat(match("org/**/Test.java", "org/foo/Test.java")).isTrue(); + assertThat(match("org/**/Test.java", "org/foo/bar/Test.java")).isTrue(); - assertTrue(match("org/**/*.java", "org/Foo.java")); - assertTrue(match("org/**/*.java", "org/foo/Bar.java")); - assertTrue(match("org/**/*.java", "org/foo/bar/Baz.java")); + assertThat(match("org/**/*.java", "org/Foo.java")).isTrue(); + assertThat(match("org/**/*.java", "org/foo/Bar.java")).isTrue(); + assertThat(match("org/**/*.java", "org/foo/bar/Baz.java")).isTrue(); } @Test public void javaResourcesShouldMatchWildcards() { - assertTrue(match("Foo", "Foo", ".")); - assertFalse(match("Foo", "Bar", ".")); + assertThat(match("Foo", "Foo", ".")).isTrue(); + assertThat(match("Foo", "Bar", ".")).isFalse(); - assertTrue(match("org/sonar/**", "org.sonar.commons.Foo", ".")); - assertTrue(match("org/sonar/**", "org.sonar.Foo", ".")); - assertFalse(match("xxx/org/sonar/**", "org.sonar.Foo", ".")); + assertThat(match("org/sonar/**", "org.sonar.commons.Foo", ".")).isTrue(); + assertThat(match("org/sonar/**", "org.sonar.Foo", ".")).isTrue(); + assertThat(match("xxx/org/sonar/**", "org.sonar.Foo", ".")).isFalse(); - assertTrue(match("org/sonar/**/**", "org.sonar.commons.Foo", ".")); - assertTrue(match("org/sonar/**/**", "org.sonar.commons.sub.Foo", ".")); - assertTrue(match("org/sonar/**/Foo", "org.sonar.commons.sub.Foo", ".")); - assertTrue(match("org/sonar/**/Foo", "org.sonar.Foo", ".")); + assertThat(match("org/sonar/**/**", "org.sonar.commons.Foo", ".")).isTrue(); + assertThat(match("org/sonar/**/**", "org.sonar.commons.sub.Foo", ".")).isTrue(); + assertThat(match("org/sonar/**/Foo", "org.sonar.commons.sub.Foo", ".")).isTrue(); + assertThat(match("org/sonar/**/Foo", "org.sonar.Foo", ".")).isTrue(); - assertTrue(match("*/foo/*", "org.foo.Bar", ".")); - assertFalse(match("*/foo/*", "foo.Bar", ".")); - assertFalse(match("*/foo/*", "foo", ".")); - assertFalse(match("*/foo/*", "org.foo.bar.Hello", ".")); + assertThat(match("*/foo/*", "org.foo.Bar", ".")).isTrue(); + assertThat(match("*/foo/*", "foo.Bar", ".")).isFalse(); + assertThat(match("*/foo/*", "foo", ".")).isFalse(); + assertThat(match("*/foo/*", "org.foo.bar.Hello", ".")).isFalse(); - assertTrue(match("hell?", "hello", ".")); - assertFalse(match("hell?", "helloworld", ".")); - assertFalse(match("hell?", "hell", ".")); + assertThat(match("hell?", "hello", ".")).isTrue(); + assertThat(match("hell?", "helloworld", ".")).isFalse(); + assertThat(match("hell?", "hell", ".")).isFalse(); - assertTrue(match("a.b.c", "a.b.c", ".")); - assertTrue(match("*/a.b.c", "foo.a.b.c", ".")); - assertFalse(match("*/a.b.c", "foo/aabbc", ".")); + assertThat(match("a.b.c", "a.b.c", ".")).isTrue(); + assertThat(match("*/a.b.c", "foo.a.b.c", ".")).isTrue(); + assertThat(match("*/a.b.c", "foo/aabbc", ".")).isFalse(); - assertTrue(match("**/Reader", "java.io.Reader", ".")); - assertFalse(match("**/Reader", "org.sonar.channel.CodeReader", ".")); + assertThat(match("**/Reader", "java.io.Reader", ".")).isTrue(); + assertThat(match("**/Reader", "org.sonar.channel.CodeReader", ".")).isFalse(); - assertTrue(match("**", "java.io.Reader", ".")); + assertThat(match("**", "java.io.Reader", ".")).isTrue(); } @Test public void directoriesShouldMatchWildcards() { - assertTrue(match("Foo", "Foo")); - assertFalse(match("Foo", "Bar")); + assertThat(match("Foo", "Foo")).isTrue(); + assertThat(match("Foo", "Bar")).isFalse(); - assertTrue(match("org/sonar/**", "org/sonar/commons/Foo")); - assertTrue(match("org/sonar/**", "org/sonar/Foo.java")); - assertFalse(match("xxx/org/sonar/**", "org/sonar/Foo")); + assertThat(match("org/sonar/**", "org/sonar/commons/Foo")).isTrue(); + assertThat(match("org/sonar/**", "org/sonar/Foo.java")).isTrue(); + assertThat(match("xxx/org/sonar/**", "org/sonar/Foo")).isFalse(); - assertTrue(match("org/sonar/**/**", "org/sonar/commons/Foo")); - assertTrue(match("org/sonar/**/**", "org/sonar/commons/sub/Foo.java")); - assertTrue(match("org/sonar/**/Foo", "org/sonar/commons/sub/Foo")); - assertTrue(match("org/sonar/**/Foo", "org/sonar/Foo")); + assertThat(match("org/sonar/**/**", "org/sonar/commons/Foo")).isTrue(); + assertThat(match("org/sonar/**/**", "org/sonar/commons/sub/Foo.java")).isTrue(); + assertThat(match("org/sonar/**/Foo", "org/sonar/commons/sub/Foo")).isTrue(); + assertThat(match("org/sonar/**/Foo", "org/sonar/Foo")).isTrue(); - assertTrue(match("*/foo/*", "org/foo/Bar")); - assertFalse(match("*/foo/*", "foo/Bar")); - assertFalse(match("*/foo/*", "foo")); - assertFalse(match("*/foo/*", "org/foo/bar/Hello")); + assertThat(match("*/foo/*", "org/foo/Bar")).isTrue(); + assertThat(match("*/foo/*", "foo/Bar")).isFalse(); + assertThat(match("*/foo/*", "foo")).isFalse(); + assertThat(match("*/foo/*", "org/foo/bar/Hello")).isFalse(); - assertTrue(match("hell?", "hello")); - assertFalse(match("hell?", "helloworld")); - assertFalse(match("hell?", "hell")); + assertThat(match("hell?", "hello")).isTrue(); + assertThat(match("hell?", "helloworld")).isFalse(); + assertThat(match("hell?", "hell")).isFalse(); - assertTrue(match("a.b.c", "a.b.c")); - assertTrue(match("*/a.b.c", "foo/a.b.c")); - assertFalse(match("*/a.b.c", "foo/aabbc")); + assertThat(match("a.b.c", "a.b.c")).isTrue(); + assertThat(match("*/a.b.c", "foo/a.b.c")).isTrue(); + assertThat(match("*/a.b.c", "foo/aabbc")).isFalse(); - assertTrue(match("**/Reader", "java/io/Reader")); - assertFalse(match("**/Reader", "org/sonar/channel/CodeReader")); + assertThat(match("**/Reader", "java/io/Reader")).isTrue(); + assertThat(match("**/Reader", "org/sonar/channel/CodeReader")).isFalse(); - assertTrue(match("**", "java/io/Reader")); + assertThat(match("**", "java/io/Reader")).isTrue(); } /** @@ -127,11 +124,11 @@ public class WildcardPatternTest { */ @Test public void issue2193() { - assertTrue(match("**/app/**", "com.app.Utils", ".")); - assertFalse(match("**/app/**", "com.application.MyService", ".")); + assertThat(match("**/app/**", "com.app.Utils", ".")).isTrue(); + assertThat(match("**/app/**", "com.application.MyService", ".")).isFalse(); - assertTrue(match("**/app/**", "com/app/Utils")); - assertFalse(match("**/app/**", "com/application/MyService")); + assertThat(match("**/app/**", "com/app/Utils")).isTrue(); + assertThat(match("**/app/**", "com/application/MyService")).isFalse(); } /** @@ -139,28 +136,28 @@ public class WildcardPatternTest { */ @Test public void shouldEscapeRegexpSpecificCharacters() { - assertFalse(match("**/*$*", "foo/bar")); - assertTrue(match("**/*$*", "foo/bar$baz")); + assertThat(match("**/*$*", "foo/bar")).isFalse(); + assertThat(match("**/*$*", "foo/bar$baz")).isTrue(); - assertFalse(match("a+", "aa")); - assertTrue(match("a+", "a+")); + assertThat(match("a+", "aa")).isFalse(); + assertThat(match("a+", "a+")).isTrue(); - assertFalse(match("[ab]", "a")); - assertTrue(match("[ab]", "[ab]")); + assertThat(match("[ab]", "a")).isFalse(); + assertThat(match("[ab]", "[ab]")).isTrue(); - assertTrue("all regexp-specific characters", match("()[]^$.{}+|", "()[]^$.{}+|")); + assertThat(match("()[]^$.{}+|", "()[]^$.{}+|")).as("all regexp-specific characters").isTrue(); } @Test public void backslash() { - assertFalse("backslash is not an escape character", match("\\n", "\n")); - assertTrue("backslash is the same as forward slash", match("foo\\bar", "foo/bar")); + assertThat(match("\\n", "\n")).as("backslash is not an escape character").isFalse(); + assertThat(match("foo\\bar", "foo/bar")).as("backslash is the same as forward slash").isTrue(); } @Test public void shouldIgnoreStartingSlash() { - assertTrue(match("/foo", "foo")); - assertTrue(match("\\foo", "foo")); + assertThat(match("/foo", "foo")).isTrue(); + assertThat(match("\\foo", "foo")).isTrue(); } /** @@ -169,21 +166,21 @@ public class WildcardPatternTest { */ @Test public void cornerCase() { - assertTrue(match("org/**.*", "org.sonar.commons.Foo.java", ".")); + assertThat(match("org/**.*", "org.sonar.commons.Foo.java", ".")).isTrue(); } @Test public void multiplePatterns() { - WildcardPattern[] patterns = WildcardPattern.create(new String[] { "Foo", "Bar" }); - assertTrue(WildcardPattern.match(patterns, "Foo")); - assertTrue(WildcardPattern.match(patterns, "Bar")); - assertFalse(WildcardPattern.match(patterns, "Other")); + WildcardPattern[] patterns = WildcardPattern.create(new String[] {"Foo", "Bar"}); + assertThat(WildcardPattern.match(patterns, "Foo")).isTrue(); + assertThat(WildcardPattern.match(patterns, "Bar")).isTrue(); + assertThat(WildcardPattern.match(patterns, "Other")).isFalse(); - assertThat(WildcardPattern.create((String[]) null).length, is(0)); + assertThat(WildcardPattern.create((String[]) null)).isEmpty(); } @Test public void testToString() { - assertThat(WildcardPattern.create("foo*").toString(), is("foo*")); + assertThat(WildcardPattern.create("foo*").toString()).isEqualTo("foo*"); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/web/AbstractRubyTemplateTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/AbstractRubyTemplateTest.java index 869466fb6be..65b385bf9ed 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/web/AbstractRubyTemplateTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/web/AbstractRubyTemplateTest.java @@ -19,14 +19,13 @@ */ package org.sonar.api.web; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; import org.junit.Test; import org.sonar.api.utils.SonarException; import java.net.URL; +import static org.assertj.core.api.Assertions.assertThat; + public class AbstractRubyTemplateTest { @Test @@ -38,9 +37,9 @@ public class AbstractRubyTemplateTest { } }; - assertThat(template.loadTemplateFromCache(), nullValue()); - assertThat(template.getTemplate(), is("ok")); - assertThat(template.loadTemplateFromCache(), is("ok")); + assertThat(template.loadTemplateFromCache()).isNull(); + assertThat(template.getTemplate()).isEqualTo("ok"); + assertThat(template.loadTemplateFromCache()).isEqualTo("ok"); } @Test @@ -53,9 +52,9 @@ public class AbstractRubyTemplateTest { } }; - assertThat(template.loadTemplateFromCache(), nullValue()); - assertThat(template.getTemplate(), is("ok")); - assertThat(template.loadTemplateFromCache(), nullValue()); + assertThat(template.loadTemplateFromCache()).isNull(); + assertThat(template.getTemplate()).isEqualTo("ok"); + assertThat(template.loadTemplateFromCache()).isNull(); } @Test(expected = SonarException.class) diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/web/DashboardTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/web/DashboardTest.java index f28ba47e3da..80ed02d6dc6 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/web/DashboardTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/web/DashboardTest.java @@ -21,34 +21,32 @@ package org.sonar.api.web; import org.junit.Test; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class DashboardTest { @Test public void shouldCreateDashboard() { Dashboard dashboard = Dashboard.create(); - assertThat(dashboard.getLayout(), is(DashboardLayout.TWO_COLUMNS)); - assertThat(dashboard.getDescription(), nullValue()); - assertThat(dashboard.getWidgets().size(), is(0)); + assertThat(dashboard.getLayout()).isEqualTo(DashboardLayout.TWO_COLUMNS); + assertThat(dashboard.getDescription()).isNull(); + assertThat(dashboard.getWidgets()).hasSize(0); } @Test public void shouldAddWidgets() { Dashboard dashboard = Dashboard.create(); Dashboard.Widget mostViolatedRules = dashboard.addWidget("most_violated_rules", 1); - assertThat(mostViolatedRules.getId(), is("most_violated_rules")); - assertThat(dashboard.getWidgets().size(), is(1)); - assertThat(dashboard.getWidgetsOfColumn(1).size(), is(1)); + assertThat(mostViolatedRules.getId()).isEqualTo("most_violated_rules"); + assertThat(dashboard.getWidgets()).hasSize(1); + assertThat(dashboard.getWidgetsOfColumn(1)).hasSize(1); dashboard.addWidget("hotspots", 1); - assertThat(dashboard.getWidgets().size(), is(2)); - assertThat(dashboard.getWidgetsOfColumn(1).size(), is(2)); + assertThat(dashboard.getWidgets()).hasSize(2); + assertThat(dashboard.getWidgetsOfColumn(1)).hasSize(2); // widgets are sorted by order of insertion - assertThat(dashboard.getWidgetsOfColumn(1).get(1).getId(), is("hotspots")); + assertThat(dashboard.getWidgetsOfColumn(1).get(1).getId()).isEqualTo("hotspots"); } @Test @@ -56,12 +54,12 @@ public class DashboardTest { Dashboard dashboard = Dashboard.create(); dashboard.addWidget("most_violated_rules", 1); - assertThat(dashboard.getWidgets().size(), is(1)); - assertThat(dashboard.getWidgetsOfColumn(1).size(), is(1)); + assertThat(dashboard.getWidgets().size()).isEqualTo(1); + assertThat(dashboard.getWidgetsOfColumn(1).size()).isEqualTo(1); dashboard.addWidget("hotspots", 2); - assertThat(dashboard.getWidgets().size(), is(2)); - assertThat(dashboard.getWidgetsOfColumn(2).size(), is(1)); + assertThat(dashboard.getWidgets().size()).isEqualTo(2); + assertThat(dashboard.getWidgetsOfColumn(2).size()).isEqualTo(1); } @Test @@ -70,9 +68,9 @@ public class DashboardTest { dashboard.addWidget("most_violated_rules", 1); dashboard.addWidget("most_violated_rules", 1).setProperty("foo", "bar"); - assertThat(dashboard.getWidgets().size(), is(2)); - assertThat(dashboard.getWidgetsOfColumn(1).get(0).getProperties().size(), is(0)); - assertThat(dashboard.getWidgetsOfColumn(1).get(1).getProperty("foo"), is("bar")); + assertThat(dashboard.getWidgets().size()).isEqualTo(2); + assertThat(dashboard.getWidgetsOfColumn(1).get(0).getProperties().size()).isEqualTo(0); + assertThat(dashboard.getWidgetsOfColumn(1).get(1).getProperty("foo")).isEqualTo("bar"); } @Test @@ -81,6 +79,6 @@ public class DashboardTest { Dashboard.Widget widget = dashboard.addWidget("fake-widget", 1); widget.setProperty("foo", "bar"); - assertThat(widget.getProperties().get("foo"), is("bar")); + assertThat(widget.getProperties().get("foo")).isEqualTo("bar"); } } diff --git a/sonar-testing-harness/pom.xml b/sonar-testing-harness/pom.xml index c7eaa3ddcb3..17df9f28935 100644 --- a/sonar-testing-harness/pom.xml +++ b/sonar-testing-harness/pom.xml @@ -12,20 +12,6 @@ <dependencies> <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-core</artifactId> - </dependency> - <dependency> - <groupId>org.assertj</groupId> - <artifactId>assertj-guava</artifactId> - <exclusions> - <exclusion> - <groupId>com.google.guava</groupId> - <artifactId>guava</artifactId> - </exclusion> - </exclusions> - </dependency> - <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> </dependency> @@ -38,30 +24,25 @@ <artifactId>junit</artifactId> </dependency> <dependency> - <groupId>com.tngtech.java</groupId> - <artifactId>junit-dataprovider</artifactId> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-all</artifactId> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-core</artifactId> - </dependency> - <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - </dependency> <dependency> <groupId>com.google.code.findbugs</groupId> <artifactId>jsr305</artifactId> <scope>provided</scope> </dependency> + + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest-all</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java index 0749a0fb5c0..90e9dd3b744 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/BundleSynchronizedMatcher.java @@ -19,10 +19,6 @@ */ package org.sonar.test.i18n; -import org.apache.commons.io.IOUtils; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; - import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -34,10 +30,12 @@ import java.util.Map; import java.util.Properties; import java.util.SortedMap; import java.util.TreeMap; +import org.apache.commons.io.IOUtils; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; public class BundleSynchronizedMatcher extends BaseMatcher<String> { @@ -152,21 +150,20 @@ public class BundleSynchronizedMatcher extends BaseMatcher<String> { protected static InputStream getBundleFileInputStream(String bundleName) { InputStream bundle = BundleSynchronizedMatcher.class.getResourceAsStream(L10N_PATH + bundleName); - assertThat("File '" + bundleName + "' does not exist in '/org/sonar/l10n/'.", bundle, notNullValue()); + assertNotNull("File '" + bundleName + "' does not exist in '/org/sonar/l10n/'.", bundle); return bundle; } protected static InputStream getDefaultBundleFileInputStream(String bundleName) { String defaultBundleName = extractDefaultBundleName(bundleName); InputStream bundle = BundleSynchronizedMatcher.class.getResourceAsStream(L10N_PATH + defaultBundleName); - assertThat("Default bundle '" + defaultBundleName + "' could not be found: add a dependency to the corresponding plugin in your POM.", bundle, notNullValue()); + assertNotNull("Default bundle '" + defaultBundleName + "' could not be found: add a dependency to the corresponding plugin in your POM.", bundle); return bundle; } protected static String extractDefaultBundleName(String bundleName) { int firstUnderScoreIndex = bundleName.indexOf('_'); - assertThat("The bundle '" + bundleName + "' is a default bundle (without locale), so it can't be compared.", firstUnderScoreIndex > 0, - is(true)); + assertTrue("The bundle '" + bundleName + "' is a default bundle (without locale), so it can't be compared.", firstUnderScoreIndex > 0); return bundleName.substring(0, firstUnderScoreIndex) + ".properties"; } diff --git a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java index b6428f1cb59..874215299d5 100644 --- a/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java +++ b/sonar-testing-harness/src/main/java/org/sonar/test/i18n/I18nMatchers.java @@ -19,15 +19,13 @@ */ package org.sonar.test.i18n; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.sonar.test.TestUtils; - import java.io.File; import java.net.URL; import java.util.Collection; import java.util.HashMap; import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.sonar.test.TestUtils; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; @@ -55,7 +53,7 @@ public final class I18nMatchers { fail("No bundle found in: " + BundleSynchronizedMatcher.L10N_PATH); } - Collection<File> bundles = FileUtils.listFiles(bundleFolder, new String[]{"properties"}, false); + Collection<File> bundles = FileUtils.listFiles(bundleFolder, new String[] {"properties"}, false); Map<String, String> failedAssertionMessages = new HashMap<>(); for (File bundle : bundles) { String bundleName = bundle.getName(); @@ -72,9 +70,9 @@ public final class I18nMatchers { StringBuilder message = new StringBuilder(); message.append(failedAssertionMessages.size()); message.append(" bundles are not up-to-date: "); - message.append(StringUtils.join(failedAssertionMessages.keySet(), ", ")); + message.append(String.join(", ", failedAssertionMessages.keySet())); message.append("\n\n"); - message.append(StringUtils.join(failedAssertionMessages.values(), "\n\n")); + message.append(String.join("\n\n", failedAssertionMessages.values())); fail(message.toString()); } } diff --git a/sonar-ws/pom.xml b/sonar-ws/pom.xml index 04e46379c45..720dec97b7e 100644 --- a/sonar-ws/pom.xml +++ b/sonar-ws/pom.xml @@ -48,6 +48,21 @@ <!-- Tests --> <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>${project.groupId}</groupId> <artifactId>sonar-testing-harness</artifactId> <version>${project.version}</version> @@ -58,5 +73,10 @@ <artifactId>mockwebserver</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <scope>test</scope> + </dependency> </dependencies> </project> |