aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server/src/test/java/org/sonar/server
diff options
context:
space:
mode:
Diffstat (limited to 'sonar-server/src/test/java/org/sonar/server')
-rw-r--r--sonar-server/src/test/java/org/sonar/server/db/EmbeddedDatabaseFactoryTest.java12
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java70
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java8
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/CleanPreviewAnalysisCacheTest.java38
-rw-r--r--sonar-server/src/test/java/org/sonar/server/startup/ServerMetadataPersisterTest.java16
-rw-r--r--sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtFormatterTest.java (renamed from sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtFormatterTest.java)25
-rw-r--r--sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtServiceTest.java (renamed from sonar-server/src/test/java/org/sonar/server/technicaldebt/InternalRubyTechnicalDebtServiceTest.java)27
-rw-r--r--sonar-server/src/test/java/org/sonar/server/user/CompatibilityRealmTest.java (renamed from sonar-server/src/test/java/org/sonar/server/ui/CompatibilityRealmTest.java)2
-rw-r--r--sonar-server/src/test/java/org/sonar/server/user/GroupMembershipFinderTest.java (renamed from sonar-server/src/test/java/org/sonar/server/group/GroupMembershipFinderTest.java)27
-rw-r--r--sonar-server/src/test/java/org/sonar/server/user/GroupMembershipServiceTest.java (renamed from sonar-server/src/test/java/org/sonar/server/group/InternalGroupMembershipServiceTest.java)26
-rw-r--r--sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java (renamed from sonar-server/src/test/java/org/sonar/server/ui/SecurityRealmFactoryTest.java)34
-rw-r--r--sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java3
12 files changed, 138 insertions, 150 deletions
diff --git a/sonar-server/src/test/java/org/sonar/server/db/EmbeddedDatabaseFactoryTest.java b/sonar-server/src/test/java/org/sonar/server/db/EmbeddedDatabaseFactoryTest.java
index 79ed485350d..ed43851aea6 100644
--- a/sonar-server/src/test/java/org/sonar/server/db/EmbeddedDatabaseFactoryTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/db/EmbeddedDatabaseFactoryTest.java
@@ -20,23 +20,15 @@
package org.sonar.server.db;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.api.config.Settings;
import org.sonar.api.database.DatabaseProperties;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.*;
public class EmbeddedDatabaseFactoryTest {
- private Settings settings;
-
- @Before
- public void initSettings() {
- settings = new Settings();
- }
+ Settings settings = new Settings();
@Test
public void should_start_and_stop_tcp_h2_database() throws Exception {
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java b/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java
index c214dac11a1..ff90a7cc425 100644
--- a/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/issue/IssueChangelogFormatterTest.java
@@ -27,7 +27,7 @@ import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.issue.internal.FieldDiffs;
import org.sonar.api.issue.internal.WorkDayDuration;
import org.sonar.core.i18n.DefaultI18n;
-import org.sonar.server.technicaldebt.TechnicalDebtFormatter;
+import org.sonar.server.technicaldebt.DebtFormatter;
import java.util.List;
import java.util.Locale;
@@ -41,26 +41,26 @@ public class IssueChangelogFormatterTest {
private static final Locale DEFAULT_LOCALE = Locale.getDefault();
@Mock
- private DefaultI18n defaultI18n;
+ private DefaultI18n i18n;
@Mock
- private TechnicalDebtFormatter technicalDebtFormatter;
+ private DebtFormatter debtFormatter;
private IssueChangelogFormatter formatter;
@Before
- public void before(){
- formatter = new IssueChangelogFormatter(defaultI18n, technicalDebtFormatter);
+ public void before() {
+ formatter = new IssueChangelogFormatter(i18n, debtFormatter);
}
@Test
- public void format_field_diffs_with_new_and_old_value(){
+ public void format_field_diffs_with_new_and_old_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "BLOCKER", "INFO");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
@@ -69,12 +69,12 @@ public class IssueChangelogFormatterTest {
}
@Test
- public void format_field_diffs_with_only_new_value(){
+ public void format_field_diffs_with_only_new_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", null, "INFO");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Severity", "INFO")).thenReturn("Severity changed to INFO");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
@@ -83,13 +83,13 @@ public class IssueChangelogFormatterTest {
}
@Test
- public void format_field_diffs_with_only_old_value(){
+ public void format_field_diffs_with_only_old_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "BLOCKER", null);
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "BLOCKER")).thenReturn("was BLOCKER");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
@@ -98,12 +98,12 @@ public class IssueChangelogFormatterTest {
}
@Test
- public void format_field_diffs_without_value(){
+ public void format_field_diffs_without_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", null, null);
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
@@ -112,12 +112,12 @@ public class IssueChangelogFormatterTest {
}
@Test
- public void format_field_diffs_with_empty_old_value(){
+ public void format_field_diffs_with_empty_old_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("severity", "", null);
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.severity", null)).thenReturn("Severity");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Severity")).thenReturn("Severity removed");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
@@ -126,16 +126,16 @@ public class IssueChangelogFormatterTest {
}
@Test
- public void format_technical_debt_with_old_and_new_value(){
+ public void format_technical_debt_with_old_and_new_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("technicalDebt", "500", "10000");
- when(technicalDebtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 5, 0))).thenReturn("5 hours");
- when(technicalDebtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days");
+ when(debtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 5, 0))).thenReturn("5 hours");
+ when(debtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "5 hours")).thenReturn("was 5 hours");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.was", null, "5 hours")).thenReturn("was 5 hours");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
@@ -144,14 +144,14 @@ public class IssueChangelogFormatterTest {
}
@Test
- public void format_technical_debt_with_new_value_only(){
+ public void format_technical_debt_with_new_value_only() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("technicalDebt", null, "10000");
- when(technicalDebtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days");
+ when(debtFormatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 1))).thenReturn("1 days");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.changed_to", null, "Technical Debt", "1 days")).thenReturn("Technical Debt changed to 1 days");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
@@ -160,12 +160,12 @@ public class IssueChangelogFormatterTest {
}
@Test
- public void format_technical_debt_without_value(){
+ public void format_technical_debt_without_value() {
FieldDiffs diffs = new FieldDiffs();
diffs.setDiff("technicalDebt", null, null);
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Technical Debt")).thenReturn("Technical Debt removed");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.field.technicalDebt", null)).thenReturn("Technical Debt");
+ when(i18n.message(DEFAULT_LOCALE, "issue.changelog.removed", null, "Technical Debt")).thenReturn("Technical Debt removed");
List<String> result = formatter.format(DEFAULT_LOCALE, diffs);
assertThat(result).hasSize(1);
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java
index f123ae99f8a..c8337a87279 100644
--- a/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/issue/ws/IssueShowWsHandlerTest.java
@@ -53,7 +53,7 @@ import org.sonar.server.issue.ActionService;
import org.sonar.server.issue.IssueChangelog;
import org.sonar.server.issue.IssueChangelogService;
import org.sonar.server.issue.IssueService;
-import org.sonar.server.technicaldebt.TechnicalDebtFormatter;
+import org.sonar.server.technicaldebt.DebtFormatter;
import org.sonar.server.user.MockUserSession;
import org.sonar.server.user.UserSession;
@@ -84,7 +84,7 @@ public class IssueShowWsHandlerTest {
ActionService actionService;
@Mock
- TechnicalDebtFormatter technicalDebtFormatter;
+ DebtFormatter debtFormatter;
@Mock
DefaultTechnicalDebtManager technicalDebtManager;
@@ -113,7 +113,7 @@ public class IssueShowWsHandlerTest {
when(i18n.message(any(Locale.class), eq("created"), eq((String) null))).thenReturn("Created");
- tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, issueChangelogService, actionService, technicalDebtFormatter, technicalDebtManager, i18n)));
+ tester = new WsTester(new IssuesWs(new IssueShowWsHandler(issueFinder, issueService, issueChangelogService, actionService, debtFormatter, technicalDebtManager, i18n)));
}
@Test
@@ -214,7 +214,7 @@ public class IssueShowWsHandlerTest {
.setTechnicalDebt(technicalDebt);
issues.add(issue);
- when(technicalDebtFormatter.format(any(Locale.class), eq(technicalDebt))).thenReturn("2 hours 1 minutes");
+ when(debtFormatter.format(any(Locale.class), eq(technicalDebt))).thenReturn("2 hours 1 minutes");
MockUserSession.set();
WsTester.TestRequest request = tester.newRequest("show").setParam("key", issue.key());
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/CleanPreviewAnalysisCacheTest.java b/sonar-server/src/test/java/org/sonar/server/startup/CleanPreviewAnalysisCacheTest.java
new file mode 100644
index 00000000000..2ae9b5b020a
--- /dev/null
+++ b/sonar-server/src/test/java/org/sonar/server/startup/CleanPreviewAnalysisCacheTest.java
@@ -0,0 +1,38 @@
+/*
+ * SonarQube, open source software quality management tool.
+ * Copyright (C) 2008-2013 SonarSource
+ * mailto:contact AT sonarsource DOT com
+ *
+ * SonarQube is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * SonarQube is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package org.sonar.server.startup;
+
+import org.junit.Test;
+import org.sonar.core.preview.PreviewCache;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+public class CleanPreviewAnalysisCacheTest {
+ @Test
+ public void clean_cache_on_startup() throws Exception {
+ PreviewCache cache = mock(PreviewCache.class);
+ CleanPreviewAnalysisCache cleaner = new CleanPreviewAnalysisCache(cache);
+
+ cleaner.start();
+ verify(cache).cleanAll();
+ cleaner.stop();
+ }
+}
diff --git a/sonar-server/src/test/java/org/sonar/server/startup/ServerMetadataPersisterTest.java b/sonar-server/src/test/java/org/sonar/server/startup/ServerMetadataPersisterTest.java
index 9ddeeaae9e0..f5c8bf13c92 100644
--- a/sonar-server/src/test/java/org/sonar/server/startup/ServerMetadataPersisterTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/startup/ServerMetadataPersisterTest.java
@@ -32,14 +32,12 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
public class ServerMetadataPersisterTest {
- private TimeZone initialTimeZone;
- private PersistentSettings persistentSettings;
+ TimeZone initialTimeZone;
+ PersistentSettings persistentSettings;
@Before
public void fixTimeZone() {
@@ -65,9 +63,11 @@ public class ServerMetadataPersisterTest {
persister.start();
verify(persistentSettings).saveProperties(ImmutableMap.of(
- CoreProperties.SERVER_ID, "123",
- CoreProperties.SERVER_VERSION, "3.2",
- CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000"));
+ CoreProperties.SERVER_ID, "123",
+ CoreProperties.SERVER_VERSION, "3.2",
+ CoreProperties.SERVER_STARTTIME, "2010-05-18T17:59:00+0000"));
+
+ persister.stop();
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtFormatterTest.java b/sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtFormatterTest.java
index 0de635bfcd1..f7249fb21b5 100644
--- a/sonar-server/src/test/java/org/sonar/server/technicaldebt/TechnicalDebtFormatterTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtFormatterTest.java
@@ -20,39 +20,28 @@
package org.sonar.server.technicaldebt;
-import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.issue.internal.WorkDayDuration;
import org.sonar.core.i18n.DefaultI18n;
import java.util.Locale;
import static org.fest.assertions.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-@RunWith(MockitoJUnitRunner.class)
-public class TechnicalDebtFormatterTest {
+public class DebtFormatterTest {
private static final Locale DEFAULT_LOCALE = Locale.getDefault();
- @Mock
- private DefaultI18n defaultI18n;
-
- private TechnicalDebtFormatter formatter;
-
- @Before
- public void before() {
- formatter = new TechnicalDebtFormatter(defaultI18n);
- }
+ DefaultI18n i18n = mock(DefaultI18n.class);
+ DebtFormatter formatter = new DebtFormatter(i18n);
@Test
public void format() {
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_days", null, 5)).thenReturn("5 days");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_hours", null, 2)).thenReturn("2 hours");
- when(defaultI18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_minutes", null, 1)).thenReturn("1 minutes");
+ when(i18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_days", null, 5)).thenReturn("5 days");
+ when(i18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_hours", null, 2)).thenReturn("2 hours");
+ when(i18n.message(DEFAULT_LOCALE, "issue.technical_debt.x_minutes", null, 1)).thenReturn("1 minutes");
assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 0, 5))).isEqualTo("5 days");
assertThat(formatter.format(DEFAULT_LOCALE, WorkDayDuration.of(0, 2, 0))).isEqualTo("2 hours");
diff --git a/sonar-server/src/test/java/org/sonar/server/technicaldebt/InternalRubyTechnicalDebtServiceTest.java b/sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtServiceTest.java
index f3f836a312b..b0a1cd61cb2 100644
--- a/sonar-server/src/test/java/org/sonar/server/technicaldebt/InternalRubyTechnicalDebtServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/technicaldebt/DebtServiceTest.java
@@ -19,11 +19,7 @@
*/
package org.sonar.server.technicaldebt;
-import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.api.issue.internal.WorkDayDuration;
import org.sonar.api.rules.Rule;
import org.sonar.api.technicaldebt.server.Characteristic;
@@ -37,30 +33,19 @@ import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
-public class InternalRubyTechnicalDebtServiceTest {
+public class DebtServiceTest {
- @Mock
- TechnicalDebtFormatter technicalDebtFormatter;
-
- @Mock
- DefaultTechnicalDebtManager finder;
-
- private InternalRubyTechnicalDebtService service;
-
- @Before
- public void before() {
- service = new InternalRubyTechnicalDebtService(technicalDebtFormatter, finder);
- }
+ DebtFormatter debtFormatter = mock(DebtFormatter.class);
+ DefaultTechnicalDebtManager finder = mock(DefaultTechnicalDebtManager.class);
+ DebtService service = new DebtService(debtFormatter, finder);
@Test
public void format() {
WorkDayDuration technicalDebt = WorkDayDuration.of(5, 0, 0);
service.format(technicalDebt);
- verify(technicalDebtFormatter).format(any(Locale.class), eq(technicalDebt));
+ verify(debtFormatter).format(any(Locale.class), eq(technicalDebt));
}
@Test
diff --git a/sonar-server/src/test/java/org/sonar/server/ui/CompatibilityRealmTest.java b/sonar-server/src/test/java/org/sonar/server/user/CompatibilityRealmTest.java
index 3b68e4c24d8..ee47aeaedda 100644
--- a/sonar-server/src/test/java/org/sonar/server/ui/CompatibilityRealmTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/user/CompatibilityRealmTest.java
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.server.ui;
+package org.sonar.server.user;
import org.junit.Test;
import org.sonar.api.security.LoginPasswordAuthenticator;
diff --git a/sonar-server/src/test/java/org/sonar/server/group/GroupMembershipFinderTest.java b/sonar-server/src/test/java/org/sonar/server/user/GroupMembershipFinderTest.java
index 874d9f11957..2b4eff37486 100644
--- a/sonar-server/src/test/java/org/sonar/server/group/GroupMembershipFinderTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/user/GroupMembershipFinderTest.java
@@ -18,31 +18,24 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.server.group;
+package org.sonar.server.user;
import org.junit.Before;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.runners.MockitoJUnitRunner;
import org.sonar.core.user.*;
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyLong;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
-@RunWith(MockitoJUnitRunner.class)
public class GroupMembershipFinderTest {
- @Mock
- UserDao userDao;
-
- @Mock
- GroupMembershipDao groupMembershipDao;
-
+ UserDao userDao = mock(UserDao.class);
+ GroupMembershipDao groupMembershipDao = mock(GroupMembershipDao.class);
GroupMembershipFinder finder;
@Before
@@ -58,7 +51,7 @@ public class GroupMembershipFinderTest {
newArrayList(new GroupMembershipDto().setId(1L).setName("users").setUserId(100L))
);
- GroupMembershipQueryResult result = finder.find(query);
+ GroupMembershipFinder.Membership result = finder.find(query);
assertThat(result.groups()).hasSize(1);
assertThat(result.hasMoreResults()).isFalse();
@@ -89,7 +82,7 @@ public class GroupMembershipFinderTest {
new GroupMembershipDto().setId(2L).setName("group2"),
new GroupMembershipDto().setId(3L).setName("group3"))
);
- GroupMembershipQueryResult result = finder.find(query);
+ GroupMembershipFinder.Membership result = finder.find(query);
ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class);
ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class);
@@ -109,7 +102,7 @@ public class GroupMembershipFinderTest {
new GroupMembershipDto().setId(3L).setName("group3"),
new GroupMembershipDto().setId(4L).setName("group4"))
);
- GroupMembershipQueryResult result = finder.find(query);
+ GroupMembershipFinder.Membership result = finder.find(query);
ArgumentCaptor<Integer> argumentOffset = ArgumentCaptor.forClass(Integer.class);
ArgumentCaptor<Integer> argumentLimit = ArgumentCaptor.forClass(Integer.class);
diff --git a/sonar-server/src/test/java/org/sonar/server/group/InternalGroupMembershipServiceTest.java b/sonar-server/src/test/java/org/sonar/server/user/GroupMembershipServiceTest.java
index aa687691be5..ff99af0f694 100644
--- a/sonar-server/src/test/java/org/sonar/server/group/InternalGroupMembershipServiceTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/user/GroupMembershipServiceTest.java
@@ -18,7 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.server.group;
+package org.sonar.server.user;
import com.google.common.collect.ImmutableMap;
import org.junit.Before;
@@ -37,23 +37,23 @@ import static org.fest.assertions.Fail.fail;
/**
* Use BbUnit tests because there's no IT on this feature for the moment
*/
-public class InternalGroupMembershipServiceTest extends AbstractDaoTestCase {
+public class GroupMembershipServiceTest extends AbstractDaoTestCase {
- private InternalGroupMembershipService service;
+ GroupMembershipService service;
@Before
public void before() throws Exception {
- GroupMembershipDao groupMembershipDao = new GroupMembershipDao(getMyBatis());
+ GroupMembershipDao membershipDao = new GroupMembershipDao(getMyBatis());
UserDao userDao = new UserDao(getMyBatis());
- GroupMembershipFinder finder = new GroupMembershipFinder(userDao, groupMembershipDao);
- service = new InternalGroupMembershipService(finder);
+ GroupMembershipFinder finder = new GroupMembershipFinder(userDao, membershipDao);
+ service = new GroupMembershipService(finder);
}
@Test
public void find_all_member_groups() {
setupData("shared");
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
"user", "user1",
"selected", "all"));
List<GroupMembership> result = queryResult.groups();
@@ -67,7 +67,7 @@ public class InternalGroupMembershipServiceTest extends AbstractDaoTestCase {
public void find_all_member_groups_when_no_selected_parameter() {
setupData("shared");
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
"user", "user1"));
List<GroupMembership> result = queryResult.groups();
assertThat(result).hasSize(3);
@@ -80,7 +80,7 @@ public class InternalGroupMembershipServiceTest extends AbstractDaoTestCase {
public void find_member_groups() {
setupData("shared");
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
"user", "user1",
"selected", "selected"));
List<GroupMembership> result = queryResult.groups();
@@ -92,7 +92,7 @@ public class InternalGroupMembershipServiceTest extends AbstractDaoTestCase {
public void find_not_member_groups() {
setupData("shared");
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
"user", "user1",
"selected", "deselected"));
List<GroupMembership> result = queryResult.groups();
@@ -105,7 +105,7 @@ public class InternalGroupMembershipServiceTest extends AbstractDaoTestCase {
public void find_with_paging_with_more_results() {
setupData("shared");
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
"user", "user1",
"selected", "all",
"page", 1,
@@ -120,7 +120,7 @@ public class InternalGroupMembershipServiceTest extends AbstractDaoTestCase {
public void find_with_paging_with_no_more_results() {
setupData("shared");
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
"user", "user1",
"selected", "all",
"page", 3,
@@ -149,7 +149,7 @@ public class InternalGroupMembershipServiceTest extends AbstractDaoTestCase {
public void find_matched_groups_name() {
setupData("shared");
- GroupMembershipQueryResult queryResult = service.find(ImmutableMap.<String, Object>of(
+ GroupMembershipFinder.Membership queryResult = service.find(ImmutableMap.<String, Object>of(
"user", "user1",
"selected", "all",
"query", "user"));
diff --git a/sonar-server/src/test/java/org/sonar/server/ui/SecurityRealmFactoryTest.java b/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java
index c2e134f9d5c..70bd0be1b7f 100644
--- a/sonar-server/src/test/java/org/sonar/server/ui/SecurityRealmFactoryTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/user/SecurityRealmFactoryTest.java
@@ -17,9 +17,8 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
-package org.sonar.server.ui;
+package org.sonar.server.user;
-import org.junit.Before;
import org.junit.Test;
import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
@@ -27,23 +26,14 @@ import org.sonar.api.security.LoginPasswordAuthenticator;
import org.sonar.api.security.SecurityRealm;
import org.sonar.api.utils.SonarException;
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.instanceOf;
-import static org.hamcrest.Matchers.is;
-import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.assertThat;
+import static org.fest.assertions.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
public class SecurityRealmFactoryTest {
- private Settings settings;
-
- @Before
- public void setUp() {
- settings = new Settings();
- }
+ Settings settings = new Settings();
/**
* Typical usage.
@@ -55,7 +45,7 @@ public class SecurityRealmFactoryTest {
SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[]{realm});
factory.start();
- assertThat(factory.getRealm(), is(realm));
+ assertThat(factory.getRealm()).isSameAs(realm);
verify(realm).init();
}
@@ -63,7 +53,7 @@ public class SecurityRealmFactoryTest {
public void do_not_fail_if_no_realms() {
SecurityRealmFactory factory = new SecurityRealmFactory(settings);
factory.start();
- assertThat(factory.getRealm(), nullValue());
+ assertThat(factory.getRealm()).isNull();
}
@Test
@@ -74,7 +64,7 @@ public class SecurityRealmFactoryTest {
new SecurityRealmFactory(settings);
fail();
} catch (SonarException e) {
- assertThat(e.getMessage(), containsString("Realm 'Fake' not found."));
+ assertThat(e.getMessage()).contains("Realm 'Fake' not found.");
}
}
@@ -85,7 +75,7 @@ public class SecurityRealmFactoryTest {
SecurityRealmFactory factory = new SecurityRealmFactory(settings, new LoginPasswordAuthenticator[]{authenticator});
SecurityRealm realm = factory.getRealm();
- assertThat(realm, instanceOf(CompatibilityRealm.class));
+ assertThat(realm).isInstanceOf(CompatibilityRealm.class);
}
@Test
@@ -96,8 +86,8 @@ public class SecurityRealmFactoryTest {
settings.setProperty(CoreProperties.CORE_AUTHENTICATOR_CLASS, FakeAuthenticator.class.getName());
SecurityRealmFactory factory = new SecurityRealmFactory(settings, new SecurityRealm[]{realm},
- new LoginPasswordAuthenticator[]{authenticator});
- assertThat(factory.getRealm(), is(realm));
+ new LoginPasswordAuthenticator[]{authenticator});
+ assertThat(factory.getRealm()).isSameAs(realm);
}
@Test
@@ -108,7 +98,7 @@ public class SecurityRealmFactoryTest {
new SecurityRealmFactory(settings);
fail();
} catch (SonarException e) {
- assertThat(e.getMessage(), containsString("Authenticator 'Fake' not found."));
+ assertThat(e.getMessage()).contains("Authenticator 'Fake' not found.");
}
}
@@ -131,8 +121,8 @@ public class SecurityRealmFactoryTest {
new SecurityRealmFactory(settings, new SecurityRealm[]{realm}).start();
fail();
} catch (SonarException e) {
- assertThat(e.getCause(), instanceOf(IllegalStateException.class));
- assertThat(e.getMessage(), containsString("Security realm fails to start"));
+ assertThat(e.getCause()).isInstanceOf(IllegalStateException.class);
+ assertThat(e.getMessage()).contains("Security realm fails to start");
}
}
diff --git a/sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java b/sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java
index 0ca4143ddea..f17386c287f 100644
--- a/sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/ws/WebServiceEngineTest.java
@@ -30,6 +30,7 @@ import org.sonar.api.server.ws.Response;
import org.sonar.api.server.ws.WebService;
import org.sonar.api.utils.text.JsonWriter;
import org.sonar.api.utils.text.XmlWriter;
+import org.sonar.server.plugins.MimeTypes;
import javax.annotation.CheckForNull;
@@ -187,7 +188,7 @@ public class WebServiceEngineTest {
assertThat(response.stream().outputAsString()).isEqualTo("{\"errors\":[{\"msg\":\"Unexpected\"}]}");
assertThat(response.stream().httpStatus()).isEqualTo(500);
- assertThat(response.stream().mediaType()).isEqualTo("application/json");
+ assertThat(response.stream().mediaType()).isEqualTo(MimeTypes.JSON);
}
static class SystemWebService implements WebService {