diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-03-27 09:11:23 +0100 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2015-03-27 09:11:23 +0100 |
commit | 8218494577a870ae3ef81997f3a17da50d199403 (patch) | |
tree | 34772d48c200d0ba506db3b11683425138bf89eb /server | |
parent | a91e8653a48236e9a55228755455ac5868e059ae (diff) | |
download | sonarqube-8218494577a870ae3ef81997f3a17da50d199403.tar.gz sonarqube-8218494577a870ae3ef81997f3a17da50d199403.zip |
Fix quality flaws
Diffstat (limited to 'server')
6 files changed, 22 insertions, 32 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddNewCharacteristics.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddNewCharacteristics.java index 9b66e70a07e..ffc4a1103c0 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddNewCharacteristics.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/AddNewCharacteristics.java @@ -31,6 +31,7 @@ import org.sonar.server.db.migrations.Select; import javax.annotation.CheckForNull; import javax.annotation.Nullable; + import java.sql.SQLException; import java.util.Date; import java.util.List; @@ -269,11 +270,16 @@ public class AddNewCharacteristics extends BaseDataChange { } private int selectCharacteristicId(String key) throws SQLException { - return context.prepareSelect( + Long id = context.prepareSelect( "SELECT c.id FROM characteristics c WHERE c.kee = ? AND c.enabled=?") .setString(1, key) .setBoolean(2, true) - .get(Select.LONG_READER).intValue(); + .get(Select.LONG_READER); + if (id != null) { + return id.intValue(); + } else { + throw new IllegalStateException(String.format("Characteristic '%s' could not be inserted", key)); + } } public void insertCharacteristic(Characteristic characteristic) throws SQLException { diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDates.java index 81a690a38e9..6573c1f6baa 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDates.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedIssuesLongDates.java @@ -28,6 +28,7 @@ import org.sonar.server.db.migrations.Select; import org.sonar.server.db.migrations.SqlStatement; import java.sql.SQLException; +import java.util.Date; public class FeedIssuesLongDates extends BaseDataChange { @@ -51,7 +52,8 @@ public class FeedIssuesLongDates extends BaseDataChange { @Override public boolean handle(Select.Row row, SqlStatement update) throws SQLException { for (int i = 1; i <= 3; i++) { - update.setLong(i, row.getNullableDate(i) == null ? null : Math.min(now, row.getNullableDate(i).getTime())); + Date date = row.getNullableDate(i); + update.setLong(i, date == null ? null : Math.min(now, date.getTime())); } Long id = row.getNullableLong(4); diff --git a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDates.java b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDates.java index 2897eb7dd1d..dc2f6de26df 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDates.java +++ b/server/sonar-server/src/main/java/org/sonar/server/db/migrations/v51/FeedSnapshotsLongDates.java @@ -28,6 +28,7 @@ import org.sonar.server.db.migrations.Select; import org.sonar.server.db.migrations.SqlStatement; import java.sql.SQLException; +import java.util.Date; public class FeedSnapshotsLongDates extends BaseDataChange { @@ -51,7 +52,8 @@ public class FeedSnapshotsLongDates extends BaseDataChange { @Override public boolean handle(Select.Row row, SqlStatement update) throws SQLException { for (int i = 1; i <= 7; i++) { - update.setLong(i, row.getNullableDate(i) == null ? null : Math.min(now, row.getNullableDate(i).getTime())); + Date date = row.getNullableDate(i); + update.setLong(i, date == null ? null : Math.min(now, date.getTime())); } Long id = row.getNullableLong(8); diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index d6c8f06dd75..f9950cad550 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -38,7 +38,6 @@ import org.sonar.api.web.UserRole; import org.sonar.core.component.ComponentDto; import org.sonar.core.issue.DefaultIssueBuilder; import org.sonar.core.issue.IssueUpdater; -import org.sonar.core.issue.db.IssueDao; import org.sonar.core.issue.db.IssueDto; import org.sonar.core.issue.db.IssueStorage; import org.sonar.core.issue.workflow.IssueWorkflow; @@ -60,12 +59,8 @@ import org.sonar.server.user.index.UserIndex; import javax.annotation.CheckForNull; import javax.annotation.Nullable; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; + +import java.util.*; public class IssueService implements ServerComponent { @@ -78,7 +73,6 @@ public class IssueService implements ServerComponent { private final NotificationManager notificationService; private final ActionPlanService actionPlanService; private final RuleFinder ruleFinder; - private final IssueDao deprecatedIssueDao; private final UserFinder userFinder; private final UserIndex userIndex; private final SourceLineIndex sourceLineIndex; @@ -90,7 +84,6 @@ public class IssueService implements ServerComponent { NotificationManager notificationService, ActionPlanService actionPlanService, RuleFinder ruleFinder, - IssueDao deprecatedIssueDao, UserFinder userFinder, UserIndex userIndex, SourceLineIndex sourceLineIndex) { this.dbClient = dbClient; @@ -101,7 +94,6 @@ public class IssueService implements ServerComponent { this.actionPlanService = actionPlanService; this.ruleFinder = ruleFinder; this.notificationService = notificationService; - this.deprecatedIssueDao = deprecatedIssueDao; this.userFinder = userFinder; this.userIndex = userIndex; this.sourceLineIndex = sourceLineIndex; diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/SourceService.java b/server/sonar-server/src/main/java/org/sonar/server/source/SourceService.java index 581df02b837..b9877861a35 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/SourceService.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/SourceService.java @@ -23,7 +23,6 @@ package org.sonar.server.source; import org.apache.commons.lang.ObjectUtils; import org.elasticsearch.common.collect.Lists; import org.sonar.api.ServerComponent; -import org.sonar.server.db.DbClient; import org.sonar.server.source.index.SourceLineDoc; import org.sonar.server.source.index.SourceLineIndex; @@ -33,12 +32,10 @@ import java.util.List; public class SourceService implements ServerComponent { - private final DbClient dbClient; private final HtmlSourceDecorator sourceDecorator; private final SourceLineIndex sourceLineIndex; - public SourceService(DbClient dbClient, HtmlSourceDecorator sourceDecorator, SourceLineIndex sourceLineIndex) { - this.dbClient = dbClient; + public SourceService(HtmlSourceDecorator sourceDecorator, SourceLineIndex sourceLineIndex) { this.sourceDecorator = sourceDecorator; this.sourceLineIndex = sourceLineIndex; } diff --git a/server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java b/server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java index 100348abe6c..67cc7e51b49 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/source/SourceServiceTest.java @@ -25,19 +25,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.runners.MockitoJUnitRunner; -import org.sonar.api.web.UserRole; -import org.sonar.core.persistence.DbSession; -import org.sonar.server.db.DbClient; import org.sonar.server.measure.persistence.MeasureDao; import org.sonar.server.source.index.SourceLineDoc; import org.sonar.server.source.index.SourceLineIndex; -import org.sonar.server.user.MockUserSession; import java.util.Arrays; import java.util.List; 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.when; @@ -46,27 +41,25 @@ public class SourceServiceTest { static final String PROJECT_KEY = "org.sonar.sample"; static final String COMPONENT_UUID = "abc123"; - @Mock - DbSession session; + @Mock HtmlSourceDecorator sourceDecorator; + @Mock MeasureDao measureDao; + @Mock SourceLineIndex sourceLineIndex; + SourceService service; @Before public void setUp() throws Exception { - DbClient dbClient = mock(DbClient.class); - when(dbClient.openSession(false)).thenReturn(session); - when(dbClient.measureDao()).thenReturn(measureDao); - service = new SourceService(dbClient, sourceDecorator, sourceLineIndex); + service = new SourceService(sourceDecorator, sourceLineIndex); } @Test public void get_html_lines() throws Exception { - MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, PROJECT_KEY, COMPONENT_UUID); when(sourceLineIndex.getLines(COMPONENT_UUID, 1, Integer.MAX_VALUE)).thenReturn( Arrays.asList(new SourceLineDoc().setSource("source").setHighlighting("highlight").setSymbols("symbols"))); @@ -77,7 +70,6 @@ public class SourceServiceTest { @Test public void get_block_of_lines() throws Exception { - MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, PROJECT_KEY, COMPONENT_UUID); when(sourceLineIndex.getLines(COMPONENT_UUID, 1, Integer.MAX_VALUE)).thenReturn( Arrays.asList(new SourceLineDoc().setSource("source").setHighlighting("highlight").setSymbols("symbols"), @@ -91,7 +83,6 @@ public class SourceServiceTest { @Test public void getLinesAsTxt() throws Exception { - MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, PROJECT_KEY, COMPONENT_UUID); when(sourceLineIndex.getLines(COMPONENT_UUID, 1, Integer.MAX_VALUE)).thenReturn( Arrays.asList( new SourceLineDoc().setSource("line1"), |