Skip to content

Commit

Permalink
Adding JUnit to project and first test
Browse files Browse the repository at this point in the history
Signed-off-by: Alfredo Gutierrez <[email protected]>
  • Loading branch information
AlfredoG87 committed Aug 30, 2024
1 parent 37a95e8 commit 8d9ce80
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
7 changes: 7 additions & 0 deletions simulator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class BlockStreamSimulator {

Configuration configuration;
BlockStreamManager blockStreamManager;
boolean isRunning = false;

@Inject
public BlockStreamSimulator(
Expand All @@ -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() {}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}

0 comments on commit 8d9ce80

Please sign in to comment.