From: David Gageot Date: Wed, 23 May 2012 20:11:53 +0000 (+0200) Subject: Fix violations, simplify code and improve documentation X-Git-Tag: 3.1~93 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fe9e4f3eea867948e25642c24d0ff376907a3f2a;p=sonarqube.git Fix violations, simplify code and improve documentation --- diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java index 8fa44b14fbb..7230e87f561 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java @@ -116,7 +116,7 @@ public class BatchExtensionInstallerTest { @Override public Object provide() { - return Arrays.asList(BatchService.class, ServerService.class); + return Arrays. asList(BatchService.class, ServerService.class); } } diff --git a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibilityTest.java b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibilityTest.java index 4c023921487..eb2c719a8ee 100644 --- a/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibilityTest.java +++ b/sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibilityTest.java @@ -110,7 +110,7 @@ public class DatabaseBatchCompatibilityTest { @Test public void shouldFailIfCantGetServerId() throws Exception { - when(remoteServerMetadata.getServerId()).thenThrow(IOException.class); + when(remoteServerMetadata.getServerId()).thenThrow(new IOException()); thrown.expect(SonarException.class); thrown.expectMessage("Impossible to get the ID of the remote server: http://localhost:9000"); diff --git a/sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java b/sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java index 02fc0d04a54..936af6d3572 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java @@ -23,7 +23,6 @@ package org.sonar.core.filter; * @since 3.1 */ public final class CriterionDto { - private Long id; private Long filterId; private String family; private String key; @@ -32,73 +31,57 @@ public final class CriterionDto { private String textValue; private Boolean variation; - public Long getId() { - return id; - } - - public CriterionDto setId(Long id) { - this.id = id; - return this; - } - - public Long getFilterId() { - return filterId; - } - + /** + * @param filterId the filter id to set + */ public CriterionDto setFilterId(Long filterId) { this.filterId = filterId; return this; } - public String getFamily() { - return family; - } - + /** + * @param family the family to set + */ public CriterionDto setFamily(String family) { this.family = family; return this; } - public String getKey() { - return key; - } - + /** + * @param key the key to set + */ public CriterionDto setKey(String key) { this.key = key; return this; } - public String getOperator() { - return operator; - } - + /** + * @param operator the operator to set + */ public CriterionDto setOperator(String operator) { this.operator = operator; return this; } - public Float getValue() { - return value; - } - + /** + * @param value the value to set + */ public CriterionDto setValue(Float value) { this.value = value; return this; } - public String getTextValue() { - return textValue; - } - + /** + * @param textValue the textValue to set + */ public CriterionDto setTextValue(String textValue) { this.textValue = textValue; return this; } - public Boolean getVariation() { - return variation; - } - + /** + * @param variation the variation to set + */ public CriterionDto setVariation(Boolean variation) { this.variation = variation; return this; diff --git a/sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java b/sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java index f933c6ffda8..25ca37bdb0f 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java @@ -23,5 +23,10 @@ package org.sonar.core.filter; * @since 3.1 */ public interface CriterionMapper { - void insert(CriterionDto criteriaDto); + /** + * Insert a {@link CriterionDto}. + * + * @param criterionDto the criterion to insert + */ + void insert(CriterionDto criterionDto); } diff --git a/sonar-core/src/main/java/org/sonar/core/filter/FilterColumnDto.java b/sonar-core/src/main/java/org/sonar/core/filter/FilterColumnDto.java index e7141a54731..38a92e51baf 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/FilterColumnDto.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/FilterColumnDto.java @@ -23,7 +23,6 @@ package org.sonar.core.filter; * @since 3.1 */ public final class FilterColumnDto { - private Long id; private Long filterId; private String family; private String key; @@ -31,64 +30,49 @@ public final class FilterColumnDto { private Long orderIndex; private Boolean variation; - public Long getId() { - return id; - } - - public FilterColumnDto setId(Long id) { - this.id = id; - return this; - } - - public Long getFilterId() { - return filterId; - } - + /** + * @param filterId the filterId to set + */ public FilterColumnDto setFilterId(Long filterId) { this.filterId = filterId; return this; } - public String getFamily() { - return family; - } - + /** + * @param family the family to set + */ public FilterColumnDto setFamily(String family) { this.family = family; return this; } - public String getKey() { - return key; - } - + /** + * @param key the key to set + */ public FilterColumnDto setKey(String key) { this.key = key; return this; } - public String getSortDirection() { - return sortDirection; - } - + /** + * @param sortDirection the sortDirection to set + */ public FilterColumnDto setSortDirection(String sortDirection) { this.sortDirection = sortDirection; return this; } - public Long getOrderIndex() { - return orderIndex; - } - + /** + * @param orderIndex the orderIndex to set + */ public FilterColumnDto setOrderIndex(Long orderIndex) { this.orderIndex = orderIndex; return this; } - public Boolean getVariation() { - return variation; - } - + /** + * @param variation the variation to set + */ public FilterColumnDto setVariation(Boolean variation) { this.variation = variation; return this; diff --git a/sonar-core/src/main/java/org/sonar/core/filter/FilterColumnMapper.java b/sonar-core/src/main/java/org/sonar/core/filter/FilterColumnMapper.java index b5cc739ea86..60706d87a17 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/FilterColumnMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/FilterColumnMapper.java @@ -23,5 +23,10 @@ package org.sonar.core.filter; * @since 3.1 */ public interface FilterColumnMapper { + /** + * Insert a {@link FilterColumnDto}. + * + * @param filterColumnDto the filter column to insert + */ void insert(FilterColumnDto filterColumnDto); } diff --git a/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java b/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java index 61dd2728ca0..8cd6c1db334 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java @@ -41,78 +41,91 @@ public final class FilterDto { private List criteria = Lists.newArrayList(); private List filterColumns = Lists.newArrayList(); + /** + * @return the id + */ public Long getId() { return id; } - public FilterDto setId(Long id) { - this.id = id; - return this; - } - + /** + * @return the name + */ public String getName() { return name; } + /** + * @param name the name to set + */ public FilterDto setName(String name) { this.name = name; return this; } + /** + * @return the key + */ public String getKey() { return key; } + /** + * @param key the key to set + */ public FilterDto setKey(String key) { this.key = key; return this; } - public Long getUserId() { - return userId; - } - - public FilterDto setUserId(Long userId) { - this.userId = userId; - return this; - } - + /** + * @return true if the filter is shared + */ public Boolean isShared() { return shared; } + /** + * @param shared the shared to set + */ public FilterDto setShared(Boolean shared) { this.shared = shared; return this; } + /** + * @return true if the filter displays only favourite resources. + */ public Boolean isFavourites() { return favourites; } + /** + * @param favourites the favourites to set + */ public FilterDto setFavourites(Boolean favourites) { this.favourites = favourites; return this; } - public Long getResourceId() { - return resourceId; - } - - public FilterDto setResourceId(Long resourceId) { - this.resourceId = resourceId; - return this; - } - + /** + * @return the defaut view + */ public String getDefaultView() { return defaultView; } + /** + * @param defaultView the defaultView to set + */ public FilterDto setDefaultView(String defaultView) { this.defaultView = defaultView; return this; } + /** + * @return the page size + */ public Long getPageSize() { return pageSize; } @@ -122,28 +135,35 @@ public final class FilterDto { return this; } - public Long getPeriodIndex() { - return periodIndex; - } - - public FilterDto setPeriodIndex(Long periodIndex) { - this.periodIndex = periodIndex; - return this; - } - + /** + * @return the criterion list + */ public Collection getCriteria() { return criteria; } + /** + * Add a {@link CriterionDto} to the list. + * + * @param criterion the criterion to add + */ public FilterDto add(CriterionDto criterion) { criteria.add(criterion); return this; } + /** + * @return the column list + */ public Collection getColumns() { return filterColumns; } + /** + * Add a {@link FilterColumnDto} to the list. + * + * @param filterColumn the column to add + */ public FilterDto add(FilterColumnDto filterColumn) { filterColumns.add(filterColumn); return this; diff --git a/sonar-core/src/main/java/org/sonar/core/filter/FilterMapper.java b/sonar-core/src/main/java/org/sonar/core/filter/FilterMapper.java index 75920978d57..b3b2fa3f2bf 100644 --- a/sonar-core/src/main/java/org/sonar/core/filter/FilterMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/filter/FilterMapper.java @@ -23,7 +23,18 @@ package org.sonar.core.filter; * @since 3.1 */ public interface FilterMapper { - FilterDto findFilter(String name); + /** + * Find a {@link FilterDto} by its unique key. + * + * @param key the key to search on + * @return the filter + */ + FilterDto findFilter(String key); + /** + * Insert a {@link FilterDto}. + * + * @param filterDto the filter to insert + */ void insert(FilterDto filterDto); } diff --git a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java index c30cbd3ff69..046aedb799b 100644 --- a/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java +++ b/sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java @@ -42,6 +42,7 @@ public final class HasProjectPropertyCondition extends ProjectPropertyCondition return settings.hasKey(getPropertyKey()) || settings.getDefaultValue(getPropertyKey()) != null; } + @Override public String toString() { return "Property " + getPropertyKey() + " must be set"; } diff --git a/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java b/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java index faac03f92ad..504f0a4bd78 100644 --- a/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java @@ -19,12 +19,10 @@ */ package org.sonar.core.filters; -import org.sonar.core.filter.FilterColumnDto; - -import org.sonar.core.filter.CriterionDto; - import org.junit.Before; import org.junit.Test; +import org.sonar.core.filter.CriterionDto; +import org.sonar.core.filter.FilterColumnDto; import org.sonar.core.filter.FilterDao; import org.sonar.core.filter.FilterDto; import org.sonar.core.persistence.DaoTestCase; @@ -48,7 +46,6 @@ public class FilterDaoTest extends DaoTestCase { assertThat(filter.getId()).isEqualTo(1L); assertThat(filter.getName()).isEqualTo("Projects"); assertThat(filter.getKey()).isEqualTo("Projects"); - assertThat(filter.getUserId()).isNull(); assertThat(dao.findFilter("")).isNull(); } @@ -59,13 +56,10 @@ public class FilterDaoTest extends DaoTestCase { FilterDto filterDto = new FilterDto(); filterDto.setName("Projects"); filterDto.setKey("Projects"); - filterDto.setUserId(null); filterDto.setShared(true); filterDto.setFavourites(false); - filterDto.setResourceId(null); filterDto.setDefaultView("list"); filterDto.setPageSize(10L); - filterDto.setPeriodIndex(1L); CriterionDto criterionDto = new CriterionDto(); criterionDto.setFamily("family"); diff --git a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java index 677358b9c11..8d877d42508 100644 --- a/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java @@ -19,6 +19,8 @@ */ package org.sonar.core.resource; +import org.fest.assertions.Assertions; + import org.hamcrest.BaseMatcher; import org.hamcrest.Description; import org.hamcrest.core.Is; diff --git a/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert-result.xml b/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert-result.xml index b65ba064cef..80849e355bb 100644 --- a/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert-result.xml +++ b/sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert-result.xml @@ -10,7 +10,7 @@ resource_id="[null]" default_view="list" page_size="10" - period_index="1" + period_index="[null]" /> DIRECTIONS = ImmutableSortedSet.of(ASC, DESC); diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java index ff270e66719..e284678871a 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java @@ -47,20 +47,17 @@ public final class RegisterNewDashboards { private DashboardDao dashboardDao; private ActiveDashboardDao activeDashboardDao; private LoadedTemplateDao loadedTemplateDao; - private RegisterNewFilters registerNewFilters; // To force loading the filters before the dashboards - public RegisterNewDashboards(DashboardDao dashboardDao, ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao, RegisterNewFilters registerNewFilters) { - this(new DashboardTemplate[] {}, dashboardDao, activeDashboardDao, loadedTemplateDao, registerNewFilters); + public RegisterNewDashboards(DashboardDao dashboardDao, ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao) { + this(new DashboardTemplate[] {}, dashboardDao, activeDashboardDao, loadedTemplateDao); } public RegisterNewDashboards(DashboardTemplate[] dashboardTemplatesArray, DashboardDao dashboardDao, - ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao, - RegisterNewFilters registerNewFilters) { + ActiveDashboardDao activeDashboardDao, LoadedTemplateDao loadedTemplateDao) { this.dashboardTemplates = Lists.newArrayList(dashboardTemplatesArray); this.dashboardDao = dashboardDao; this.activeDashboardDao = activeDashboardDao; this.loadedTemplateDao = loadedTemplateDao; - this.registerNewFilters = registerNewFilters; } public void start() { diff --git a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java index 4c768a99186..01e33d0fb6c 100644 --- a/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java +++ b/sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java @@ -65,7 +65,7 @@ public final class RegisterNewFilters { for (FilterTemplate template : filterTemplates) { if (shouldRegister(template.getName())) { Filter filter = template.createFilter(); - FilterDto dto = register(template.getName(), filter); + register(template.getName(), filter); } } @@ -88,12 +88,6 @@ public final class RegisterNewFilters { return dto; } - private static void addCriteria(FilterDto filterDto, String family, String operator, String textValue) { - if (textValue != null) { - filterDto.add(new CriterionDto().setFamily(family).setOperator(operator).setTextValue(textValue)); - } - } - protected FilterDto createDtoFromExtension(String name, Filter filter) { FilterDto filterDto = new FilterDto() .setName(name) diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java index 0259f232692..39b991dd3e0 100644 --- a/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java +++ b/sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java @@ -149,7 +149,7 @@ public class DefaultServerPluginRepositoryTest { @Override public Object provide() { - return Arrays.asList(FakeBatchExtension.class, FakeServerExtension.class); + return Arrays. asList(FakeBatchExtension.class, FakeServerExtension.class); } } diff --git a/sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java b/sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java index c5725717e16..1953278a660 100644 --- a/sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java +++ b/sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java @@ -88,7 +88,7 @@ public class ServerExtensionInstallerTest { @Override public Object provide() { - return Arrays.asList(FakeBatchExtension.class, FakeServerExtension.class); + return Arrays. asList(FakeBatchExtension.class, FakeServerExtension.class); } } diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java index e74119c6817..b7c9c82993c 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java @@ -27,7 +27,12 @@ import org.junit.Test; import org.sonar.api.web.Dashboard; import org.sonar.api.web.DashboardLayout; import org.sonar.api.web.DashboardTemplate; -import org.sonar.core.dashboard.*; +import org.sonar.core.dashboard.ActiveDashboardDao; +import org.sonar.core.dashboard.ActiveDashboardDto; +import org.sonar.core.dashboard.DashboardDao; +import org.sonar.core.dashboard.DashboardDto; +import org.sonar.core.dashboard.WidgetDto; +import org.sonar.core.dashboard.WidgetPropertyDto; import org.sonar.core.template.LoadedTemplateDao; import org.sonar.core.template.LoadedTemplateDto; @@ -39,8 +44,11 @@ import static org.hamcrest.Matchers.nullValue; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.argThat; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class RegisterNewDashboardsTest { @@ -59,7 +67,7 @@ public class RegisterNewDashboardsTest { fakeDashboardTemplate = new FakeDashboard(); task = new RegisterNewDashboards(new DashboardTemplate[]{fakeDashboardTemplate}, dashboardDao, - activeDashboardDao, loadedTemplateDao, null); + activeDashboardDao, loadedTemplateDao); } @Test diff --git a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java index d5ce0d4a179..e0ac7e02a9a 100644 --- a/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java +++ b/sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java @@ -122,7 +122,6 @@ public class RegisterNewFiltersTest { FilterDto dto = register.createDtoFromExtension("Fake", filterTemplate.createFilter()); - assertThat(dto.getUserId()).isNull(); assertThat(dto.getName()).isEqualTo("Fake"); assertThat(dto.getKey()).isEqualTo("Fake"); assertThat(dto.isShared()).isTrue();