Skip to content

Commit

Permalink
Replaced Charset.forName with StandardCharsets
Browse files Browse the repository at this point in the history
  • Loading branch information
g4s8 committed May 25, 2017
1 parent cd3d932 commit 4a28576
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/test/java/org/cactoos/io/FileAsInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.cactoos.text.StringAsText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -45,7 +46,7 @@ public final class FileAsInputTest {
*/
@Test
public void readsFileContent() throws IOException {
final Charset utf = Charset.forName("UTF-8");
final Charset utf = StandardCharsets.UTF_8;
final File temp = File.createTempFile("cactoos", "txt");
temp.deleteOnExit();
MatcherAssert.assertThat(
Expand Down
17 changes: 5 additions & 12 deletions src/test/java/org/cactoos/io/InputAsBytesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package org.cactoos.io;

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import org.cactoos.text.StringAsText;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
Expand All @@ -39,28 +39,22 @@
*/
public final class InputAsBytesTest {

/**
* UTF-8 encoding.
*/
private static final String UTF8 = "UTF-8";

/**
* InputAsBytes can read input.
*
* @throws IOException If some problem inside
*/
@Test
public void readsInputIntoBytes() throws IOException {
final Charset utf = Charset.forName(InputAsBytesTest.UTF8);
MatcherAssert.assertThat(
new String(
new InputAsBytes(
new TextAsInput(
new StringAsText("Hello, друг!"),
utf
StandardCharsets.UTF_8
)
).asBytes(),
utf
StandardCharsets.UTF_8
),
Matchers.allOf(
Matchers.startsWith("Hello, "),
Expand All @@ -76,17 +70,16 @@ public void readsInputIntoBytes() throws IOException {
*/
@Test
public void readsInputIntoBytesWithSmallBuffer() throws IOException {
final Charset utf = Charset.forName(InputAsBytesTest.UTF8);
MatcherAssert.assertThat(
new String(
new InputAsBytes(
new TextAsInput(
new StringAsText("Hello, товарищ!"),
utf
StandardCharsets.UTF_8
),
2
).asBytes(),
utf
StandardCharsets.UTF_8
),
Matchers.allOf(
Matchers.startsWith("Hello,"),
Expand Down

0 comments on commit 4a28576

Please sign in to comment.