diff options
author | Jenkins CI <ci@sonarsource.com> | 2012-07-24 00:40:26 +0200 |
---|---|---|
committer | Jenkins CI <ci@sonarsource.com> | 2012-07-24 00:40:26 +0200 |
commit | 722433baa940051c46123363958a7faeec59f908 (patch) | |
tree | cd88652689ed3ee5ab66d8f143452606ac590c39 | |
parent | 554202ed2dbbdc7aa3c231f2900939a3577748d7 (diff) | |
parent | 90f4577aa3e3b8b759ff58bfc09d6a546da17f8c (diff) | |
download | sonarqube-722433baa940051c46123363958a7faeec59f908.tar.gz sonarqube-722433baa940051c46123363958a7faeec59f908.zip |
Automatic merge from branch-3.2
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java | 25 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/database/model/MeasureDataTest.java | 18 |
2 files changed, 37 insertions, 6 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java index 9dcfb371b8d..d52e0e58ca0 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/database/model/MeasureData.java @@ -19,11 +19,14 @@ */ package org.sonar.api.database.model; +import com.google.common.base.Charsets; +import com.google.common.base.Throwables; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.database.BaseIdentifiable; import javax.persistence.*; +import java.io.UnsupportedEncodingException; @Entity @Table(name = "measure_data") @@ -50,7 +53,12 @@ public class MeasureData extends BaseIdentifiable { public MeasureData(MeasureModel measure, String dataString) { this.measure = measure; - this.data = dataString.getBytes(); + try { + this.data = dataString.getBytes(Charsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + // how is it possible to not support UTF-8 ? + Throwables.propagate(e); + } } public MeasureData() { @@ -70,7 +78,12 @@ public class MeasureData extends BaseIdentifiable { public String getText() { if (data != null) { - return new String(data); + try { + return new String(data, Charsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + // how is it possible to not support UTF-8 ? + Throwables.propagate(e); + } } return null; } @@ -90,10 +103,10 @@ public class MeasureData extends BaseIdentifiable { @Override public String toString() { return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) - .append("snapshotId", snapshotId) - .append("mesasure", measure) - .append("data", data) - .toString(); + .append("snapshotId", snapshotId) + .append("mesasure", measure) + .append("data", data) + .toString(); } } diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/database/model/MeasureDataTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/MeasureDataTest.java new file mode 100644 index 00000000000..6d966088d1d --- /dev/null +++ b/sonar-plugin-api/src/test/java/org/sonar/api/database/model/MeasureDataTest.java @@ -0,0 +1,18 @@ +package org.sonar.api.database.model; + +import com.google.common.base.Charsets; +import org.junit.Test; + +import static org.fest.assertions.Assertions.assertThat; + +public class MeasureDataTest { + @Test + public void text_is_utf8() { + System.out.println(Charsets.UTF_8.name()); + MeasureData data = new MeasureData(); + String s = "accents éà and special characters ç€"; + data.setData(s.getBytes(Charsets.UTF_8)); + + assertThat(data.getText()).isEqualTo(s); + } +} |