This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #865 from timkoon/issue-848
Close response InputStreams
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/java/org/opendatakit/briefcase/reused/UncheckedFilesInputStreamTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.opendatakit.briefcase.reused; | ||
|
||
import static org.opendatakit.briefcase.reused.UncheckedFiles.createFile; | ||
import static org.opendatakit.briefcase.reused.UncheckedFiles.createTempDirectory; | ||
import static org.opendatakit.briefcase.reused.UncheckedFiles.deleteRecursive; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.UncheckedIOException; | ||
import java.nio.file.Path; | ||
|
||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
|
||
public class UncheckedFilesInputStreamTest { | ||
private Path tempDir; | ||
private Path temp; | ||
|
||
|
||
@Before | ||
public void setUp() { | ||
tempDir = createTempDirectory("briefcase"); | ||
temp = tempDir.resolve("test.txt"); | ||
createFile(temp); | ||
} | ||
|
||
@After | ||
public void tearDown() { | ||
deleteRecursive(tempDir); | ||
} | ||
|
||
@Test(expected = IOException.class) | ||
public void closeInputStream_should_close() throws IOException { | ||
InputStream inputStream = UncheckedFiles.newInputStream(temp); | ||
|
||
UncheckedFiles.closeInputStream(inputStream); | ||
|
||
// after close, .available() should throw exception | ||
inputStream.available(); | ||
} | ||
|
||
@Test(expected = UncheckedIOException.class) | ||
public void closeInputStream_should_throw_exception() throws IOException { | ||
InputStream is = new InputStream() { | ||
@Override | ||
public int read() throws IOException { | ||
return 0; | ||
} | ||
@Override | ||
public void close() throws IOException { | ||
throw new IOException("chuchu"); | ||
} | ||
}; | ||
UncheckedFiles.closeInputStream(is); | ||
} | ||
} |