Copilot commented on code in PR #708: URL: https://github.com/apache/commons-compress/pull/708#discussion_r2365548412
########## src/test/java/org/apache/commons/compress/LegacyConstructorsTest.java: ########## @@ -0,0 +1,220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.compress; + +import static java.nio.charset.StandardCharsets.US_ASCII; +import static org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField; +import static org.apache.commons.lang3.reflect.FieldUtils.readField; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; + +import java.io.InputStream; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.util.stream.Stream; + +import org.apache.commons.compress.archivers.arj.ArjArchiveInputStream; +import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream; +import org.apache.commons.compress.archivers.dump.DumpArchiveInputStream; +import org.apache.commons.compress.archivers.jar.JarArchiveInputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Verifies that deprecated constructors are equivalent to the new builder pattern. + */ +@Tag("deprecated") +@SuppressWarnings("deprecation") // testing deprecated code +class LegacyConstructorsTest extends AbstractTest { + + @Test + void testArjConstructor() throws Exception { + try (InputStream inputStream = Files.newInputStream(getPath("bla.arj")); + ArjArchiveInputStream archiveInputStream = new ArjArchiveInputStream(inputStream, "US-ASCII")) { + // Arj wraps the input stream in a DataInputStream + assertEquals(inputStream, getNestedInputStream(getNestedInputStream(archiveInputStream))); + assertEquals(US_ASCII, archiveInputStream.getCharset()); + } + } + + static Stream<Arguments> testCpioConstructors() { + final InputStream inputStream = mock(InputStream.class); + return Stream.of( + Arguments.of(new CpioArchiveInputStream(inputStream, 1024), inputStream, "US-ASCII", 1024), + Arguments.of(new CpioArchiveInputStream(inputStream, 1024, "UTF-8"), inputStream, "UTF-8", 1024), + Arguments.of(new CpioArchiveInputStream(inputStream, "UTF-8"), inputStream, "UTF-8", 512)); + } + + @ParameterizedTest + @MethodSource + void testCpioConstructors( + CpioArchiveInputStream archiveStream, + InputStream expectedInput, + String expectedEncoding, + int expectedBlockSize) + throws Exception { + assertEquals(expectedInput, getNestedInputStream(archiveStream)); + assertEquals(Charset.forName(expectedEncoding), archiveStream.getCharset()); + assertEquals(expectedBlockSize, readDeclaredField(archiveStream, "blockSize", true)); + } + + @Test + void testDumpConstructor() throws Exception { + final String otherEncoding = "UTF-8".equals(Charset.defaultCharset().name()) ? "US-ASCII" : "UTF-8"; + try (InputStream inputStream = Files.newInputStream(getPath("bla.dump")); + DumpArchiveInputStream archiveStream = new DumpArchiveInputStream(inputStream, otherEncoding)) { + assertEquals(inputStream, getNestedInputStream(archiveStream)); + assertEquals(Charset.forName(otherEncoding), archiveStream.getCharset()); + } + } + + @Test + void testJarConstructor() throws Exception { + final InputStream inputStream = mock(InputStream.class); + try (JarArchiveInputStream archiveInputStream = new JarArchiveInputStream(inputStream, "US-ASCII")) { + assertEquals(US_ASCII, archiveInputStream.getCharset()); + } + } + + static Stream<Arguments> testTarContructors() { Review Comment: Method name has a typo: 'testTarContructors' should be 'testTarConstructors'. ########## src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java: ########## @@ -138,7 +138,7 @@ private ArjArchiveInputStream(final InputStream inputStream, final Builder build * @param inputStream the underlying stream, whose ownership is taken * @param charsetName the charset used for file names and comments in the archive. May be {@code null} to use the platform default. * @throws ArchiveException if an exception occurs while reading - * @deprecated Use {@link #builder()} and {@link Builder}. + * @deprecated Since 1.29.0 use {@link #builder()}. Review Comment: Missing comma after version number. Should be 'Since 1.29.0, use {@link #builder()}'. ```suggestion * @deprecated Since 1.29.0, use {@link #builder()}. ``` ########## src/test/java/org/apache/commons/compress/LegacyConstructorsTest.java: ########## @@ -0,0 +1,220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.commons.compress; + +import static java.nio.charset.StandardCharsets.US_ASCII; +import static org.apache.commons.lang3.reflect.FieldUtils.readDeclaredField; +import static org.apache.commons.lang3.reflect.FieldUtils.readField; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; + +import java.io.InputStream; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.util.stream.Stream; + +import org.apache.commons.compress.archivers.arj.ArjArchiveInputStream; +import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream; +import org.apache.commons.compress.archivers.dump.DumpArchiveInputStream; +import org.apache.commons.compress.archivers.jar.JarArchiveInputStream; +import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; +import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Verifies that deprecated constructors are equivalent to the new builder pattern. + */ +@Tag("deprecated") +@SuppressWarnings("deprecation") // testing deprecated code +class LegacyConstructorsTest extends AbstractTest { + + @Test + void testArjConstructor() throws Exception { + try (InputStream inputStream = Files.newInputStream(getPath("bla.arj")); + ArjArchiveInputStream archiveInputStream = new ArjArchiveInputStream(inputStream, "US-ASCII")) { + // Arj wraps the input stream in a DataInputStream + assertEquals(inputStream, getNestedInputStream(getNestedInputStream(archiveInputStream))); + assertEquals(US_ASCII, archiveInputStream.getCharset()); + } + } + + static Stream<Arguments> testCpioConstructors() { + final InputStream inputStream = mock(InputStream.class); + return Stream.of( + Arguments.of(new CpioArchiveInputStream(inputStream, 1024), inputStream, "US-ASCII", 1024), + Arguments.of(new CpioArchiveInputStream(inputStream, 1024, "UTF-8"), inputStream, "UTF-8", 1024), + Arguments.of(new CpioArchiveInputStream(inputStream, "UTF-8"), inputStream, "UTF-8", 512)); + } + + @ParameterizedTest + @MethodSource + void testCpioConstructors( + CpioArchiveInputStream archiveStream, + InputStream expectedInput, + String expectedEncoding, + int expectedBlockSize) + throws Exception { + assertEquals(expectedInput, getNestedInputStream(archiveStream)); + assertEquals(Charset.forName(expectedEncoding), archiveStream.getCharset()); + assertEquals(expectedBlockSize, readDeclaredField(archiveStream, "blockSize", true)); + } + + @Test + void testDumpConstructor() throws Exception { + final String otherEncoding = "UTF-8".equals(Charset.defaultCharset().name()) ? "US-ASCII" : "UTF-8"; + try (InputStream inputStream = Files.newInputStream(getPath("bla.dump")); + DumpArchiveInputStream archiveStream = new DumpArchiveInputStream(inputStream, otherEncoding)) { + assertEquals(inputStream, getNestedInputStream(archiveStream)); + assertEquals(Charset.forName(otherEncoding), archiveStream.getCharset()); + } + } + + @Test + void testJarConstructor() throws Exception { + final InputStream inputStream = mock(InputStream.class); + try (JarArchiveInputStream archiveInputStream = new JarArchiveInputStream(inputStream, "US-ASCII")) { + assertEquals(US_ASCII, archiveInputStream.getCharset()); + } + } + + static Stream<Arguments> testTarContructors() { + final InputStream inputStream = mock(InputStream.class); + final String defaultEncoding = Charset.defaultCharset().name(); + final String otherEncoding = "UTF-8".equals(defaultEncoding) ? "US-ASCII" : "UTF-8"; + return Stream.of( + Arguments.of( + new TarArchiveInputStream(inputStream, true), inputStream, 10240, 512, defaultEncoding, true), + Arguments.of( + new TarArchiveInputStream(inputStream, 20480), inputStream, 20480, 512, defaultEncoding, false), + Arguments.of( + new TarArchiveInputStream(inputStream, 20480, 1024), + inputStream, + 20480, + 1024, + defaultEncoding, + false), + Arguments.of( + new TarArchiveInputStream(inputStream, 20480, 1024, otherEncoding), + inputStream, + 20480, + 1024, + otherEncoding, + false), + Arguments.of( + new TarArchiveInputStream(inputStream, 20480, 1024, otherEncoding, true), + inputStream, + 20480, + 1024, + otherEncoding, + true), + Arguments.of( + new TarArchiveInputStream(inputStream, 20480, otherEncoding), + inputStream, + 20480, + 512, + otherEncoding, + false), + Arguments.of( + new TarArchiveInputStream(inputStream, otherEncoding), + inputStream, + 10240, + 512, + otherEncoding, + false)); + } + + @ParameterizedTest + @MethodSource + void testTarContructors( Review Comment: Method name has a typo: 'testTarContructors' should be 'testTarConstructors'. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
