diff --git a/server/src/main/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalFilePathResolver.java b/server/src/main/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalFilePathResolver.java index 4a8c4c62..6b2235cb 100644 --- a/server/src/main/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalFilePathResolver.java +++ b/server/src/main/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalFilePathResolver.java @@ -20,7 +20,6 @@ import com.hedera.block.server.Constants; import edu.umd.cs.findbugs.annotations.NonNull; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.Objects; /** diff --git a/server/src/test/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalDirPathResolverTest.java b/server/src/test/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalDirPathResolverTest.java index 4f62f42e..9a9a7ade 100644 --- a/server/src/test/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalDirPathResolverTest.java +++ b/server/src/test/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalDirPathResolverTest.java @@ -49,6 +49,7 @@ void setUp() { * the live root path appended with the given block number. * * @param toResolve parameterized, valid block number + * @param expected parameterized, expected path */ @ParameterizedTest @MethodSource("validBlockNumbers") diff --git a/server/src/test/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalFilePathResolverTest.java b/server/src/test/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalFilePathResolverTest.java index 8f4b0fee..fe438b34 100644 --- a/server/src/test/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalFilePathResolverTest.java +++ b/server/src/test/java/com/hedera/block/server/persistence/storage/path/BlockAsLocalFilePathResolverTest.java @@ -53,6 +53,7 @@ void setUp() { * itself is the file name. * * @param toResolve parameterized, valid block number + * @param expected parameterized, expected path */ @ParameterizedTest @MethodSource("validBlockNumbers") diff --git a/server/src/test/java/com/hedera/block/server/persistence/storage/path/NoOpBlockPathResolverTest.java b/server/src/test/java/com/hedera/block/server/persistence/storage/path/NoOpBlockPathResolverTest.java new file mode 100644 index 00000000..fc689572 --- /dev/null +++ b/server/src/test/java/com/hedera/block/server/persistence/storage/path/NoOpBlockPathResolverTest.java @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2024 Hedera Hashgraph, LLC + * + * Licensed 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 com.hedera.block.server.persistence.storage.path; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.nio.file.Path; +import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +/** + * Tests for the {@link NoOpBlockPathResolver} class. + */ +class NoOpBlockPathResolverTest { + private NoOpBlockPathResolver toTest; + + @BeforeEach + void setUp() { + toTest = NoOpBlockPathResolver.newInstance(); + } + + /** + * This test aims to verify that the + * {@link NoOpBlockPathResolver#resolvePathToBlock(long)} correctly resolves + * the path to a block by a given number. The no-op resolver does nothing, + * always returns null and has no preconditions check. + * + * @param toResolve parameterized, block number + */ + @ParameterizedTest + @MethodSource({"validBlockNumbers", "invalidBlockNumbers"}) + void testSuccessfulPathResolution(final long toResolve) { + final Path actual = toTest.resolvePathToBlock(toResolve); + // we always expect null, no preconditions as well + assertThat(actual).isNull(); + } + + /** + * Some valid block numbers. + * + * @return a stream of valid block numbers + */ + public static Stream validBlockNumbers() { + return Stream.of( + Arguments.of(0L), + Arguments.of(1L), + Arguments.of(2L), + Arguments.of(10L), + Arguments.of(100L), + Arguments.of(1_000L), + Arguments.of(10_000L), + Arguments.of(100_000L), + Arguments.of(1_000_000L), + Arguments.of(10_000_000L), + Arguments.of(100_000_000L), + Arguments.of(1_000_000_000L), + Arguments.of(10_000_000_000L), + Arguments.of(100_000_000_000L), + Arguments.of(1_000_000_000_000L), + Arguments.of(10_000_000_000_000L), + Arguments.of(100_000_000_000_000L), + Arguments.of(1_000_000_000_000_000L), + Arguments.of(10_000_000_000_000_000L), + Arguments.of(100_000_000_000_000_000L), + Arguments.of(1_000_000_000_000_000_000L), + Arguments.of(Long.MAX_VALUE)); + } + + /** + * Some invalid block numbers. + * + * @return a stream of invalid block numbers + */ + public static Stream invalidBlockNumbers() { + return Stream.of( + Arguments.of(-1L), + Arguments.of(-2L), + Arguments.of(-10L), + Arguments.of(-100L), + Arguments.of(-1_000L), + Arguments.of(-10_000L), + Arguments.of(-100_000L), + Arguments.of(-1_000_000L), + Arguments.of(-10_000_000L), + Arguments.of(-100_000_000L), + Arguments.of(-1_000_000_000L), + Arguments.of(-10_000_000_000L), + Arguments.of(-100_000_000_000L), + Arguments.of(-1_000_000_000_000L), + Arguments.of(-10_000_000_000_000L), + Arguments.of(-100_000_000_000_000L), + Arguments.of(-1_000_000_000_000_000L), + Arguments.of(-10_000_000_000_000_000L), + Arguments.of(-100_000_000_000_000_000L), + Arguments.of(-1_000_000_000_000_000_000L), + Arguments.of(Long.MIN_VALUE)); + } +}