Skip to content

Commit

Permalink
Adding Unit Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Aug 6, 2024
1 parent e4a2bbc commit 835bc88
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.hedera.block.server.config;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class BlockNodeContextFactoryTest {

@Test
void create_returnsBlockNodeContext() {
BlockNodeContext context = BlockNodeContextFactory.create();

assertNotNull(context.metrics());
assertNotNull(context.configuration());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.hedera.block.server.config;

import com.swirlds.config.api.Configuration;
import com.swirlds.metrics.api.Metrics;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class BlockNodeContextTest {

@Test
void BlockNodeContext_initializesWithMetricsAndConfiguration() {
Metrics metrics = mock(Metrics.class);
Configuration configuration = mock(Configuration.class);

BlockNodeContext context = new BlockNodeContext(metrics, configuration);

assertEquals(metrics, context.metrics());
assertEquals(configuration, context.configuration());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.hedera.block.server.metrics;

import com.swirlds.metrics.api.Counter;
import com.swirlds.metrics.api.LongGauge;
import com.swirlds.metrics.api.Metrics;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

class MetricsServiceTest {

@Test
void MetricsService_initializesExampleGauge() {
Metrics metrics = mock(Metrics.class);
LongGauge exampleGauge = mock(LongGauge.class);
when(metrics.getOrCreate(any(LongGauge.Config.class))).thenReturn(exampleGauge);

MetricsService service = new MetricsService(metrics);

assertEquals(exampleGauge, service.exampleGauge);
}

@Test
void MetricsService_initializesExampleCounter() {
Metrics metrics = mock(Metrics.class);
Counter exampleCounter = mock(Counter.class);
when(metrics.getOrCreate(any(Counter.Config.class))).thenReturn(exampleCounter);

MetricsService service = new MetricsService(metrics);

assertEquals(exampleCounter, service.exampleCounter);
}

@Test
void MetricsService_handlesNullMetrics() {
assertThrows(NullPointerException.class, () -> new MetricsService(null));
}
}

0 comments on commit 835bc88

Please sign in to comment.