diff options
author | Julien Lancelot <julien.lancelot@gmail.com> | 2013-07-05 13:39:11 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@gmail.com> | 2013-07-05 13:39:22 +0200 |
commit | 8ffca6c7304e7082b207512e54e55e9d0be3dd68 (patch) | |
tree | 71e028c1583b40faca738c2b6678954729cb189b | |
parent | 55658bd42b6ac8567575bd98f17f143462820a00 (diff) | |
download | sonarqube-8ffca6c7304e7082b207512e54e55e9d0be3dd68.tar.gz sonarqube-8ffca6c7304e7082b207512e54e55e9d0be3dd68.zip |
Fix quality flaws
9 files changed, 41 insertions, 29 deletions
diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/BulkChange.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/BulkChange.java index d20dd220315..020715111f7 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/BulkChange.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/BulkChange.java @@ -28,8 +28,8 @@ public interface BulkChange { List<String> issuesNotChangedKeys(); - int totalIssuesChanged(); + Integer totalIssuesChanged(); - int totalIssuesNotChanged(); + Integer totalIssuesNotChanged(); } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultBulkChange.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultBulkChange.java index de76f8a54bd..fe44ebe63d1 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultBulkChange.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/issue/internal/DefaultBulkChange.java @@ -21,6 +21,7 @@ package org.sonar.wsclient.issue.internal; import org.sonar.wsclient.issue.BulkChange; +import javax.annotation.CheckForNull; import javax.annotation.Nullable; import java.util.ArrayList; @@ -31,28 +32,30 @@ import java.util.List; */ public class DefaultBulkChange implements BulkChange { - private int totalIssuesChanged; - private int totalIssuesNotChanged; + private Integer totalIssuesChanged; + private Integer totalIssuesNotChanged; private final List<String> issuesNotChangedKeys = new ArrayList<String>(); public List<String> issuesNotChangedKeys() { return issuesNotChangedKeys; } - public int totalIssuesChanged() { + @CheckForNull + public Integer totalIssuesChanged() { return totalIssuesChanged; } - public int totalIssuesNotChanged() { + @CheckForNull + public Integer totalIssuesNotChanged() { return totalIssuesNotChanged; } - DefaultBulkChange setTotalIssuesChanged(@Nullable int totalIssuesChanged) { + DefaultBulkChange setTotalIssuesChanged(@Nullable Integer totalIssuesChanged) { this.totalIssuesChanged = totalIssuesChanged; return this; } - DefaultBulkChange setTotalIssuesNotChanged(@Nullable int totalIssuesNotChanged) { + DefaultBulkChange setTotalIssuesNotChanged(@Nullable Integer totalIssuesNotChanged) { this.totalIssuesNotChanged = totalIssuesNotChanged; return this; } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Authentication.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Authentication.java index 9c669f8fd29..5bf6b062377 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Authentication.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Authentication.java @@ -19,16 +19,15 @@ */ package org.sonar.wsclient.services; -import javax.annotation.Nullable; - public class Authentication extends Model { + private boolean valid; - public boolean isValid() { + public boolean isValid() { return valid; } - public Authentication setValid(@Nullable boolean valid) { + public Authentication setValid(boolean valid) { this.valid = valid; return this; } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Profile.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Profile.java index d709e970e78..75b335fd116 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Profile.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Profile.java @@ -60,7 +60,7 @@ public class Profile extends Model { return defaultProfile; } - public Profile setDefaultProfile(@Nullable boolean b) { + public Profile setDefaultProfile(boolean b) { this.defaultProfile = b; return this; } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceSearchResult.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceSearchResult.java index 83abf7f37bb..bc3927deb56 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceSearchResult.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/ResourceSearchResult.java @@ -58,14 +58,16 @@ public class ResourceSearchResult extends Model { } - private int page, pageSize, total; + private Integer page, pageSize, total; private List<ResourceSearchResult.Resource> resources; - public int getPage() { + @CheckForNull + public Integer getPage() { return page; } - public int getTotal() { + @CheckForNull + public Integer getTotal() { return total; } @@ -73,19 +75,20 @@ public class ResourceSearchResult extends Model { return resources; } - public void setPage(@Nullable int page) { + public void setPage(@Nullable Integer page) { this.page = page; } - public void setTotal(@Nullable int total) { + public void setTotal(@Nullable Integer total) { this.total = total; } - public int getPageSize() { + @CheckForNull + public Integer getPageSize() { return pageSize; } - public void setPageSize(@Nullable int pageSize) { + public void setPageSize(@Nullable Integer pageSize) { this.pageSize = pageSize; } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AuthenticationUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AuthenticationUnmarshaller.java index 471a0853d4d..650c20fee48 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AuthenticationUnmarshaller.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/AuthenticationUnmarshaller.java @@ -25,12 +25,13 @@ import org.sonar.wsclient.services.WSUtils; import java.util.List; public class AuthenticationUnmarshaller implements Unmarshaller<Authentication> { + public Authentication toModel(String json) { WSUtils utils = WSUtils.getINSTANCE(); Object map = utils.parse(json); - return new Authentication() - .setValid(utils.getBoolean(map, "valid")); + Boolean validJson = utils.getBoolean(map, "valid"); + return new Authentication().setValid(validJson != null ? validJson : false); } public List<Authentication> toModels(String json) { diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ProfileUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ProfileUnmarshaller.java index ab200984d8a..1f28afaf1b7 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ProfileUnmarshaller.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ProfileUnmarshaller.java @@ -28,10 +28,11 @@ public class ProfileUnmarshaller extends AbstractUnmarshaller<Profile> { protected Profile parse(Object json) { WSUtils utils = WSUtils.getINSTANCE(); Profile profile = new Profile(); + Boolean defaultProfile = utils.getBoolean(json, "default"); profile .setLanguage(utils.getString(json, "language")) .setName(utils.getString(json, "name")) - .setDefaultProfile(utils.getBoolean(json, "default")) + .setDefaultProfile(defaultProfile != null ? defaultProfile : false) .setParentName(utils.getString(json, "parent")); parseRules(utils, profile, json); diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceSearchUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceSearchUnmarshaller.java index 011aa893d22..407bfdecace 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceSearchUnmarshaller.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ResourceSearchUnmarshaller.java @@ -19,6 +19,7 @@ */ package org.sonar.wsclient.unmarshallers; +import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.sonar.wsclient.services.ResourceSearchResult; import org.sonar.wsclient.services.WSUtils; @@ -40,12 +41,15 @@ public class ResourceSearchUnmarshaller extends AbstractUnmarshaller<ResourceSea result.setTotal(utils.getInteger(json, "total")); List<ResourceSearchResult.Resource> resources = new ArrayList<ResourceSearchResult.Resource>(); - for (Object jsonResource : JsonUtils.getArray((JSONObject) json, "data")) { - ResourceSearchResult.Resource resource = new ResourceSearchResult.Resource(); - resource.setKey(JsonUtils.getString((JSONObject) jsonResource, "key")); - resource.setName(JsonUtils.getString((JSONObject) jsonResource, "nm")); - resource.setQualifier(JsonUtils.getString((JSONObject) jsonResource, "q")); - resources.add(resource); + JSONArray dataJson = JsonUtils.getArray((JSONObject) json, "data"); + if (dataJson != null) { + for (Object jsonResource : dataJson) { + ResourceSearchResult.Resource resource = new ResourceSearchResult.Resource(); + resource.setKey(JsonUtils.getString((JSONObject) jsonResource, "key")); + resource.setName(JsonUtils.getString((JSONObject) jsonResource, "nm")); + resource.setQualifier(JsonUtils.getString((JSONObject) jsonResource, "q")); + resources.add(resource); + } } result.setResources(resources); return result; diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/AuthenticationTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/AuthenticationTest.java index 193dd56ed55..684177a176c 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/services/AuthenticationTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/services/AuthenticationTest.java @@ -24,6 +24,7 @@ import org.junit.Test; import static org.fest.assertions.Assertions.assertThat; public class AuthenticationTest { + @Test public void should_set_valid_state() { assertThat(new Authentication().isValid()).isFalse(); |