Skip to content

Commit

Permalink
Last UT to complete coverage
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Aug 25, 2024
1 parent 689b6fc commit 56af241
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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() {

Expand Down

0 comments on commit 56af241

Please sign in to comment.