]> source.dussan.org Git - sonarqube.git/commitdiff
Fix violations, simplify code and improve documentation
authorDavid Gageot <david@gageot.net>
Wed, 23 May 2012 20:11:53 +0000 (22:11 +0200)
committerDavid Gageot <david@gageot.net>
Wed, 23 May 2012 20:13:25 +0000 (22:13 +0200)
21 files changed:
sonar-batch/src/test/java/org/sonar/batch/bootstrap/BatchExtensionInstallerTest.java
sonar-batch/src/test/java/org/sonar/batch/bootstrap/DatabaseBatchCompatibilityTest.java
sonar-core/src/main/java/org/sonar/core/filter/CriterionDto.java
sonar-core/src/main/java/org/sonar/core/filter/CriterionMapper.java
sonar-core/src/main/java/org/sonar/core/filter/FilterColumnDto.java
sonar-core/src/main/java/org/sonar/core/filter/FilterColumnMapper.java
sonar-core/src/main/java/org/sonar/core/filter/FilterDto.java
sonar-core/src/main/java/org/sonar/core/filter/FilterMapper.java
sonar-core/src/main/java/org/sonar/core/review/workflow/condition/HasProjectPropertyCondition.java
sonar-core/src/test/java/org/sonar/core/filters/FilterDaoTest.java
sonar-core/src/test/java/org/sonar/core/resource/ResourceDaoTest.java
sonar-core/src/test/resources/org/sonar/core/filters/FilterDaoTest/shouldInsert-result.xml
sonar-plugin-api/src/main/java/org/sonar/api/web/Criterion.java
sonar-plugin-api/src/main/java/org/sonar/api/web/Filter.java
sonar-plugin-api/src/main/java/org/sonar/api/web/FilterColumn.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterNewDashboards.java
sonar-server/src/main/java/org/sonar/server/startup/RegisterNewFilters.java
sonar-server/src/test/java/org/sonar/server/plugins/DefaultServerPluginRepositoryTest.java
sonar-server/src/test/java/org/sonar/server/plugins/ServerExtensionInstallerTest.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterNewDashboardsTest.java
sonar-server/src/test/java/org/sonar/server/startup/RegisterNewFiltersTest.java

index 8fa44b14fbb34c21b0ccd3ba3e7f92171de64138..7230e87f5616c36c236668a7319cb3bacb068bda 100644 (file)
@@ -116,7 +116,7 @@ public class BatchExtensionInstallerTest {
 
     @Override
     public Object provide() {
-      return Arrays.asList(BatchService.class, ServerService.class);
+      return Arrays.<Object> asList(BatchService.class, ServerService.class);
     }
   }
 
index 4c02392148735f538be95658cdc990c50f83d80e..eb2c719a8eeea89e163400072a10038e416798ad 100644 (file)
@@ -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");
index 02fc0d04a54e5fdf5a4cfc3d827fd1bdf3c38bcd..936af6d3572c6380bc1dc59282a9fd9b4741ac0e 100644 (file)
@@ -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;
index f933c6ffda8f7edc264da216ffbb63418a47329b..25ca37bdb0f3dfa739fd6741ba169bac19536743 100644 (file)
@@ -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);
 }
index e7141a5473166360bf55f9117c2266e769a94c5f..38a92e51baf621e1c396c0f04379f12670b64832 100644 (file)
@@ -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;
index b5cc739ea865830e1e56436503469b4e5e9982df..60706d87a17908e7ef953063339596dd232a803b 100644 (file)
@@ -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);
 }
index 61dd2728ca04f0259db832d46b0fe90b097eaa97..8cd6c1db334dcbc241bec993c353ab65530be533 100644 (file)
@@ -41,78 +41,91 @@ public final class FilterDto {
   private List<CriterionDto> criteria = Lists.newArrayList();
   private List<FilterColumnDto> 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 <code>true</code> 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 <code>true</code> 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<CriterionDto> 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<FilterColumnDto> 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;
index 75920978d57a36783be48874fbc131ae10f9e611..b3b2fa3f2bf271f86112b6bd04a198ea85963d36 100644 (file)
@@ -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);
 }
index c30cbd3ff697a9c9ab30b454e4e7d16142b62c95..046aedb799bde73a8d118bd1bf66616c2e039cec 100644 (file)
@@ -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";
   }
index faac03f92ad87f54aaa1e5c58c667eac5846ad6b..504f0a4bd787a11ad398bbfa182b5300ed728455 100644 (file)
  */
 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("<UNKNOWN>")).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");
index 677358b9c119752506dbfd5f5828c393b7919942..8d877d42508576efc57bb4f9692e292104a8e305 100644 (file)
@@ -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;
index b65ba064cef532e8eecace5b22aad4cc817aff12..80849e355bbf88192a7f7b2867e40de0bc57aae0 100644 (file)
@@ -10,7 +10,7 @@
     resource_id="[null]"
     default_view="list"
     page_size="10"
-    period_index="1"
+    period_index="[null]"
     />
 
   <criteria
index 5c5582107a9bfaf98e76f5b896d0009574acff2c..f43bc68c659381a540a0aaab33a59249b0fb5894 100644 (file)
@@ -29,7 +29,7 @@ import java.util.Set;
  *
  * @since 3.1
  */
-public class Criterion {
+public final class Criterion {
   public static final String EQ = "=";
   public static final String GT = ">";
   public static final String GTE = ">=";
index 46a38519a5beadc8e64152d418eccb2989808b5c..7c8d4d55c67d96b619b0a2a0b62378a7b48ec2a8 100644 (file)
@@ -32,7 +32,7 @@ import com.google.common.base.Preconditions;
  *
  * @since 3.1
  */
-public class Filter {
+public final class Filter {
   public static final String LIST = "list";
   public static final String TREEMAP = "treemap";
 
index 1326ffd4d8d19e5558a08bcbf7760285fee44237..d5e8e323cd6d747b91fab5f6cd69f667562825a4 100644 (file)
@@ -30,7 +30,7 @@ import com.google.common.base.Preconditions;
  *
  * @since 3.1
  */
-public class FilterColumn {
+public final class FilterColumn {
   public static final String ASC = "ASC";
   public static final String DESC = "DESC";
   public static final Set<String> DIRECTIONS = ImmutableSortedSet.of(ASC, DESC);
index ff270e667191e4524e7a5e5ec4cb04f66e38e5d4..e284678871a999656fc767669554d8cd3fff5d52 100644 (file)
@@ -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() {
index 4c768a99186b58c178b75feb575fc7f8eb86e94c..01e33d0fb6c8f9a6b422d7524a8ef1f9188230ea 100644 (file)
@@ -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)
index 0259f2326924e913d9c7ce962da0061789b15273..39b991dd3e0c88ed94ff3f4fd962a6c8f1f3a3c9 100644 (file)
@@ -149,7 +149,7 @@ public class DefaultServerPluginRepositoryTest {
 
     @Override
     public Object provide() {
-      return Arrays.asList(FakeBatchExtension.class, FakeServerExtension.class);
+      return Arrays.<Object> asList(FakeBatchExtension.class, FakeServerExtension.class);
     }
   }
 
index c5725717e16b304265b706a21d7c81fdd3a1092f..1953278a660de4c30021df733c0ec6190ad50ef8 100644 (file)
@@ -88,7 +88,7 @@ public class ServerExtensionInstallerTest {
 
     @Override
     public Object provide() {
-      return Arrays.asList(FakeBatchExtension.class, FakeServerExtension.class);
+      return Arrays.<Object> asList(FakeBatchExtension.class, FakeServerExtension.class);
     }
   }
 
index e74119c681715f5d0f50e89ffe5c73b5dd82ed44..b7c9c82993c34d6520ba979052aae737b4b35314 100644 (file)
@@ -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
index d5ce0d4a179f31a8f798e9eb17405e30348570d7..e0ac7e02a9aa1b70d484120c81f68f51cf4850fa 100644 (file)
@@ -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();