import com.google.common.base.Function;
import com.google.common.io.Files;
-import org.apache.commons.io.Charsets;
import org.sonar.api.CoreProperties;
import org.sonar.api.SonarPlugin;
import org.sonar.api.batch.bootstrap.ProjectReactor;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
public TaskBuilder newScanTask(File sonarProps) {
Properties prop = new Properties();
- try (Reader reader = new InputStreamReader(new FileInputStream(sonarProps), Charsets.UTF_8)) {
+ try (Reader reader = new InputStreamReader(new FileInputStream(sonarProps), StandardCharsets.UTF_8)) {
prop.load(reader);
} catch (Exception e) {
throw new IllegalStateException("Unable to read configuration file", e);
*/
package org.sonar.batch.report;
-import com.google.common.base.Charsets;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.BOMInputStream;
import org.sonar.batch.index.ResourceCache;
import org.sonar.batch.protocol.output.BatchReportWriter;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
public class SourcePublisher implements ReportPublisherStep {
BufferedReader reader = new BufferedReader(new InputStreamReader(bomIn, inputFile.charset()))) {
String lineStr = reader.readLine();
while (lineStr != null) {
- IOUtils.write(lineStr, output, Charsets.UTF_8);
+ IOUtils.write(lineStr, output, StandardCharsets.UTF_8);
line++;
if (line < inputFile.lines()) {
- IOUtils.write("\n", output, Charsets.UTF_8);
+ IOUtils.write("\n", output, StandardCharsets.UTF_8);
}
lineStr = reader.readLine();
}
package org.sonar.batch.scan.report;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Charsets;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
File exportFile = new File(fileSystem.workDir(), exportPath);
LOG.info("Export issues to " + exportFile.getAbsolutePath());
- try (Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile), Charsets.UTF_8))) {
+ try (Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(exportFile), StandardCharsets.UTF_8))) {
writeJson(output);
} catch (IOException e) {
*/
package org.sonar.batch.bootstrap;
-import com.google.common.base.Charsets;
import com.google.common.io.Files;
import org.apache.commons.io.IOUtils;
import org.eclipse.jetty.server.Handler;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import static javax.servlet.http.HttpServletResponse.SC_OK;
import static org.apache.commons.io.IOUtils.write;
File file = temp.newFile();
newServerClient().download("/foo", file);
- assertThat(Files.toString(file, Charsets.UTF_8)).isEqualTo("this is the content");
+ assertThat(Files.toString(file, StandardCharsets.UTF_8)).isEqualTo("this is the content");
}
@Test
import java.io.File;
import java.io.IOException;
-import static com.google.common.base.Charsets.UTF_8;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.verify;
import java.util.Arrays;
import java.util.Set;
-import static com.google.common.base.Charsets.UTF_8;
+import static java.nio.charset.StandardCharsets.UTF_8;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
*/
package org.sonar.batch.issue.tracking;
-import com.google.common.base.Charsets;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.java.api.JavaClass;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import static com.google.common.collect.Lists.newArrayList;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.*;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyCollection;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.argThat;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.isA;
+import static org.mockito.Mockito.RETURNS_MOCKS;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class IssueTrackingDecoratorTest {
java.io.File f = temp.newFile();
when(inputFile.path()).thenReturn(f.toPath());
when(inputFile.file()).thenReturn(f);
- when(inputFile.charset()).thenReturn(Charsets.UTF_8);
+ when(inputFile.charset()).thenReturn(StandardCharsets.UTF_8);
when(inputFile.lines()).thenReturn(StringUtils.countMatches(newSource, "\n") + 1);
- FileUtils.write(f, newSource, Charsets.UTF_8);
+ FileUtils.write(f, newSource, StandardCharsets.UTF_8);
when(inputFile.key()).thenReturn("foo:Action.java");
when(inputPathCache.getFile("foo", "Action.java")).thenReturn(inputFile);
when(lastSnapshots.getLineHashes("foo:Action.java")).thenReturn(computeHexHashes(originalSource));
package org.sonar.batch.issue.tracking;
-import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import com.google.common.io.Resources;
import org.apache.commons.codec.digest.DigestUtils;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collections;
}
private static String load(String name) throws IOException {
- return Resources.toString(IssueTrackingTest.class.getResource("IssueTrackingTest/" + name + ".txt"), Charsets.UTF_8);
+ return Resources.toString(IssueTrackingTest.class.getResource("IssueTrackingTest/" + name + ".txt"), StandardCharsets.UTF_8);
}
private DefaultIssue newDefaultIssue(String message, Integer line, RuleKey ruleKey, String checksum) {
File f = temp.newFile();
when(inputFile.path()).thenReturn(f.toPath());
when(inputFile.file()).thenReturn(f);
- when(inputFile.charset()).thenReturn(Charsets.UTF_8);
+ when(inputFile.charset()).thenReturn(StandardCharsets.UTF_8);
String data = load(newSource);
when(inputFile.lines()).thenReturn(StringUtils.countMatches(data, "\n") + 1);
- FileUtils.write(f, data, Charsets.UTF_8);
+ FileUtils.write(f, data, StandardCharsets.UTF_8);
when(inputFile.key()).thenReturn("foo:Action.java");
when(lastSnapshots.getLineHashes("foo:Action.java")).thenReturn(computeHexHashes(load(reference)));
sourceHashHolder = new SourceHashHolder(inputFile, lastSnapshots);
*/
package org.sonar.batch.issue.tracking;
-import com.google.common.base.Charsets;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import java.io.File;
+import java.nio.charset.StandardCharsets;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
import static org.assertj.core.api.Assertions.assertThat;
when(file.file()).thenReturn(ioFile);
when(file.path()).thenReturn(ioFile.toPath());
when(file.lines()).thenReturn(1);
- when(file.charset()).thenReturn(Charsets.UTF_8);
+ when(file.charset()).thenReturn(StandardCharsets.UTF_8);
sourceHashHolder = new SourceHashHolder(file, lastSnapshots);
}
@Test
public void should_lazy_load_line_hashes() throws Exception {
final String source = "source";
- FileUtils.write(ioFile, source + "\n", Charsets.UTF_8);
+ FileUtils.write(ioFile, source + "\n", StandardCharsets.UTF_8);
when(file.lines()).thenReturn(2);
assertThat(sourceHashHolder.getHashedSource().getHash(1)).isEqualTo(md5Hex(source));
public void should_lazy_load_reference_hashes_when_status_changed() throws Exception {
final String source = "source";
String key = "foo:src/Foo.java";
- FileUtils.write(ioFile, source, Charsets.UTF_8);
+ FileUtils.write(ioFile, source, StandardCharsets.UTF_8);
when(file.key()).thenReturn(key);
when(file.status()).thenReturn(InputFile.Status.CHANGED);
when(lastSnapshots.getLineHashes(key)).thenReturn(new String[] {md5Hex(source)});
public void should_not_load_reference_hashes_when_status_same() throws Exception {
final String source = "source";
String key = "foo:src/Foo.java";
- FileUtils.write(ioFile, source, Charsets.UTF_8);
+ FileUtils.write(ioFile, source, StandardCharsets.UTF_8);
when(file.key()).thenReturn(key);
when(file.status()).thenReturn(InputFile.Status.SAME);
public void no_reference_hashes_when_status_added() throws Exception {
final String source = "source";
String key = "foo:src/Foo.java";
- FileUtils.write(ioFile, source, Charsets.UTF_8);
+ FileUtils.write(ioFile, source, StandardCharsets.UTF_8);
when(file.key()).thenReturn(key);
when(file.status()).thenReturn(InputFile.Status.ADDED);
*/
package org.sonar.batch.mediumtest.dependency;
-import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
FileUtils.write(xooFile2, "foo");
File xooDepFile = new File(srcDir, "dir1/sample" + nb + ".xoo.deps");
for (int otherId = 1; otherId <= nbFiles; otherId++) {
- FileUtils.write(xooDepFile, "src/dir2/sample" + otherId + ".xoo:1\n", Charsets.UTF_8, true);
+ FileUtils.write(xooDepFile, "src/dir2/sample" + otherId + ".xoo:1\n", StandardCharsets.UTF_8, true);
}
}
*/
package org.sonar.batch.mediumtest.fs;
-import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import org.apache.commons.io.FileUtils;
import org.junit.After;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
int ISSUE_COUNT = 10000;
for (int i = 0; i < ISSUE_COUNT; i++) {
File xooFile = new File(srcDir, "sample" + (i / 10 + 1) + ".xoo");
- FileUtils.write(paths, xooFile.getAbsolutePath() + "\n", Charsets.UTF_8, true);
+ FileUtils.write(paths, xooFile.getAbsolutePath() + "\n", StandardCharsets.UTF_8, true);
}
long start = System.currentTimeMillis();
File paths = new File(baseDir, "paths.txt");
int ISSUE_COUNT = 10000;
for (int i = 0; i < ISSUE_COUNT; i++) {
- FileUtils.write(paths, "src/sample" + (i / 10 + 1) + ".xoo\n", Charsets.UTF_8, true);
+ FileUtils.write(paths, "src/sample" + (i / 10 + 1) + ".xoo\n", StandardCharsets.UTF_8, true);
}
TaskResult result = tester.newTask()
*/
package org.sonar.batch.report;
-import com.google.common.base.Charsets;
import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Rule;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.Date;
import static org.assertj.core.api.Assertions.assertThat;
resourceCache.add(p, null).setSnapshot(new Snapshot().setId(2));
File baseDir = temp.newFolder();
sourceFile = new File(baseDir, "src/Foo.php");
- resourceCache.add(sampleFile, null).setInputPath(new DefaultInputFile("foo", "src/Foo.php").setLines(5).setModuleBaseDir(baseDir.toPath()).setCharset(Charsets.ISO_8859_1));
+ resourceCache.add(sampleFile, null).setInputPath(
+ new DefaultInputFile("foo", "src/Foo.php").setLines(5).setModuleBaseDir(baseDir.toPath()).setCharset(StandardCharsets.ISO_8859_1));
publisher = new SourcePublisher(resourceCache);
File outputDir = temp.newFolder();
writer = new BatchReportWriter(outputDir);
@Test
public void publishEmptySource() throws Exception {
- FileUtils.write(sourceFile, "", Charsets.ISO_8859_1);
+ FileUtils.write(sourceFile, "", StandardCharsets.ISO_8859_1);
publisher.publish(writer);
File out = writer.getSourceFile(2);
- assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("");
+ assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("");
}
@Test
public void publishSourceWithLastEmptyLine() throws Exception {
- FileUtils.write(sourceFile, "1\n2\n3\n4\n", Charsets.ISO_8859_1);
+ FileUtils.write(sourceFile, "1\n2\n3\n4\n", StandardCharsets.ISO_8859_1);
publisher.publish(writer);
File out = writer.getSourceFile(2);
- assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
+ assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
}
@Test
public void publishTestSource() throws Exception {
- FileUtils.write(sourceFile, "1\n2\n3\n4\n", Charsets.ISO_8859_1);
+ FileUtils.write(sourceFile, "1\n2\n3\n4\n", StandardCharsets.ISO_8859_1);
sampleFile.setQualifier(Qualifiers.UNIT_TEST_FILE);
publisher.publish(writer);
File out = writer.getSourceFile(2);
- assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
+ assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
}
@Test
public void publishSourceWithLastLineNotEmpty() throws Exception {
- FileUtils.write(sourceFile, "1\n2\n3\n4\n5", Charsets.ISO_8859_1);
+ FileUtils.write(sourceFile, "1\n2\n3\n4\n5", StandardCharsets.ISO_8859_1);
publisher.publish(writer);
File out = writer.getSourceFile(2);
- assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("1\n2\n3\n4\n5");
+ assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n5");
}
@Test
public void cleanLineEnds() throws Exception {
- FileUtils.write(sourceFile, "\n2\r\n3\n4\r5", Charsets.ISO_8859_1);
+ FileUtils.write(sourceFile, "\n2\r\n3\n4\r5", StandardCharsets.ISO_8859_1);
publisher.publish(writer);
File out = writer.getSourceFile(2);
- assertThat(FileUtils.readFileToString(out, Charsets.UTF_8)).isEqualTo("\n2\n3\n4\n5");
+ assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("\n2\n3\n4\n5");
}
}
*/
package org.sonar.batch.scan.filesystem;
-import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.batch.bootstrap.DefaultAnalysisMode;
import java.io.File;
+import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
FileUtils.touch(srcFile);
FileUtils.write(srcFile, "single line");
when(fs.baseDir()).thenReturn(basedir);
- when(fs.encoding()).thenReturn(Charsets.UTF_8);
+ when(fs.encoding()).thenReturn(StandardCharsets.UTF_8);
// lang
when(langDetection.language(any(InputFile.class))).thenReturn("java");
FileUtils.touch(srcFile);
FileUtils.write(srcFile, "single line");
when(fs.baseDir()).thenReturn(basedir);
- when(fs.encoding()).thenReturn(Charsets.UTF_8);
+ when(fs.encoding()).thenReturn(StandardCharsets.UTF_8);
// lang
when(langDetection.language(any(InputFile.class))).thenReturn(null);
*/
package org.sonar.batch.scan.filesystem;
-import com.google.common.base.Charsets;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.sonar.api.batch.fs.internal.DefaultInputFile;
import org.sonar.api.batch.fs.internal.DeprecatedDefaultInputFile;
+import java.nio.charset.StandardCharsets;
+
import static org.assertj.core.api.Assertions.assertThat;
public class InputPathCacheTest {
.setType(Type.MAIN)
.setStatus(Status.ADDED)
.setLines(2)
- .setCharset(Charsets.UTF_8)
+ .setCharset(StandardCharsets.UTF_8)
.setModuleBaseDir(temp.newFolder().toPath()));
DefaultInputFile loadedFile = (DefaultInputFile) cache.getFile("struts-core", "src/main/java/Bar.java");
assertThat(loadedFile.relativePath()).isEqualTo("src/main/java/Bar.java");
- assertThat(loadedFile.charset()).isEqualTo(Charsets.UTF_8);
+ assertThat(loadedFile.charset()).isEqualTo(StandardCharsets.UTF_8);
assertThat(cache.filesByModule("struts")).hasSize(1);
assertThat(cache.filesByModule("struts-core")).hasSize(1);
*/
package org.sonar.batch.source;
-import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import org.sonar.api.batch.sensor.highlighting.NewHighlighting;
import org.sonar.api.batch.sensor.highlighting.TypeOfText;
import org.sonar.api.web.CodeColorizerFormat;
-import org.sonar.colorizer.*;
+import org.sonar.colorizer.CDocTokenizer;
+import org.sonar.colorizer.CppDocTokenizer;
+import org.sonar.colorizer.JavadocTokenizer;
+import org.sonar.colorizer.KeywordsTokenizer;
+import org.sonar.colorizer.StringTokenizer;
+import org.sonar.colorizer.Tokenizer;
import java.io.File;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
File jsFile = new File(this.getClass().getResource("CodeColorizersTest/Person.js").toURI());
NewHighlighting highlighting = mock(NewHighlighting.class);
- codeColorizers.toSyntaxHighlighting(jsFile, Charsets.UTF_8, "js", highlighting);
+ codeColorizers.toSyntaxHighlighting(jsFile, StandardCharsets.UTF_8, "js", highlighting);
verifyForJs(highlighting);
}
FileUtils.write(fileWithBom, FileUtils.readFileToString(jsFile), "UTF-8", true);
NewHighlighting highlighting = mock(NewHighlighting.class);
- codeColorizers.toSyntaxHighlighting(fileWithBom, Charsets.UTF_8, "js", highlighting);
+ codeColorizers.toSyntaxHighlighting(fileWithBom, StandardCharsets.UTF_8, "js", highlighting);
verifyForJs(highlighting);
}
File javaFile = new File(this.getClass().getResource("CodeColorizersTest/Person.java").toURI());
NewHighlighting highlighting = mock(NewHighlighting.class);
- codeColorizers.toSyntaxHighlighting(javaFile, Charsets.UTF_8, "java", highlighting);
+ codeColorizers.toSyntaxHighlighting(javaFile, StandardCharsets.UTF_8, "java", highlighting);
verify(highlighting).highlight(0, 4, TypeOfText.STRUCTURED_COMMENT);
verify(highlighting).highlight(5, 11, TypeOfText.STRUCTURED_COMMENT);
*/
package org.sonar.api.batch.fs.internal;
-import org.sonar.api.BatchSide;
-
-import com.google.common.base.Charsets;
import com.google.common.primitives.Ints;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.ByteOrderMark;
import org.apache.commons.io.input.BOMInputStream;
+import org.sonar.api.BatchSide;
import org.sonar.api.CoreProperties;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.List;
@Override
protected void newLine() {
sb.append(LINE_FEED);
- globalMd5Digest.update(sb.toString().getBytes(Charsets.UTF_8));
+ globalMd5Digest.update(sb.toString().getBytes(StandardCharsets.UTF_8));
sb.setLength(0);
}
@Override
protected void eof() {
if (sb.length() > 0) {
- globalMd5Digest.update(sb.toString().getBytes(Charsets.UTF_8));
+ globalMd5Digest.update(sb.toString().getBytes(StandardCharsets.UTF_8));
}
}
@Override
protected void newLine() {
- consumer.consume(line, sb.length() > 0 ? lineMd5Digest.digest(sb.toString().getBytes(Charsets.UTF_8)) : null);
+ consumer.consume(line, sb.length() > 0 ? lineMd5Digest.digest(sb.toString().getBytes(StandardCharsets.UTF_8)) : null);
sb.setLength(0);
line++;
}
@Override
protected void eof() {
if (this.line > 0) {
- consumer.consume(line, sb.length() > 0 ? lineMd5Digest.digest(sb.toString().getBytes(Charsets.UTF_8)) : null);
+ consumer.consume(line, sb.length() > 0 ? lineMd5Digest.digest(sb.toString().getBytes(StandardCharsets.UTF_8)) : null);
}
}
* For testing purpose
*/
public Metadata readMetadata(Reader reader) {
- LineCounter lineCounter = new LineCounter(new File("fromString"), Charsets.UTF_16);
+ LineCounter lineCounter = new LineCounter(new File("fromString"), StandardCharsets.UTF_16);
FileHashComputer fileHashComputer = new FileHashComputer();
LineOffsetCounter lineOffsetCounter = new LineOffsetCounter();
try {
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Throwables;
import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.Charsets;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.CoreProperties;
import java.io.File;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.security.Key;
import java.security.SecureRandom;
javax.crypto.Cipher cipher = javax.crypto.Cipher.getInstance(CRYPTO_KEY);
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, loadSecretFile());
byte[] cipherData = cipher.doFinal(Base64.decodeBase64(StringUtils.trim(encryptedText)));
- return new String(cipherData, Charsets.UTF_8);
+ return new String(cipherData, StandardCharsets.UTF_8);
} catch (Exception e) {
throw Throwables.propagate(e);
}
*/
package org.sonar.api.config;
-import com.google.common.base.Charsets;
import org.apache.commons.codec.binary.Base64;
+import java.nio.charset.StandardCharsets;
+
final class Base64Cipher extends Cipher {
@Override
String encrypt(String clearText) {
- return Base64.encodeBase64String(clearText.getBytes(Charsets.UTF_8));
+ return Base64.encodeBase64String(clearText.getBytes(StandardCharsets.UTF_8));
}
@Override
String decrypt(String encryptedText) {
- return new String(Base64.decodeBase64(encryptedText), Charsets.UTF_8);
+ return new String(Base64.decodeBase64(encryptedText), StandardCharsets.UTF_8);
}
}
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.utils.DateUtils;
import java.io.IOException;
import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
}
public static License readBase64(String base64) {
- return readPlainText(new String(Base64.decodeBase64(base64.getBytes(Charsets.UTF_8)), Charsets.UTF_8));
+ return readPlainText(new String(Base64.decodeBase64(base64.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8));
}
@VisibleForTesting
*/
package org.sonar.api.database.model;
-import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.rules.RulePriority;
import javax.annotation.CheckForNull;
-import javax.persistence.*;
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Table;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
/**
* This class is the Hibernate model to store a measure in the DB
}
if (metric.isDataType() && data != null) {
try {
- return new String(data, Charsets.UTF_8.name());
+ return new String(data, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
// how is it possible to not support UTF-8 ?
Throwables.propagate(e);
} else {
if (data.length() > TEXT_VALUE_LENGTH) {
this.textValue = null;
- this.data = data.getBytes(Charsets.UTF_8);
+ this.data = data.getBytes(StandardCharsets.UTF_8);
} else {
this.textValue = data;
this.data = null;
*/
package org.sonar.api.profiles;
-import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.codehaus.staxmate.SMInputFactory;
import java.io.InputStreamReader;
import java.io.Reader;
+import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
}
public RulesProfile parseResource(ClassLoader classloader, String xmlClassPath, ValidationMessages messages) {
- Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), Charsets.UTF_8);
+ Reader reader = new InputStreamReader(classloader.getResourceAsStream(xmlClassPath), StandardCharsets.UTF_8);
try {
return parse(reader, messages);
*/
package org.sonar.api.server.ws;
-import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.io.IOException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
public String responseExampleAsString() {
try {
if (responseExample != null) {
- return StringUtils.trim(IOUtils.toString(responseExample, Charsets.UTF_8));
+ return StringUtils.trim(IOUtils.toString(responseExample, StandardCharsets.UTF_8));
}
return null;
} catch (IOException e) {
*/
package org.sonar.api.utils;
-import org.apache.commons.io.Charsets;
import org.apache.commons.io.IOUtils;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
BufferedReader buffer = null;
try {
- buffer = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8));
+ buffer = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
parse(buffer);
} catch (IOException e) {
public void parse(InputStream stream) {
BufferedReader buffer = null;
try {
- buffer = new BufferedReader(new InputStreamReader(stream, Charsets.UTF_8));
+ buffer = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
parse(buffer);
} catch (IOException e) {
public void parse(String xml) {
try {
String fixedXml = fixUnicodeChar(xml);
- doc = builder.parse(new ByteArrayInputStream(fixedXml.getBytes(Charsets.UTF_8)));
+ doc = builder.parse(new ByteArrayInputStream(fixedXml.getBytes(StandardCharsets.UTF_8)));
XPathFactory factory = XPathFactory.newInstance();
xpath = factory.newXPath();
*/
package org.sonar.api.utils.command;
-import com.google.common.base.Charsets;
import com.google.common.io.Closeables;
import org.sonar.api.utils.log.Logger;
import org.sonar.api.utils.log.Loggers;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@Override
public void run() {
- try (BufferedReader br = new BufferedReader(new InputStreamReader(is, Charsets.UTF_8))) {
+ try (BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
String line;
while ((line = br.readLine()) != null) {
consumeLine(line);
*/
package org.sonar.api.batch.fs.internal;
-import com.google.common.base.Charsets;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.io.FileUtils;
import org.junit.Rule;
import java.io.File;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import static org.apache.commons.codec.digest.DigestUtils.md5Hex;
import static org.assertj.core.api.Assertions.assertThat;
File tempFile = temp.newFile();
FileUtils.touch(tempFile);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(1);
assertThat(metadata.nonBlankLines).isEqualTo(0);
assertThat(metadata.hash).isNotEmpty();
@Test
public void windows_without_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\r\nbar\r\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\r\nbar\r\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
File tempFile = temp.newFile();
FileUtils.write(tempFile, "marker´s\n", Charset.forName("cp1252"));
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(2);
assertThat(metadata.hash).isEqualTo(md5Hex("marker\ufffds\n"));
assertThat(metadata.originalLineOffsets).containsOnly(0, 9);
@Test
public void non_ascii_utf_8() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("föo\nbàr\n\u1D11Ebaßz\n"));
@Test
public void non_ascii_utf_16() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", Charsets.UTF_16, true);
+ FileUtils.write(tempFile, "föo\r\nbàr\r\n\u1D11Ebaßz\r\n", StandardCharsets.UTF_16, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_16);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_16);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("föo\nbàr\n\u1D11Ebaßz\n"));
@Test
public void unix_without_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\nbar\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\nbar\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
@Test
public void unix_with_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\nbar\nbaz\n", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\nbar\nbaz\n", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz\n"));
@Test
public void mix_of_newlines_with_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\nbar\r\nbaz\n", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\nbar\r\nbaz\n", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz\n"));
@Test
public void several_new_lines() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\n\n\nbar", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\n\n\nbar", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(2);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\n\n\nbar"));
@Test
public void mix_of_newlines_without_latest_eol() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "foo\nbar\r\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "foo\nbar\r\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
@Test
public void start_with_newline() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "\nfoo\nbar\r\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "\nfoo\nbar\r\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(4);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("\nfoo\nbar\nbaz"));
@Test
public void start_with_bom() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "\uFEFFfoo\nbar\r\nbaz", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "\uFEFFfoo\nbar\r\nbaz", StandardCharsets.UTF_8, true);
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(tempFile, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(3);
assertThat(metadata.nonBlankLines).isEqualTo(3);
assertThat(metadata.hash).isEqualTo(md5Hex("foo\nbar\nbaz"));
@Test
public void ignore_whitespace_when_computing_line_hashes() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, " foo\nb ar\r\nbaz \t", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, " foo\nb ar\r\nbaz \t", StandardCharsets.UTF_8, true);
DefaultInputFile f = new DefaultInputFile("foo", tempFile.getName());
f.setModuleBaseDir(tempFile.getParentFile().toPath());
- f.setCharset(Charsets.UTF_8);
+ f.setCharset(StandardCharsets.UTF_8);
FileMetadata.computeLineHashesForIssueTracking(f, new LineHashConsumer() {
@Override
@Test
public void dont_fail_on_empty_file() throws Exception {
File tempFile = temp.newFile();
- FileUtils.write(tempFile, "", Charsets.UTF_8, true);
+ FileUtils.write(tempFile, "", StandardCharsets.UTF_8, true);
DefaultInputFile f = new DefaultInputFile("foo", tempFile.getName());
f.setModuleBaseDir(tempFile.getParentFile().toPath());
- f.setCharset(Charsets.UTF_8);
+ f.setCharset(StandardCharsets.UTF_8);
FileMetadata.computeLineHashesForIssueTracking(f, new LineHashConsumer() {
@Override
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Fail to read file '" + file.getAbsolutePath() + "' with encoding 'UTF-8'");
- new FileMetadata().readMetadata(file, Charsets.UTF_8);
+ new FileMetadata().readMetadata(file, StandardCharsets.UTF_8);
}
@Test
public void line_feed_is_included_into_hash() throws Exception {
File file1 = temp.newFile();
- FileUtils.write(file1, "foo\nbar\n", Charsets.UTF_8, true);
+ FileUtils.write(file1, "foo\nbar\n", StandardCharsets.UTF_8, true);
// same as file1, except an additional return carriage
File file1a = temp.newFile();
- FileUtils.write(file1a, "foo\r\nbar\n", Charsets.UTF_8, true);
+ FileUtils.write(file1a, "foo\r\nbar\n", StandardCharsets.UTF_8, true);
File file2 = temp.newFile();
- FileUtils.write(file2, "foo\nbar", Charsets.UTF_8, true);
+ FileUtils.write(file2, "foo\nbar", StandardCharsets.UTF_8, true);
- String hash1 = new FileMetadata().readMetadata(file1, Charsets.UTF_8).hash;
- String hash1a = new FileMetadata().readMetadata(file1a, Charsets.UTF_8).hash;
- String hash2 = new FileMetadata().readMetadata(file2, Charsets.UTF_8).hash;
+ String hash1 = new FileMetadata().readMetadata(file1, StandardCharsets.UTF_8).hash;
+ String hash1a = new FileMetadata().readMetadata(file1a, StandardCharsets.UTF_8).hash;
+ String hash2 = new FileMetadata().readMetadata(file2, StandardCharsets.UTF_8).hash;
assertThat(hash1).isEqualTo(hash1a);
assertThat(hash1).isNotEqualTo(hash2);
}
public void binary_file_with_unmappable_character() throws Exception {
File woff = new File(this.getClass().getResource("glyphicons-halflings-regular.woff").toURI());
- FileMetadata.Metadata metadata = new FileMetadata().readMetadata(woff, Charsets.UTF_8);
+ FileMetadata.Metadata metadata = new FileMetadata().readMetadata(woff, StandardCharsets.UTF_8);
assertThat(metadata.lines).isEqualTo(135);
assertThat(metadata.nonBlankLines).isEqualTo(134);
assertThat(metadata.hash).isNotEmpty();
*/
package org.sonar.api.batch.maven;
-import com.google.common.base.Charsets;
import org.apache.maven.project.MavenProject;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.test.MavenTestUtils;
import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
@Test
public void testSourceEncoding() {
MavenProject pom = MavenTestUtils.loadPom("/org/sonar/api/batch/maven/MavenPomWithSourceEncoding.xml");
- assertEquals(MavenUtils.getSourceCharset(pom), Charsets.UTF_16);
+ assertEquals(MavenUtils.getSourceCharset(pom), StandardCharsets.UTF_16);
}
}
*/
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.Closeables;
import com.google.common.io.Files;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
static void write(String content, File file) throws IOException {
file.getParentFile().mkdirs();
- Files.write(content, file, Charsets.UTF_8);
+ Files.write(content, file, StandardCharsets.UTF_8);
}
static String read(InputStream input) throws IOException {
try {
- return new String(ByteStreams.toByteArray(input), Charsets.UTF_8.displayName());
+ return new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8.displayName());
} finally {
Closeables.closeQuietly(input);
}
*/
package org.sonar.api.server.rule;
-import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
@Test
public void parse_xml() {
InputStream input = getClass().getResourceAsStream("/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest/rules.xml");
- RulesDefinition.Repository repository = load(input, Charsets.UTF_8.name());
+ RulesDefinition.Repository repository = load(input, StandardCharsets.UTF_8.name());
assertThat(repository.rules()).hasSize(2);
RulesDefinition.Rule rule = repository.rule("complete");
@Test
public void fail_if_missing_rule_key() {
thrown.expect(IllegalStateException.class);
- load(IOUtils.toInputStream("<rules><rule><name>Foo</name></rule></rules>"), Charsets.UTF_8.name());
+ load(IOUtils.toInputStream("<rules><rule><name>Foo</name></rule></rules>"), StandardCharsets.UTF_8.name());
}
@Test
public void fail_if_missing_property_key() {
thrown.expect(IllegalStateException.class);
- load(IOUtils.toInputStream("<rules><rule><key>foo</key><name>Foo</name><param></param></rule></rules>"), Charsets.UTF_8.name());
+ load(IOUtils.toInputStream("<rules><rule><key>foo</key><name>Foo</name><param></param></rule></rules>"), StandardCharsets.UTF_8.name());
}
@Test
public void fail_on_invalid_rule_parameter_type() {
thrown.expect(IllegalStateException.class);
- load(IOUtils.toInputStream("<rules><rule><key>foo</key><name>Foo</name><param><key>key</key><type>INVALID</type></param></rule></rules>"), Charsets.UTF_8.name());
+ load(IOUtils.toInputStream("<rules><rule><key>foo</key><name>Foo</name><param><key>key</key><type>INVALID</type></param></rule></rules>"), StandardCharsets.UTF_8.name());
}
@Test
thrown.expectMessage("XML is not valid");
InputStream input = getClass().getResourceAsStream("/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest/invalid.xml");
- load(input, Charsets.UTF_8.name());
+ load(input, StandardCharsets.UTF_8.name());
}
@Test
public void test_utf8_encoding() throws UnsupportedEncodingException {
InputStream input = getClass().getResourceAsStream("/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest/utf8.xml");
- RulesDefinition.Repository repository = load(input, Charsets.UTF_8.name());
+ RulesDefinition.Repository repository = load(input, StandardCharsets.UTF_8.name());
assertThat(repository.rules()).hasSize(1);
RulesDefinition.Rule rule = repository.rules().get(0);
public void support_deprecated_format() {
// the deprecated format uses some attributes instead of nodes
InputStream input = getClass().getResourceAsStream("/org/sonar/api/server/rule/RulesDefinitionXmlLoaderTest/deprecated.xml");
- RulesDefinition.Repository repository = load(input, Charsets.UTF_8.name());
+ RulesDefinition.Repository repository = load(input, StandardCharsets.UTF_8.name());
assertThat(repository.rules()).hasSize(1);
RulesDefinition.Rule rule = repository.rules().get(0);
*/
package org.sonar.api.utils;
-import com.google.common.base.Charsets;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import java.net.URI;
import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
@Test
public void file_readString() {
UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]);
- assertThat(uriReader.readString(testFile, Charsets.UTF_8)).isEqualTo("in foo");
+ assertThat(uriReader.readString(testFile, StandardCharsets.UTF_8)).isEqualTo("in foo");
}
@Test
public void file_readString_fails_if_file_not_found() throws Exception {
thrown.expect(RuntimeException.class);
UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]);
- uriReader.readString(new URI("file:/notfound"), Charsets.UTF_8);
+ uriReader.readString(new URI("file:/notfound"), StandardCharsets.UTF_8);
}
@Test
@Test
public void register_processors() throws Exception {
UriReader.SchemeProcessor processor = mock(UriReader.SchemeProcessor.class);
- when(processor.getSupportedSchemes()).thenReturn(new String[]{"ftp"});
- UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[]{processor});
+ when(processor.getSupportedSchemes()).thenReturn(new String[] {"ftp"});
+ UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[] {processor});
assertThat(uriReader.searchForSupportedProcessor(new URI("ftp://sonarsource.org"))).isNotNull();
}