Skip to content
Permalink
Browse files
Fix broken tests.
  • Loading branch information
garydgregory committed May 5, 2022
1 parent 169277a commit 10076e058b1f3d67558c304afa78f92da02f5dc6
Showing 4 changed files with 60 additions and 119 deletions.
@@ -18,9 +18,16 @@
*/
package org.apache.commons.compress.archivers.tar;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.commons.compress.archivers.tar.TarConstants.CHKSUMLEN;
import static org.apache.commons.compress.archivers.tar.TarConstants.CHKSUM_OFFSET;
import static org.apache.commons.compress.archivers.tar.TarConstants.SPARSE_NUMBYTES_LEN;
import static org.apache.commons.compress.archivers.tar.TarConstants.SPARSE_OFFSET_LEN;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -34,12 +41,6 @@
import org.apache.commons.compress.utils.CharsetNames;
import org.apache.commons.compress.utils.IOUtils;

import static java.nio.charset.StandardCharsets.*;
import static org.apache.commons.compress.archivers.tar.TarConstants.CHKSUMLEN;
import static org.apache.commons.compress.archivers.tar.TarConstants.CHKSUM_OFFSET;
import static org.apache.commons.compress.archivers.tar.TarConstants.SPARSE_NUMBYTES_LEN;
import static org.apache.commons.compress.archivers.tar.TarConstants.SPARSE_OFFSET_LEN;

/**
* This class provides static utility methods to work with byte streams.
*
@@ -854,7 +855,7 @@ protected static List<TarArchiveStructSparse> parsePAX01SparseHeaders(String spa
try {
return parseFromPAX01SparseHeaders(sparseMap);
} catch (IOException ex) {
throw new RuntimeException(ex.getMessage(), ex);
throw new UncheckedIOException(ex.getMessage(), ex);
}
}

@@ -25,9 +25,9 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -262,12 +262,12 @@ public void negativeOffsetInConstructorNotAllowed() throws IOException {
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" +
"\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000").getBytes(UTF_8);
new TarArchiveEntry(entryContent, ZipEncodingHelper.getZipEncoding(CharsetNames.ISO_8859_1), false, -1);
assertThrows(IOException.class, () -> new TarArchiveEntry(entryContent, ZipEncodingHelper.getZipEncoding(CharsetNames.ISO_8859_1), false, -1));
}

@Test
public void negativeOffsetInSetterNotAllowed() {
new TarArchiveEntry("test").setDataOffset(-1);
assertThrows(IllegalArgumentException.class, () -> new TarArchiveEntry("test").setDataOffset(-1));
}

@Test
@@ -305,7 +305,7 @@ public void getOrderedSparseHeadersRejectsStructsPointingBeyondOutputEntry() thr
final TarArchiveEntry te = new TarArchiveEntry("test");
te.setSparseHeaders(Arrays.asList(new TarArchiveStructSparse(200, 2)));
te.fillStarSparseData(Collections.singletonMap("SCHILY.realsize", "201"));
te.getOrderedSparseHeaders();
assertThrows(IOException.class, () -> te.getOrderedSparseHeaders());
}

@Test
@@ -23,9 +23,9 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
@@ -103,7 +103,7 @@ public void testBigNumberErrorMode() throws Exception {
t.setSize(0100000000000L);
final ByteArrayOutputStream bos = new ByteArrayOutputStream();
final TarArchiveOutputStream tos = new TarArchiveOutputStream(bos);
tos.putArchiveEntry(t);
assertThrows(IllegalArgumentException.class, () -> tos.putArchiveEntry(t));
}

@Test
@@ -790,7 +790,7 @@ public void testWriteLongFileNameThrowsException() throws Exception {
+ "01234567890123456789012345678901234567890123456789";
final TarArchiveEntry t = new TarArchiveEntry(n);
final TarArchiveOutputStream tos = new TarArchiveOutputStream(new ByteArrayOutputStream(), "ASCII");
tos.putArchiveEntry(t);
assertThrows(IllegalArgumentException.class, () -> tos.putArchiveEntry(t));
}

private static byte[] createTarArchiveContainingOneDirectory(final String fname,

0 comments on commit 10076e0

Please sign in to comment.