From 4a35c6d953f36e6a421cd0829750870067301944 Mon Sep 17 00:00:00 2001 From: Mehdi AOUADI Date: Wed, 16 Oct 2024 11:47:50 +0200 Subject: [PATCH] make tests parametrized --- .../chainstorage/StorageServiceTest.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/services/chainstorage/src/test/java/tech/pegasys/teku/services/chainstorage/StorageServiceTest.java b/services/chainstorage/src/test/java/tech/pegasys/teku/services/chainstorage/StorageServiceTest.java index eddd7ca6f65..87176ec3319 100644 --- a/services/chainstorage/src/test/java/tech/pegasys/teku/services/chainstorage/StorageServiceTest.java +++ b/services/chainstorage/src/test/java/tech/pegasys/teku/services/chainstorage/StorageServiceTest.java @@ -26,6 +26,8 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import tech.pegasys.teku.ethereum.execution.types.Eth1Address; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.async.StubAsyncRunner; @@ -104,21 +106,12 @@ void shouldSetupStatePrunerWhenArchiveModeAndRetentionSlotsEnabled() { .isEqualTo(StorageConfiguration.DEFAULT_STATE_PRUNING_INTERVAL); } - @Test - void shouldSetupStatePrunerWhenPruneMode() { - when(storageConfiguration.getDataStorageMode()).thenReturn(StateStorageMode.PRUNE); - final SafeFuture future = storageService.doStart(); - final Optional maybeStatePruner = storageService.getStatePruner(); - assertThat(future).isCompleted(); - assertThat(maybeStatePruner).isPresent(); - final StatePruner statePruner = maybeStatePruner.get(); - assertThat(statePruner.isRunning()).isTrue(); - assertThat(statePruner.getPruneInterval()).isEqualTo(StorageService.STATE_PRUNING_INTERVAL); - } - - @Test - void shouldSetupStatePrunerWhenMinimalMode() { - when(storageConfiguration.getDataStorageMode()).thenReturn(StateStorageMode.MINIMAL); + @ParameterizedTest + @EnumSource( + value = StateStorageMode.class, + names = {"PRUNE", "MINIMAL"}) + void shouldSetupStatePrunerWhenPruneMode(final StateStorageMode stateStorageMode) { + when(storageConfiguration.getDataStorageMode()).thenReturn(stateStorageMode); final SafeFuture future = storageService.doStart(); final Optional maybeStatePruner = storageService.getStatePruner(); assertThat(future).isCompleted(); @@ -128,9 +121,12 @@ void shouldSetupStatePrunerWhenMinimalMode() { assertThat(statePruner.getPruneInterval()).isEqualTo(StorageService.STATE_PRUNING_INTERVAL); } - @Test - void shouldSetupStatePrunerWithCustomInterval() { - when(storageConfiguration.getDataStorageMode()).thenReturn(StateStorageMode.MINIMAL); + @ParameterizedTest + @EnumSource( + value = StateStorageMode.class, + names = {"PRUNE", "MINIMAL"}) + void shouldSetupStatePrunerWithCustomInterval(final StateStorageMode stateStorageMode) { + when(storageConfiguration.getDataStorageMode()).thenReturn(stateStorageMode); final Duration customPruningInterval = Duration.ofSeconds(8); when(storageConfiguration.getStatePruningInterval()).thenReturn(customPruningInterval); final SafeFuture future = storageService.doStart();