aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-02-08 16:19:27 +0100
committerJulien Lancelot <julien.lancelot@gmail.com>2013-02-08 16:19:27 +0100
commit83a14ffbf5cb15d372c35490f9ae6a033745b96e (patch)
tree8fbb46b43c57bcc05970955ccc70fb2b92a0a971 /sonar-plugin-api
parent12cdab111316cf96aaa4baec4a04885855fbb68e (diff)
downloadsonarqube-83a14ffbf5cb15d372c35490f9ae6a033745b96e.tar.gz
sonarqube-83a14ffbf5cb15d372c35490f9ae6a033745b96e.zip
SONAR-3860 Delete test file containing the BOM character and improve unit test in order to see the BOM character
Diffstat (limited to 'sonar-plugin-api')
-rw-r--r--sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java2
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java8
-rw-r--r--sonar-plugin-api/test-resources/org/sonar/api/batch/AbstractSourceImporterTest/encoding/FileWithBom.java7
3 files changed, 7 insertions, 10 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java
index 5666ecb778e..e11db40b30e 100644
--- a/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java
+++ b/sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java
@@ -83,7 +83,7 @@ public abstract class AbstractSourceImporter implements Sensor {
context.index(resource);
if (enabled) {
String source = Files.toString(file, Charset.forName(sourcesEncoding.name()));
- // SONAR-3860 Remove Bom character from source
+ // SONAR-3860 Remove BOM character from source
source = CharMatcher.anyOf("\uFEFF").removeFrom(source);
context.saveSource(resource, source);
}
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
index 1fdc2e80bca..fc3f3c1fa3c 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.api.batch;
+import com.google.common.io.Files;
import org.apache.commons.configuration.MapConfiguration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.lang.CharEncoding;
@@ -120,7 +121,7 @@ public class AbstractSourceImporterTest {
}
@Test
- public void should_remove_bom_character() throws Exception {
+ public void should_remove_byte_order_mark_character() throws Exception {
Project project = mock(Project.class);
SensorContext context = mock(SensorContext.class);
@@ -128,7 +129,10 @@ public class AbstractSourceImporterTest {
when(project.getFileSystem()).thenReturn(fileSystem);
when(fileSystem.getSourceCharset()).thenReturn(Charset.forName(CharEncoding.UTF_8));
when(project.getConfiguration()).thenReturn(new MapConfiguration(new HashMap<String, String>()));
- when(fileSystem.getSourceFiles(any(Language.class))).thenReturn(newArrayList(getFile("FileWithBom.java")));
+
+ File file = new File(Files.createTempDir(), "Test.java");
+ Files.write("\uFEFFpublic class Test", file, Charset.defaultCharset());
+ when(fileSystem.getSourceFiles(any(Language.class))).thenReturn(newArrayList(file));
importer.shouldExecuteOnProject(project);
importer.analyse(project, context);
diff --git a/sonar-plugin-api/test-resources/org/sonar/api/batch/AbstractSourceImporterTest/encoding/FileWithBom.java b/sonar-plugin-api/test-resources/org/sonar/api/batch/AbstractSourceImporterTest/encoding/FileWithBom.java
deleted file mode 100644
index 1df2b0916bd..00000000000
--- a/sonar-plugin-api/test-resources/org/sonar/api/batch/AbstractSourceImporterTest/encoding/FileWithBom.java
+++ /dev/null
@@ -1,7 +0,0 @@
-public class FileWithBom {
-
- public FileWithBom() {
- 
- }
-
-}