test adjustments

This commit is contained in:
Ulisses Lima 2023-06-02 19:37:30 -03:00
parent 8a6a9b3273
commit 95e8e24ddd
5 changed files with 15 additions and 11 deletions

View File

@ -41,11 +41,9 @@ public class TarExtractorVfs extends TarExtractor {
if (entry.isReadable() && entry.getType() == FileType.FILE) {
Files.createDirectories(extractTo.getParent());
try (FileContent fc = entry.getContent(); InputStream stream = fc.getInputStream()) {
try (FileContent content = entry.getContent(); InputStream stream = content.getInputStream()) {
Files.copy(stream, extractTo, StandardCopyOption.REPLACE_EXISTING);
}
} else {
Files.createDirectories(extractTo);
}
}

View File

@ -3,6 +3,12 @@ package com.baeldung.commons.untar;
import java.io.InputStream;
public interface Resources {
InputStream TAR_FILE = Resources.class.getResourceAsStream("/untar/test.tar");
InputStream TAR_GZ_FILE = Resources.class.getResourceAsStream("/untar/test.tar.gz");
static InputStream tarFile() {
return Resources.class.getResourceAsStream("/untar/test.tar");
}
static InputStream tarGzFile() {
return Resources.class.getResourceAsStream("/untar/test.tar.gz");
}
}

View File

@ -17,7 +17,7 @@ public class TarExtractorAntUnitTest {
public void givenTarFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/ant");
new TarExtractorAnt(Resources.TAR_FILE, false, destination).untar();
new TarExtractorAnt(Resources.tarFile(), false, destination).untar();
assertTrue(Files.list(destination)
.findFirst()
@ -28,7 +28,7 @@ public class TarExtractorAntUnitTest {
public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/ant-gz");
new TarExtractorAnt(Resources.TAR_GZ_FILE, true, destination).untar();
new TarExtractorAnt(Resources.tarGzFile(), true, destination).untar();
assertTrue(Files.list(destination)
.findFirst()

View File

@ -17,7 +17,7 @@ public class TarExtractorCommonsCompressUnitTest {
public void givenTarFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/commons-compress");
new TarExtractorCommonsCompress(Resources.TAR_FILE, false, destination).untar();
new TarExtractorCommonsCompress(Resources.tarFile(), false, destination).untar();
assertTrue(Files.list(destination)
.findFirst()
@ -28,7 +28,7 @@ public class TarExtractorCommonsCompressUnitTest {
public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/commons-compress-gz");
new TarExtractorCommonsCompress(Resources.TAR_GZ_FILE, true, destination).untar();
new TarExtractorCommonsCompress(Resources.tarGzFile(), true, destination).untar();
assertTrue(Files.list(destination)
.findFirst()

View File

@ -17,7 +17,7 @@ public class TarExtractorVfsUnitTest {
public void givenTarFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/vfs");
new TarExtractorVfs(Resources.TAR_FILE, false, destination).untar();
new TarExtractorVfs(Resources.tarFile(), false, destination).untar();
assertTrue(Files.list(destination)
.findFirst()
@ -28,7 +28,7 @@ public class TarExtractorVfsUnitTest {
public void givenTarGzFile_whenUntar_thenExtractedToDestination() throws IOException {
Path destination = Paths.get("/tmp/vfs-gz");
new TarExtractorVfs(Resources.TAR_GZ_FILE, true, destination).untar();
new TarExtractorVfs(Resources.tarGzFile(), true, destination).untar();
assertTrue(Files.list(destination)
.findFirst()