Skip to content

Commit

Permalink
adding tests for no-op path resolver
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Atanasov <[email protected]>
  • Loading branch information
ata-nas committed Dec 2, 2024
1 parent 8dd7507 commit 1188626
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Arguments> 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<Arguments> 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));
}
}

0 comments on commit 1188626

Please sign in to comment.