From 8d9ce80952c8627338b6b8c30040209ff71e5d55 Mon Sep 17 00:00:00 2001 From: Alfredo Gutierrez Date: Fri, 30 Aug 2024 16:08:58 -0600 Subject: [PATCH] Adding JUnit to project and first test Signed-off-by: Alfredo Gutierrez --- simulator/build.gradle.kts | 7 +++ .../block/simulator/BlockStreamSimulator.java | 7 ++- .../simulator/BlockStreamSimulatorTest.java | 60 +++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 simulator/src/test/java/com/hedera/block/simulator/BlockStreamSimulatorTest.java diff --git a/simulator/build.gradle.kts b/simulator/build.gradle.kts index 5cbbcab7..54d8ab76 100644 --- a/simulator/build.gradle.kts +++ b/simulator/build.gradle.kts @@ -31,3 +31,10 @@ mainModuleInfo { annotationProcessor("com.google.auto.service.processor") runtimeOnly("com.swirlds.config.impl") } + +testModuleInfo { + requires("org.junit.jupiter.api") + requires("org.mockito") + requires("org.mockito.junit.jupiter") + requiresStatic("com.github.spotbugs.annotations") +} diff --git a/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java b/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java index 99796735..05f433ea 100644 --- a/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java +++ b/simulator/src/main/java/com/hedera/block/simulator/BlockStreamSimulator.java @@ -29,6 +29,7 @@ public class BlockStreamSimulator { Configuration configuration; BlockStreamManager blockStreamManager; + boolean isRunning = false; @Inject public BlockStreamSimulator( @@ -55,9 +56,13 @@ public void start() { // use blockStreamManager to get block stream // use PublishStreamGrpcClient to stream it to the block-node. - + isRunning = true; LOGGER.log(Logger.Level.INFO, "Block Stream Simulator has started"); } + public boolean isRunning() { + return isRunning; + } + public void stop() {} } diff --git a/simulator/src/test/java/com/hedera/block/simulator/BlockStreamSimulatorTest.java b/simulator/src/test/java/com/hedera/block/simulator/BlockStreamSimulatorTest.java new file mode 100644 index 00000000..71bd1b17 --- /dev/null +++ b/simulator/src/test/java/com/hedera/block/simulator/BlockStreamSimulatorTest.java @@ -0,0 +1,60 @@ +/* + * 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.simulator; + +import static org.junit.jupiter.api.Assertions.*; + +import com.hedera.block.simulator.generator.BlockStreamManager; +import com.swirlds.config.api.Configuration; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class BlockStreamSimulatorTest { + + @Mock private Configuration configuration; + + @Mock private BlockStreamManager blockStreamManager; + + @InjectMocks private BlockStreamSimulator blockStreamSimulator; + + @BeforeEach + void setUp() { + blockStreamSimulator = new BlockStreamSimulator(configuration, blockStreamManager); + } + + @AfterEach + void tearDown() { + blockStreamSimulator.stop(); + } + + @Test + void start_logsStartedMessage() { + blockStreamSimulator.start(); + assertTrue(blockStreamSimulator.isRunning()); + } + + @Test + void stop_doesNotThrowException() { + assertDoesNotThrow(() -> blockStreamSimulator.stop()); + } +}