]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3860 Delete test file containing the BOM character and improve unit test in...
authorJulien Lancelot <julien.lancelot@gmail.com>
Fri, 8 Feb 2013 15:19:27 +0000 (16:19 +0100)
committerJulien Lancelot <julien.lancelot@gmail.com>
Fri, 8 Feb 2013 15:19:27 +0000 (16:19 +0100)
sonar-plugin-api/src/main/java/org/sonar/api/batch/AbstractSourceImporter.java
sonar-plugin-api/src/test/java/org/sonar/api/batch/AbstractSourceImporterTest.java
sonar-plugin-api/test-resources/org/sonar/api/batch/AbstractSourceImporterTest/encoding/FileWithBom.java [deleted file]

index 5666ecb778ea8de98b3f6c615df97f10f5088e1d..e11db40b30e5e992fc154943bb75bd780109c8a9 100644 (file)
@@ -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);
           }
index 1fdc2e80bca6c3d157efb246733bd0d5d8e5945d..fc3f3c1fa3ccefb67af3dbcc98432d1172770e59 100644 (file)
@@ -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 (file)
index 1df2b09..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-public class FileWithBom {
-
-    public FileWithBom() {
-      
-    }
-
-}