rdblue commented on code in PR #16500: URL: https://github.com/apache/iceberg/pull/16500#discussion_r3313167899
########## core/src/test/java/org/apache/iceberg/util/TestContentFileUtil.java: ########## @@ -0,0 +1,97 @@ +/* + * 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 + * + * http://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.iceberg.util; + +import static org.assertj.core.api.Assertions.assertThatCode; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import org.apache.iceberg.DeleteFile; +import org.junit.jupiter.api.Test; + +public class TestContentFileUtil { + + @Test + public void validateDVRejectsNullOffset() { + DeleteFile dv = dv(null, 10L); + assertThatThrownBy(() -> ContentFileUtil.validateDV(dv)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("offset cannot be null"); + } + + @Test + public void validateDVRejectsNullLength() { + DeleteFile dv = dv(0L, null); + assertThatThrownBy(() -> ContentFileUtil.validateDV(dv)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("length cannot be null"); + } + + @Test + public void validateDVRejectsNegativeOffset() { + DeleteFile dv = dv(-1L, 10L); + assertThatThrownBy(() -> ContentFileUtil.validateDV(dv)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("offset must be non-negative"); + } + + @Test + public void validateDVRejectsNegativeLength() { + DeleteFile dv = dv(0L, -1L); + assertThatThrownBy(() -> ContentFileUtil.validateDV(dv)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("length must be non-negative"); + } + + @Test + public void validateDVRejectsLengthAboveIntegerMax() { + DeleteFile dv = dv(0L, (long) Integer.MAX_VALUE + 1); + assertThatThrownBy(() -> ContentFileUtil.validateDV(dv)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Can't read DV larger than 2GB"); + } + + @Test + public void validateDVAcceptsZero() { + DeleteFile dv = dv(0L, 0L); + assertThatCode(() -> ContentFileUtil.validateDV(dv)).doesNotThrowAnyException(); + } + + @Test + public void validateDVAcceptsTypicalValues() { + DeleteFile dv = dv(4L, 4096L); + assertThatCode(() -> ContentFileUtil.validateDV(dv)).doesNotThrowAnyException(); + } + + @Test + public void validateDVAcceptsMaximumLength() { + DeleteFile dv = dv(0L, (long) Integer.MAX_VALUE); + assertThatCode(() -> ContentFileUtil.validateDV(dv)).doesNotThrowAnyException(); + } + + private static DeleteFile dv(Long offset, Long length) { Review Comment: There's no need for a mock. Can't this use the builder like the other tests? What was the purpose of using a mock instead of a real implementation? -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
