diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-11-23 22:01:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-23 22:01:21 +0100 |
commit | 4eb8c7f8657ebe5544fcd2283145d175713ab567 (patch) | |
tree | dd9e4078d15e052578874234bbb3761e20a448e4 /server | |
parent | e02d9d4a80eeb4f5cff53dd057e86df2c48d4f7e (diff) | |
download | sonarqube-4eb8c7f8657ebe5544fcd2283145d175713ab567.tar.gz sonarqube-4eb8c7f8657ebe5544fcd2283145d175713ab567.zip |
Support build of SonarQube with JDK 9
Diffstat (limited to 'server')
14 files changed, 49 insertions, 110 deletions
diff --git a/server/sonar-ce/pom.xml b/server/sonar-ce/pom.xml index 301c2cb31f4..42dc89d5de0 100644 --- a/server/sonar-ce/pom.xml +++ b/server/sonar-ce/pom.xml @@ -53,12 +53,6 @@ <scope>test</scope> </dependency> <dependency> - <!-- TODO to be removed --> - <groupId>org.hamcrest</groupId> - <artifactId>hamcrest-all</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <scope>test</scope> diff --git a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java index 74b2a9503f7..753928597ed 100644 --- a/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java +++ b/server/sonar-ce/src/test/java/org/sonar/ce/queue/InternalCeQueueImplTest.java @@ -19,23 +19,13 @@ */ package org.sonar.ce.queue; -import static com.google.common.base.Preconditions.checkArgument; -import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.sonar.ce.container.ComputeEngineStatus.Status.STARTED; -import static org.sonar.ce.container.ComputeEngineStatus.Status.STOPPING; - +import com.google.common.collect.ImmutableSet; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.List; import java.util.Optional; import java.util.Random; - import javax.annotation.Nullable; - -import org.hamcrest.Matchers; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -59,7 +49,13 @@ import org.sonar.server.computation.task.step.TypedException; import org.sonar.server.organization.DefaultOrganization; import org.sonar.server.organization.DefaultOrganizationProvider; -import com.google.common.collect.ImmutableSet; +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.sonar.ce.container.ComputeEngineStatus.Status.STARTED; +import static org.sonar.ce.container.ComputeEngineStatus.Status.STOPPING; public class InternalCeQueueImplTest { @@ -531,7 +527,7 @@ public class InternalCeQueueImplTest { CeQueueDto queueDto = db.getDbClient().ceQueueDao().selectByUuid(db.getSession(), task.getUuid()).get(); expectedException.expect(IllegalStateException.class); - expectedException.expectMessage(Matchers.startsWith("Task is in progress and can't be canceled")); + expectedException.expectMessage("Task is in progress and can't be canceled"); underTest.cancel(db.getSession(), queueDto); } diff --git a/server/sonar-db-dao/pom.xml b/server/sonar-db-dao/pom.xml index 8d308644fdd..f76bb60e10b 100644 --- a/server/sonar-db-dao/pom.xml +++ b/server/sonar-db-dao/pom.xml @@ -44,12 +44,6 @@ <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> diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/MyBatisTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/MyBatisTest.java index b8639017123..999b160843e 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/MyBatisTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/MyBatisTest.java @@ -27,7 +27,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.sonar.db.rule.RuleMapper; -import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.CoreMatchers.notNullValue; import static org.junit.Assert.assertThat; public class MyBatisTest { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java index 0295573904c..c163cb29b9d 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/AnalysisPropertiesDaoTest.java @@ -157,7 +157,7 @@ public class AnalysisPropertiesDaoTest { assertThat(dbTester.countRowsOfTable(dbSession, "ANALYSIS_PROPERTIES")).isEqualTo(propertyDtos.size()); List<AnalysisPropertyDto> result = underTest.selectBySnapshotUuid(dbSession, snapshotUuid); - assertThat(result).containsExactlyInAnyOrder((AnalysisPropertyDto[]) propertyDtos.toArray()); + assertThat(result).containsExactlyInAnyOrder(propertyDtos.toArray(new AnalysisPropertyDto[0])); } private AnalysisPropertyDto insertAnalysisPropertyDto(int valueLength) { diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeableAnalysisDtoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeableAnalysisDtoTest.java index eb4a558fb17..de605579469 100644 --- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeableAnalysisDtoTest.java +++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeableAnalysisDtoTest.java @@ -23,9 +23,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; public class PurgeableAnalysisDtoTest { @Rule @@ -35,18 +33,18 @@ public class PurgeableAnalysisDtoTest { public void testEquals() { PurgeableAnalysisDto dto1 = new PurgeableAnalysisDto().setAnalysisUuid("u3"); PurgeableAnalysisDto dto2 = new PurgeableAnalysisDto().setAnalysisUuid("u4"); - assertThat(dto1.equals(dto2), is(false)); - assertThat(dto2.equals(dto1), is(false)); - assertThat(dto1.equals(dto1), is(true)); - assertThat(dto1.equals(new PurgeableAnalysisDto().setAnalysisUuid("u3")), is(true)); - assertThat(dto1.equals("bi_bop_a_lou_la"), is(false)); - assertThat(dto1.equals(null), is(false)); + assertThat(dto1.equals(dto2)).isFalse(); + assertThat(dto2.equals(dto1)).isFalse(); + assertThat(dto1.equals(dto1)).isTrue(); + assertThat(dto1.equals(new PurgeableAnalysisDto().setAnalysisUuid("u3"))).isTrue(); + assertThat(dto1.equals("bi_bop_a_lou_la")).isFalse(); + assertThat(dto1.equals(null)).isFalse(); } @Test public void testHasCode() { PurgeableAnalysisDto dto = new PurgeableAnalysisDto().setAnalysisUuid("u3"); - assertThat(dto.hashCode(), is(dto.hashCode())); + assertThat(dto.hashCode()).isEqualTo(dto.hashCode()); // no uuid => NPE dto = new PurgeableAnalysisDto(); @@ -58,6 +56,6 @@ public class PurgeableAnalysisDtoTest { @Test public void testToString() { PurgeableAnalysisDto dto = new PurgeableAnalysisDto().setAnalysisUuid("u3"); - assertThat(dto.toString().length(), greaterThan(0)); + assertThat(dto.toString()).isNotEmpty(); } } diff --git a/server/sonar-server/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java b/server/sonar-server/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java index e49d5a9b784..95da611ad59 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java +++ b/server/sonar-server/src/main/java/org/sonar/server/permission/index/PermissionIndexerDao.java @@ -198,7 +198,7 @@ public class PermissionIndexerDao { if (projectUuids.isEmpty()) { sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", ""); } else { - sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", " AND (" + repeat("projects.uuid = ?", " or ", projectUuids.size()) + ")"); + sql = StringUtils.replace(SQL_TEMPLATE, "{projectsCondition}", " AND projects.uuid in (" + repeat("?", ", ", projectUuids.size()) + ")"); } PreparedStatement stmt = dbClient.getMyBatis().newScrollingSelectStatement(session, sql); int index = 1; diff --git a/server/sonar-server/src/test/java/org/sonar/elasticsearch/test/EsTestCluster.java b/server/sonar-server/src/test/java/org/sonar/elasticsearch/test/EsTestCluster.java index 91d403e4d37..c7287a7058a 100644 --- a/server/sonar-server/src/test/java/org/sonar/elasticsearch/test/EsTestCluster.java +++ b/server/sonar-server/src/test/java/org/sonar/elasticsearch/test/EsTestCluster.java @@ -100,7 +100,7 @@ import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; import org.junit.Assert; -import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; import static org.junit.Assert.fail; diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java index 5c9c31fd772..3d407a1477b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/AddTagsActionTest.java @@ -20,53 +20,40 @@ package org.sonar.server.issue; import com.google.common.collect.ImmutableSet; -import java.util.Collection; +import java.util.HashMap; import java.util.Map; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.Mockito; import org.sonar.core.issue.DefaultIssue; -import org.sonar.core.issue.IssueChangeContext; -import static com.google.common.collect.Maps.newHashMap; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; public class AddTagsActionTest { - private AddTagsAction action; - - private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class); - @Rule public ExpectedException throwable = ExpectedException.none(); - @Before - public void before() { - action = new AddTagsAction(issueUpdater); - } + private IssueFieldsSetter issueUpdater = new IssueFieldsSetter(); + private AddTagsAction underTest = new AddTagsAction(issueUpdater); @Test @SuppressWarnings("unchecked") public void should_execute() { - Map<String, Object> properties = newHashMap(); + Map<String, Object> properties = new HashMap<>(); properties.put("tags", "tag2,tag3"); DefaultIssue issue = mock(DefaultIssue.class); when(issue.tags()).thenReturn(ImmutableSet.of("tag1", "tag3")); - Action.Context context = mock(Action.Context.class); + Action.Context context = mock(Action.Context.class, Mockito.RETURNS_DEEP_STUBS); when(context.issue()).thenReturn(issue); - action.execute(properties, context); - verify(issueUpdater).setTags(eq(issue), - (Collection<String>) Matchers.argThat(org.hamcrest.Matchers.containsInAnyOrder("tag1", "tag2", "tag3")), - any(IssueChangeContext.class)); + underTest.execute(properties, context); + verify(issue).setTags(ImmutableSet.of("tag1", "tag2", "tag3")); } @Test @@ -74,7 +61,7 @@ public class AddTagsActionTest { throwable.expect(IllegalArgumentException.class); throwable.expectMessage("Tag 'th ag' is invalid. Rule tags accept only the characters: a-z, 0-9, '+', '-', '#', '.'"); - Map<String, Object> properties = newHashMap(); + Map<String, Object> properties = new HashMap<>(); properties.put("tags", "th ag"); DefaultIssue issue = mock(DefaultIssue.class); @@ -83,6 +70,6 @@ public class AddTagsActionTest { Action.Context context = mock(Action.Context.class); when(context.issue()).thenReturn(issue); - action.execute(properties, context); + underTest.execute(properties, context); } } diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java index fddefaa2f25..c81a2fdc2e8 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/RemoveTagsActionTest.java @@ -20,36 +20,25 @@ package org.sonar.server.issue; import com.google.common.collect.ImmutableSet; -import java.util.Collection; import java.util.Map; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.mockito.Matchers; +import org.mockito.Mockito; import org.sonar.core.issue.DefaultIssue; -import org.sonar.core.issue.IssueChangeContext; import static com.google.common.collect.Maps.newHashMap; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; public class RemoveTagsActionTest { - private RemoveTagsAction action; - - private IssueFieldsSetter issueUpdater = mock(IssueFieldsSetter.class); - @Rule public ExpectedException throwable = ExpectedException.none(); - @Before - public void before() { - action = new RemoveTagsAction(issueUpdater); - } + private IssueFieldsSetter issueUpdater = new IssueFieldsSetter(); + private RemoveTagsAction action = new RemoveTagsAction(issueUpdater); @Test @SuppressWarnings("unchecked") @@ -60,13 +49,11 @@ public class RemoveTagsActionTest { DefaultIssue issue = mock(DefaultIssue.class); when(issue.tags()).thenReturn(ImmutableSet.of("tag1", "tag3")); - Action.Context context = mock(Action.Context.class); + Action.Context context = mock(Action.Context.class, Mockito.RETURNS_DEEP_STUBS); when(context.issue()).thenReturn(issue); action.execute(properties, context); - verify(issueUpdater).setTags(eq(issue), - (Collection<String>) Matchers.argThat(org.hamcrest.Matchers.containsInAnyOrder("tag1")), - any(IssueChangeContext.class)); + verify(issue).setTags(ImmutableSet.of("tag1")); } @Test diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDispatcherTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDispatcherTest.java index 8b2f1bc150c..fed6d37ab6d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDispatcherTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notification/NotificationDispatcherTest.java @@ -26,7 +26,7 @@ import org.mockito.MockitoAnnotations; import org.sonar.api.notifications.Notification; import org.sonar.api.notifications.NotificationChannel; -import static org.hamcrest.Matchers.is; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; diff --git a/server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java b/server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java index 0384a8f5747..33fabe367f1 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/notification/email/AlertsEmailTemplateTest.java @@ -25,8 +25,8 @@ import org.sonar.api.config.EmailSettings; import org.sonar.api.notifications.Notification; import org.sonar.plugins.emailnotifications.api.EmailMessage; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/DeprecatedUserFinderTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/DeprecatedUserFinderTest.java index 32414882dc1..f967be7f164 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/DeprecatedUserFinderTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/DeprecatedUserFinderTest.java @@ -26,8 +26,8 @@ import org.sonar.api.database.model.User; import org.sonar.api.utils.System2; import org.sonar.db.DbTester; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertThat; diff --git a/server/sonar-server/src/test/java/org/sonar/server/user/UserSessionFilterTest.java b/server/sonar-server/src/test/java/org/sonar/server/user/UserSessionFilterTest.java index 79ef9e2d898..039d391c529 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/user/UserSessionFilterTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/user/UserSessionFilterTest.java @@ -28,7 +28,7 @@ import javax.servlet.http.HttpServletResponse; import org.junit.Before; import org.junit.Test; import org.mockito.InOrder; -import org.mockito.Mockito; +import org.sonar.core.platform.ComponentContainer; import org.sonar.db.DBSessions; import org.sonar.server.authentication.UserSessionInitializer; import org.sonar.server.organization.DefaultOrganizationCache; @@ -48,7 +48,8 @@ import static org.mockito.Mockito.when; public class UserSessionFilterTest { private UserSessionInitializer userSessionInitializer = mock(UserSessionInitializer.class); - private Platform platform = mock(Platform.class, Mockito.RETURNS_DEEP_STUBS); + private ComponentContainer container = new ComponentContainer(); + private Platform platform = mock(Platform.class); private HttpServletRequest request = mock(HttpServletRequest.class); private HttpServletResponse response = mock(HttpServletResponse.class); private FilterChain chain = mock(FilterChain.class); @@ -59,9 +60,8 @@ public class UserSessionFilterTest { @Before public void setUp() { - when(platform.getContainer().getComponentByType(DBSessions.class)).thenReturn(dbSessions); - when(platform.getContainer().getComponentByType(ThreadLocalSettings.class)).thenReturn(settings); - when(platform.getContainer().getComponentByType(DefaultOrganizationCache.class)).thenReturn(defaultOrganizationCache); + container.add(dbSessions, settings, defaultOrganizationCache); + when(platform.getContainer()).thenReturn(container); } @Test @@ -86,8 +86,6 @@ public class UserSessionFilterTest { @Test public void does_nothing_when_not_initialized() throws Exception { - mockNoUserSessionInitializer(); - underTest.doFilter(request, response, chain); verify(chain).doFilter(request, response); @@ -96,8 +94,6 @@ public class UserSessionFilterTest { @Test public void doFilter_loads_and_unloads_settings() throws Exception { - mockNoUserSessionInitializer(); - underTest.doFilter(request, response, chain); InOrder inOrder = inOrder(settings); @@ -108,7 +104,6 @@ public class UserSessionFilterTest { @Test public void doFilter_unloads_Settings_even_if_chain_throws_exception() throws Exception { - mockNoUserSessionInitializer(); RuntimeException thrown = mockChainDoFilterError(); try { @@ -122,8 +117,6 @@ public class UserSessionFilterTest { @Test public void doFilter_enables_and_disables_caching_in_DbSessions() throws Exception { - mockNoUserSessionInitializer(); - underTest.doFilter(request, response, chain); InOrder inOrder = inOrder(dbSessions); @@ -134,7 +127,6 @@ public class UserSessionFilterTest { @Test public void doFilter_disables_caching_in_DbSessions_even_if_chain_throws_exception() throws Exception { - mockNoUserSessionInitializer(); RuntimeException thrown = mockChainDoFilterError(); try { @@ -148,7 +140,6 @@ public class UserSessionFilterTest { @Test public void doFilter_unloads_Settings_even_if_DefaultOrganizationCache_unload_fails() throws Exception { - mockNoUserSessionInitializer(); RuntimeException thrown = new RuntimeException("Faking DefaultOrganizationCache.unload failing"); doThrow(thrown) .when(defaultOrganizationCache) @@ -178,8 +169,6 @@ public class UserSessionFilterTest { @Test public void doFilter_loads_and_unloads_DefaultOrganizationCache() throws Exception { - mockNoUserSessionInitializer(); - underTest.doFilter(request, response, chain); InOrder inOrder = inOrder(defaultOrganizationCache); @@ -190,7 +179,6 @@ public class UserSessionFilterTest { @Test public void doFilter_unloads_DefaultOrganizationCache_even_if_chain_throws_exception() throws Exception { - mockNoUserSessionInitializer(); RuntimeException thrown = mockChainDoFilterError(); try { @@ -204,7 +192,6 @@ public class UserSessionFilterTest { @Test public void doFilter_unloads_DefaultOrganizationCache_even_if_Settings_unload_fails() throws Exception { - mockNoUserSessionInitializer(); RuntimeException thrown = new RuntimeException("Faking Settings.unload failing"); doThrow(thrown) .when(settings) @@ -240,17 +227,13 @@ public class UserSessionFilterTest { // do not fail } - private void mockNoUserSessionInitializer() { - when(platform.getContainer().getComponentByType(UserSessionInitializer.class)).thenReturn(null); - } - private void mockUserSessionInitializer(boolean value) { - when(platform.getContainer().getComponentByType(UserSessionInitializer.class)).thenReturn(userSessionInitializer); + container.add(userSessionInitializer); when(userSessionInitializer.initUserSession(request, response)).thenReturn(value); } private RuntimeException mockUserSessionInitializerRemoveUserSessionFailing() { - when(platform.getContainer().getComponentByType(UserSessionInitializer.class)).thenReturn(userSessionInitializer); + container.add(userSessionInitializer); RuntimeException thrown = new RuntimeException("Faking UserSessionInitializer.removeUserSession failing"); doThrow(thrown) .when(userSessionInitializer) |