aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-deprecated/src/test
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2014-02-20 14:35:11 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2014-02-20 14:35:11 +0100
commit5d4f33d87453a9737b7716d9d3b55b3300c03108 (patch)
treefee5762418cf15b43ba200b0eee7f34876e8e1c5 /sonar-deprecated/src/test
parent8e689273caa1b424206c691e1c068beb2a315241 (diff)
downloadsonarqube-5d4f33d87453a9737b7716d9d3b55b3300c03108.tar.gz
sonarqube-5d4f33d87453a9737b7716d9d3b55b3300c03108.zip
Revert "SONAR-926 move InputFileUtils to sonar-deprecated"
This reverts commit 289b8f4694ed08197a357d9ed6b2368ec0b2a6cb.
Diffstat (limited to 'sonar-deprecated/src/test')
-rw-r--r--sonar-deprecated/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java181
1 files changed, 0 insertions, 181 deletions
diff --git a/sonar-deprecated/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java b/sonar-deprecated/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java
deleted file mode 100644
index 99bd3226c15..00000000000
--- a/sonar-deprecated/src/test/java/org/sonar/api/resources/InputFileUtilsTest.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * SonarQube, open source software quality management tool.
- * Copyright (C) 2008-2013 SonarSource
- * mailto:contact AT sonarsource DOT com
- *
- * SonarQube is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * SonarQube is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-package org.sonar.api.resources;
-
-import com.google.common.io.Closeables;
-
-import org.junit.rules.ExpectedException;
-
-import org.junit.Rule;
-
-import com.google.common.base.Charsets;
-import com.google.common.io.ByteStreams;
-import com.google.common.io.Files;
-import org.junit.Test;
-
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.List;
-
-import static org.fest.assertions.Assertions.assertThat;
-
-public class InputFileUtilsTest {
- private static final File BASE_DIR = new File("target/tmp/InputFileUtilsTest");
-
- @Rule
- public ExpectedException exception = ExpectedException.none();
-
- @Test
- public void shouldCreateInputFileWithRelativePath() {
- String relativePath = "org/sonar/Foo.java";
-
- InputFile inputFile = InputFileUtils.create(BASE_DIR, relativePath);
-
- assertThat(inputFile.getFileBaseDir()).isEqualTo(BASE_DIR);
- assertThat(inputFile.getRelativePath()).isEqualTo(relativePath);
- assertThat(inputFile.getFile()).isEqualTo(new File("target/tmp/InputFileUtilsTest/org/sonar/Foo.java"));
- }
-
- @Test
- public void shouldNotAcceptFileWithWrongbaseDir() {
- File baseDir1 = new File(BASE_DIR, "baseDir1");
- File baseDir2 = new File(BASE_DIR, "baseDir2");
-
- InputFile inputFile = InputFileUtils.create(baseDir1, new File(baseDir2, "org/sonar/Foo.java"));
-
- assertThat(inputFile).isNull();
- }
-
- @Test
- public void shouldGuessRelativePath() {
- File file = new File(BASE_DIR, "org/sonar/Foo.java");
-
- InputFile inputFile = InputFileUtils.create(BASE_DIR, file);
-
- assertThat(inputFile.getFileBaseDir()).isEqualTo(BASE_DIR);
- assertThat(inputFile.getFile()).isEqualTo(file);
- assertThat(inputFile.getRelativePath()).isEqualTo("org/sonar/Foo.java");
- }
-
- @Test
- public void testEqualsAndHashCode() {
- InputFile inputFile1 = InputFileUtils.create(BASE_DIR, "org/sonar/Foo.java");
- InputFile inputFile2 = InputFileUtils.create(BASE_DIR, "org/sonar/Foo.java");
- InputFile inputFile3 = InputFileUtils.create(BASE_DIR, "org/sonar/Bar.java");
-
- assertThat(inputFile1).isEqualTo(inputFile1).isEqualTo(inputFile2);
- assertThat(inputFile1.hashCode()).isEqualTo(inputFile2.hashCode());
- assertThat(inputFile1).isNotEqualTo(inputFile3);
- }
-
- @Test
- public void shouldNotEqualFile() {
- File file = new File(BASE_DIR, "org/sonar/Foo.java");
-
- InputFile inputFile = InputFileUtils.create(BASE_DIR, file);
-
- assertThat(inputFile.getFile()).isEqualTo(file);
- assertThat(inputFile).isNotEqualTo(file);
- }
-
- @Test
- public void shouldNotEqualIfbaseDirAreDifferents() {
- InputFile inputFile1 = InputFileUtils.create(BASE_DIR, "org/sonar/Foo.java");
- InputFile inputFile2 = InputFileUtils.create(new File(BASE_DIR, "org"), "sonar/Foo.java");
-
- assertThat(inputFile1).isNotEqualTo(inputFile2);
- }
-
- @Test
- public void testToString() {
- InputFile inputFile = InputFileUtils.create(BASE_DIR, "org/sonar/Foo.java");
-
- assertThat(inputFile.toString()).endsWith("InputFileUtilsTest -> org/sonar/Foo.java");
- }
-
- @Test
- public void testToFiles() {
- List<InputFile> inputFiles = Arrays.asList(InputFileUtils.create(BASE_DIR, "Foo.java"), InputFileUtils.create(BASE_DIR, "Bar.java"));
- List<File> files = InputFileUtils.toFiles(inputFiles);
-
- assertThat(files).containsExactly(new File(BASE_DIR, "Foo.java"), new File(BASE_DIR, "Bar.java"));
- }
-
- @Test
- public void testCreateList() {
- File file1 = new File(BASE_DIR, "org/sonar/Foo.java");
- File file2 = new File(BASE_DIR, "org/sonar/Bar.java");
- File wrongFile = new File("somewhere/else/org/sonar/Foo.java");
-
- List<InputFile> inputFiles = InputFileUtils.create(BASE_DIR, Arrays.asList(file1, file2, wrongFile));
-
- assertThat(inputFiles).hasSize(2);
- assertThat(inputFiles.get(0).getFile()).isEqualTo(file1);
- assertThat(inputFiles.get(1).getFile()).isEqualTo(file2);
- }
-
- @Test
- public void shouldExtractRelativeDirectory() {
- InputFile inputFile = InputFileUtils.create(BASE_DIR, "org/sonar/Foo.java");
- assertThat(InputFileUtils.getRelativeDirectory(inputFile)).isEqualTo("org/sonar");
-
- inputFile = InputFileUtils.create(BASE_DIR, "Foo.java");
- assertThat(InputFileUtils.getRelativeDirectory(inputFile)).isEmpty();
- }
-
- @Test
- public void should_get_file_content_as_buffered_input_stream() throws IOException {
- InputFile inputFile = InputFileUtils.create(BASE_DIR, "org/sonar/Foo.java");
- write("<FILE CONTENT>", inputFile.getFile());
-
- InputStream inputStream = inputFile.getInputStream();
-
- assertThat(inputStream).isInstanceOf(BufferedInputStream.class);
- assertThat(read(inputStream)).isEqualTo("<FILE CONTENT>");
- }
-
- @Test
- public void should_fail_to_get_input_stream_of_unknown_file() throws IOException {
- InputFile inputFile = InputFileUtils.create(BASE_DIR, "UNKNOWN.java");
-
- exception.expect(FileNotFoundException.class);
- exception.expectMessage(BASE_DIR.getPath());
- exception.expectMessage("UNKNOWN.java");
-
- inputFile.getInputStream();
- }
-
- static void write(String content, File file) throws IOException {
- file.getParentFile().mkdirs();
- Files.write(content, file, Charsets.UTF_8);
- }
-
- static String read(InputStream input) throws IOException {
- try {
- return new String(ByteStreams.toByteArray(input), Charsets.UTF_8.displayName());
- } finally {
- Closeables.closeQuietly(input);
- }
- }
-}