Skip to content

Commit

Permalink
yegor256#702 removing temporary files in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krzyk committed Apr 20, 2018
1 parent 0bfef81 commit 17ad9e1
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 12 deletions.
10 changes: 9 additions & 1 deletion src/test/java/org/cactoos/io/InputOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.takes.http.FtRemote;
import org.takes.tk.TkHtml;

Expand All @@ -56,6 +58,11 @@
*/
@SuppressWarnings("PMD.TooManyMethods")
public final class InputOfTest {
/**
* Temporary files and folders generator.
*/
@Rule
public final TemporaryFolder folder = new TemporaryFolder();

@Test
public void readsAlternativeInputForFileCase() throws IOException {
Expand All @@ -75,7 +82,8 @@ public void readsAlternativeInputForFileCase() throws IOException {

@Test
public void readsSimpleFileContent() throws IOException {
final Path temp = Files.createTempFile("cactoos-1", "txt-1");
final Path temp = this.folder.newFile("cactoos-1.txt-1")
.toPath();
final String content = "Hello, товарищ!";
Files.write(temp, content.getBytes(StandardCharsets.UTF_8));
MatcherAssert.assertThat(
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/org/cactoos/io/InputStreamOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* Test case for {@link InputStreamOf}.
Expand All @@ -46,10 +48,16 @@
*/
@SuppressWarnings("PMD.TooManyMethods")
public final class InputStreamOfTest {
/**
* Temporary files and folders generator.
*/
@Rule
public final TemporaryFolder folder = new TemporaryFolder();

@Test
public void readsSimpleFileContent() throws IOException {
final Path temp = Files.createTempFile("cactoos-1", "txt-1");
final Path temp = this.folder.newFile("cactoos-1.txt-1")
.toPath();
final String content = "Hello, товарищ!";
Files.write(temp, content.getBytes(StandardCharsets.UTF_8));
MatcherAssert.assertThat(
Expand Down
12 changes: 9 additions & 3 deletions src/test/java/org/cactoos/io/LoggingOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* Test case for {@link LoggingOutput}.
Expand All @@ -50,6 +51,11 @@
}
)
public final class LoggingOutputTest {
/**
* Temporary files and folders generator.
*/
@Rule
public final TemporaryFolder folder = new TemporaryFolder();

@Test
public void logWriteZero() throws IOException {
Expand Down Expand Up @@ -112,7 +118,7 @@ public void logWriteText() throws IOException {
@Test
public void logWriteToLargeTextFile() throws Exception {
final Logger logger = new FakeLogger();
final Path temp = Files.createTempDirectory("ccts-1");
final Path temp = this.folder.newFolder("ccts-1").toPath();
final Path path = temp.resolve("x/y/z/file.txt");
new LengthOf(
new TeeInput(
Expand Down Expand Up @@ -142,7 +148,7 @@ public void logWriteToLargeTextFile() throws Exception {
@Test
public void logAllWriteToLargeTextFile() throws Exception {
final Logger logger = new FakeLogger(Level.WARNING);
final Path temp = Files.createTempDirectory("ccts-2");
final Path temp = this.folder.newFolder("ccts-2").toPath();
final Path path = temp.resolve("a/b/c/file.txt");
new LengthOf(
new TeeInput(
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/org/cactoos/io/OutputStreamToTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
package org.cactoos.io;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.cactoos.matchers.MatcherOf;
import org.cactoos.matchers.TextHasString;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* Test case for {@link OutputStreamTo}.
Expand All @@ -42,10 +43,16 @@
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class OutputStreamToTest {
/**
* Temporary files and folders generator.
*/
@Rule
public final TemporaryFolder folder = new TemporaryFolder();

@Test
public void writesLargeContentToFile() throws IOException {
final Path temp = Files.createTempFile("cactoos-1", "txt-1");
final Path temp = this.folder.newFile("cactoos-1.txt-1")
.toPath();
MatcherAssert.assertThat(
"Can't copy Input to Output and return Input",
new TextOf(
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/org/cactoos/io/WriterAsOutputStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import org.cactoos.matchers.TextHasString;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* Test case for {@link WriterAsOutputStream}.
Expand All @@ -48,6 +50,11 @@
*/
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public final class WriterAsOutputStreamTest {
/**
* Temporary files and folders generator.
*/
@Rule
public final TemporaryFolder folder = new TemporaryFolder();

@Test
public void writesToByteArray() {
Expand Down Expand Up @@ -84,7 +91,8 @@ public void writesToByteArray() {

@Test
public void writesLargeContentToFile() throws IOException {
final Path temp = Files.createTempFile("cactoos-1", "txt-1");
final Path temp = this.folder.newFile("cactoos-1.txt-1")
.toPath();
MatcherAssert.assertThat(
"Can't copy Input to Output and return Input",
new TextOf(
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/org/cactoos/io/WriterAsOutputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import org.cactoos.matchers.MatcherOf;
import org.cactoos.matchers.TextHasString;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* Test case for {@link WriterAsOutput}.
Expand All @@ -45,10 +46,16 @@
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class WriterAsOutputTest {
/**
* Temporary files and folders generator.
*/
@Rule
public final TemporaryFolder folder = new TemporaryFolder();

@Test
public void writesLargeContentToFile() throws IOException {
final Path temp = Files.createTempFile("cactoos-1", "txt-1");
final Path temp = this.folder.newFile("cactoos-1.txt-1")
.toPath();
MatcherAssert.assertThat(
"Can't copy Input to Output and return Input",
new TextOf(
Expand Down
11 changes: 9 additions & 2 deletions src/test/java/org/cactoos/io/WriterToTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@
package org.cactoos.io;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import org.cactoos.matchers.MatcherOf;
import org.cactoos.matchers.TextHasString;
import org.cactoos.text.TextOf;
import org.hamcrest.MatcherAssert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

/**
* Test case for {@link WriterTo}.
Expand All @@ -42,10 +43,16 @@
* @checkstyle ClassDataAbstractionCouplingCheck (500 lines)
*/
public final class WriterToTest {
/**
* Temporary files and folders generator.
*/
@Rule
public final TemporaryFolder folder = new TemporaryFolder();

@Test
public void writesLargeContentToFile() throws IOException {
final Path temp = Files.createTempFile("cactoos-1", "txt-1");
final Path temp = this.folder.newFile("cactoos-1.txt-1")
.toPath();
MatcherAssert.assertThat(
"Can't copy Input to Output and return Input",
new TextOf(
Expand Down

0 comments on commit 17ad9e1

Please sign in to comment.