From 56af241e3b55d06bc2e9a041720facad68879679 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Sat, 24 Aug 2024 21:43:39 -0600 Subject: [PATCH] Last UT to complete coverage Signed-off-by: Alfredo Gutierrez --- .../PersistenceInjectionModuleTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/server/src/test/java/com/hedera/block/server/persistence/PersistenceInjectionModuleTest.java b/server/src/test/java/com/hedera/block/server/persistence/PersistenceInjectionModuleTest.java index 76641b76..70ed73e6 100644 --- a/server/src/test/java/com/hedera/block/server/persistence/PersistenceInjectionModuleTest.java +++ b/server/src/test/java/com/hedera/block/server/persistence/PersistenceInjectionModuleTest.java @@ -17,6 +17,8 @@ package com.hedera.block.server.persistence; import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; import com.hedera.block.server.config.BlockNodeContext; import com.hedera.block.server.persistence.storage.PersistenceStorageConfig; @@ -25,6 +27,7 @@ import com.hedera.block.server.util.TestConfigUtil; import com.hedera.hapi.block.stream.Block; import com.hedera.hapi.block.stream.BlockItem; +import com.swirlds.config.api.Configuration; import java.io.IOException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -56,6 +59,26 @@ void testProvidesBlockWriter() { assertNotNull(blockWriter); } + @Test + void testProvidesBlockWriter_IOException() { + BlockNodeContext blockNodeContext = mock(BlockNodeContext.class); + PersistenceStorageConfig persistenceStorageConfig = mock(PersistenceStorageConfig.class); + when(persistenceStorageConfig.rootPath()).thenReturn("invalid-path*9/////+>"); + Configuration configuration = mock(Configuration.class); + when(blockNodeContext.configuration()).thenReturn(configuration); + when(configuration.getConfigData(PersistenceStorageConfig.class)) + .thenReturn(persistenceStorageConfig); + + // Expect a RuntimeException due to the IOException + RuntimeException exception = + assertThrows( + RuntimeException.class, + () -> PersistenceInjectionModule.providesBlockWriter(blockNodeContext)); + + // Verify the exception message + assertTrue(exception.getMessage().contains("Failed to create block writer")); + } + @Test void testProvidesBlockReader() {