diff options
Diffstat (limited to 'server')
13 files changed, 173 insertions, 50 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() + "]"); } } |