Skip to content

Commit

Permalink
Merge branch 'main' into extend_test_client
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianpilz authored Nov 15, 2024
2 parents e1343c2 + 7e41ddf commit e71a31d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- the collected data is now flushed after each precondition
- moved test case specific parameter into separate file test_parameter.toml
- sdc-ri version to 6.0.0-SNAPSHOT

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
package com.draeger.medical.sdccc.manipulation.precondition

import com.draeger.medical.sdccc.messages.MessageStorage
import com.google.inject.Inject
import com.google.inject.Injector
import com.google.inject.Singleton
Expand Down Expand Up @@ -101,6 +102,8 @@ class PreconditionRegistry @Inject internal constructor(private val injector: In
for (precondition in preconditions) {
logger.info { "Running precondition ${precondition.javaClass.simpleName}" }
precondition.verifyPrecondition(injector)
// flush data after each precondition to ensure that each precondition has most current data
injector.getInstance(MessageStorage::class.java).flush()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.draeger.medical.sdccc.messages.MessageStorage;
import com.google.inject.Injector;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
Expand All @@ -29,8 +31,16 @@
*/
public class PreconditionRegistryTest {

private PreconditionRegistry registry;

@BeforeEach
void setUp() {
final var mockInjector = mock(Injector.class);
final var messageStorageMock = mock(MessageStorage.class);
when(mockInjector.getInstance(MessageStorage.class)).thenReturn(messageStorageMock);

registry = new PreconditionRegistry(mockInjector);

PreconditionUtil.MockPrecondition.reset();
PreconditionUtil.MockManipulation.reset();
}
Expand All @@ -43,9 +53,6 @@ void setUp() {
@Test
@DisplayName("Tests registering a complex interaction and whether it's prompted for")
public void testPreconditionInteractionRegistrationAndPrompt() throws Exception {
final var mockInjector = mock(Injector.class);
final var registry = new PreconditionRegistry(mockInjector);

final var preconditionWasCalled = new AtomicBoolean(false);
PreconditionUtil.MockPrecondition.setIsPreconditionMet(injector -> {
preconditionWasCalled.set(true);
Expand Down Expand Up @@ -74,9 +81,6 @@ public void testPreconditionInteractionRegistrationAndPrompt() throws Exception
@Test
@DisplayName("Tests whether registering the same complex interaction thrice only prompts for it once")
public void testPreconditionInteractionRegisteredOnlyOnce() throws Exception {
final var mockInjector = mock(Injector.class);
final var registry = new PreconditionRegistry(mockInjector);

final var preconditionWasCalled = new AtomicInteger(0);
PreconditionUtil.MockPrecondition.setIsPreconditionMet(injector -> {
preconditionWasCalled.incrementAndGet();
Expand All @@ -98,9 +102,6 @@ public void testPreconditionInteractionRegisteredOnlyOnce() throws Exception {
@Test
@DisplayName("Tests whether an exception during registration causes a RuntimeException and stops the test run")
public void testPreconditionInteractionRegistrationException() {
final var mockInjector = mock(Injector.class);
final var registry = new PreconditionRegistry(mockInjector);

final var mockInteractionWasCalled = new AtomicInteger(0);
PreconditionUtil.MockPrecondition.setAfterConstructorCall(() -> {
mockInteractionWasCalled.incrementAndGet();
Expand All @@ -121,9 +122,6 @@ public void testPreconditionInteractionRegistrationException() {
@Test
@DisplayName("Tests registering a manipulation and whether it's prompted for")
public void testManipulationInteractionRegistrationAndPrompt() throws Exception {
final var mockInjector = mock(Injector.class);
final var registry = new PreconditionRegistry(mockInjector);

final var manipulationWasCalled = new AtomicBoolean(false);
PreconditionUtil.MockManipulation.setManipulationCall(injector -> {
manipulationWasCalled.set(true);
Expand All @@ -144,9 +142,6 @@ public void testManipulationInteractionRegistrationAndPrompt() throws Exception
@Test
@DisplayName("Tests whether registering the same manipulation thrice only prompts for it once")
public void testManipulationInteractionRegisteredOnlyOnce() throws Exception {
final var mockInjector = mock(Injector.class);
final var registry = new PreconditionRegistry(mockInjector);

final var manipulationWasCalled = new AtomicInteger(0);
PreconditionUtil.MockManipulation.setManipulationCall(injector -> {
manipulationWasCalled.incrementAndGet();
Expand All @@ -167,9 +162,6 @@ public void testManipulationInteractionRegisteredOnlyOnce() throws Exception {
@Test
@DisplayName("Tests whether an exception during registration causes a RuntimeException and stops the test run")
public void testManipulationInteractionRegistrationException() {
final var mockInjector = mock(Injector.class);
final var registry = new PreconditionRegistry(mockInjector);

final var mockInteractionWasCalled = new AtomicInteger(0);
PreconditionUtil.MockManipulation.setAfterConstructorCall(() -> {
mockInteractionWasCalled.incrementAndGet();
Expand All @@ -184,9 +176,6 @@ public void testManipulationInteractionRegistrationException() {

@Test
void testRegisteringObservingPreconditions() throws Exception {
final var mockInjector = mock(Injector.class);
final var registry = new PreconditionRegistry(mockInjector);

final KClass<? extends ObservingPreconditionFactory<?>> mockPreconditionFactory = mock(KClass.class);

final var mockFactory = mock(ObservingPreconditionFactory.class);
Expand All @@ -211,9 +200,6 @@ void testRegisteringObservingPreconditions() throws Exception {

@Test
void testRegisteringObservingPreconditionsFailsWhenNoObjectInstanceAvailable() {
final var mockInjector = mock(Injector.class);
final var registry = new PreconditionRegistry(mockInjector);

final KClass<? extends ObservingPreconditionFactory<?>> mockPreconditionFactory = mock(KClass.class);

final var mockFactory = mock(ObservingPreconditionFactory.class);
Expand Down

0 comments on commit e71a31d

Please sign in to comment.