diff options
author | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-04 11:26:20 +0000 |
---|---|---|
committer | simonbrandhof <simon.brandhof@gmail.com> | 2010-12-04 11:26:20 +0000 |
commit | 0db9c91b9a999a88a1557db6f70330d129b2f9a4 (patch) | |
tree | ba25e0f6b098db948a7b4522845f54e724510426 /sonar-plugin-api | |
parent | 81adc198d8db644965385e3675d46b89008ed8f5 (diff) | |
download | sonarqube-0db9c91b9a999a88a1557db6f70330d129b2f9a4.tar.gz sonarqube-0db9c91b9a999a88a1557db6f70330d129b2f9a4.zip |
SONAR-249 add some unit tests
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java | 38 | ||||
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java | 36 |
2 files changed, 54 insertions, 20 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java index ce45562be13..9700f23d424 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/Snapshot.java @@ -25,8 +25,8 @@ import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.database.BaseIdentifiable; import org.sonar.api.database.DatabaseSession; -import java.util.Date; import javax.persistence.*; +import java.util.Date; /** * A class to map a snapshot with its hibernate model @@ -160,86 +160,97 @@ public class Snapshot extends BaseIdentifiable { return createdAt; } - public void setCreatedAt(Date createdAt) { + public Snapshot setCreatedAt(Date createdAt) { this.createdAt = createdAt; + return this; } public Integer getResourceId() { return resourceId; } - public void setResourceId(Integer resourceId) { + public Snapshot setResourceId(Integer resourceId) { this.resourceId = resourceId; + return this; } - public final void setResource(ResourceModel resource) { + public final Snapshot setResource(ResourceModel resource) { this.resourceId = resource.getId(); this.scope = resource.getScope(); this.qualifier = resource.getQualifier(); + return this; } public String getVersion() { return version; } - public void setVersion(String version) { + public Snapshot setVersion(String version) { this.version = version; + return this; } public Integer getParentId() { return parentId; } - public void setParentId(Integer i) { + public Snapshot setParentId(Integer i) { this.parentId = i; + return this; } public Boolean getLast() { return last; } - public void setLast(Boolean last) { + public Snapshot setLast(Boolean last) { this.last = last; + return this; } public String getStatus() { return status; } - public void setStatus(String status) { + public Snapshot setStatus(String status) { this.status = status; + return this; } public String getScope() { return scope; } - public void setScope(String scope) { + public Snapshot setScope(String scope) { this.scope = scope; + return this; } public String getQualifier() { return qualifier; } - public void setQualifier(String qualifier) { + public Snapshot setQualifier(String qualifier) { this.qualifier = qualifier; + return this; } public Integer getRootId() { return rootId; } - public void setRootId(Integer i) { + public Snapshot setRootId(Integer i) { this.rootId = i; + return this; } public String getPath() { return path; } - public void setPath(String path) { + public Snapshot setPath(String path) { this.path = path; + return this; } public Integer getDepth() { @@ -250,8 +261,9 @@ public class Snapshot extends BaseIdentifiable { return rootProjectId; } - public void setRootProjectId(Integer rootProjectId) { + public Snapshot setRootProjectId(Integer rootProjectId) { this.rootProjectId = rootProjectId; + return this; } /** diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java index 87ff5bd61dc..73305be154a 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/measures/Metric.java @@ -22,7 +22,6 @@ package org.sonar.api.measures; import org.apache.commons.lang.builder.ToStringBuilder; import org.sonar.api.BatchExtension; import org.sonar.api.ServerExtension; -import org.sonar.api.database.BaseIdentifiable; import javax.persistence.*; @@ -31,7 +30,7 @@ import javax.persistence.*; */ @Table(name = "metrics") @Entity(name = "Metric") -public class Metric extends BaseIdentifiable implements ServerExtension, BatchExtension { +public class Metric implements ServerExtension, BatchExtension { /** * A metric bigger value means a degradation @@ -68,6 +67,11 @@ public class Metric extends BaseIdentifiable implements ServerExtension, BatchEx JAV, GUI, WS } + @Id + @Column(name = "id") + @GeneratedValue + private Integer id; + @Transient private Formula formula; @@ -119,7 +123,8 @@ public class Metric extends BaseIdentifiable implements ServerExtension, BatchEx /** * Creates an empty metric */ - @Deprecated public Metric() { + @Deprecated + public Metric() { } /** @@ -173,8 +178,8 @@ public class Metric extends BaseIdentifiable implements ServerExtension, BatchEx this.userManaged = userManaged; this.origin = Origin.JAV; if (ValueType.PERCENT.equals(this.type)) { - this.bestValue = (direction==DIRECTION_BETTER ? 100.0 : 0.0); - this.worstValue = (direction==DIRECTION_BETTER ? 0.0 : 100.0); + this.bestValue = (direction == DIRECTION_BETTER ? 100.0 : 0.0); + this.worstValue = (direction == DIRECTION_BETTER ? 0.0 : 100.0); } } @@ -206,12 +211,28 @@ public class Metric extends BaseIdentifiable implements ServerExtension, BatchEx this.userManaged = false; this.formula = formula; if (ValueType.PERCENT.equals(this.type)) { - this.bestValue = (direction==DIRECTION_BETTER ? 100.0 : 0.0); - this.worstValue = (direction==DIRECTION_BETTER ? 0.0 : 100.0); + this.bestValue = (direction == DIRECTION_BETTER ? 100.0 : 0.0); + this.worstValue = (direction == DIRECTION_BETTER ? 0.0 : 100.0); } } /** + * For internal use only + */ + public Integer getId() { + return id; + } + + /** + * For internal use only + */ + public Metric setId(Integer id) { + this.id = id; + return this; + } + + + /** * @return the metric formula */ public Formula getFormula() { @@ -513,6 +534,7 @@ public class Metric extends BaseIdentifiable implements ServerExtension, BatchEx /** * Merge with fields from other metric. All fields are copied, except the id. + * * @return this */ public Metric merge(final Metric with) { |