Skip to content

Commit

Permalink
Add JupiterEngineTests
Browse files Browse the repository at this point in the history
  • Loading branch information
YongGoose committed Feb 27, 2025
1 parent 62bcb8f commit 9fd3ba2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ public class NamespacedHierarchicalStoreProviders {
public static NamespacedHierarchicalStore<Namespace> dummyNamespacedHierarchicalStore() {
return new NamespacedHierarchicalStore<>(store, closeAutoCloseables());
}

public static NamespacedHierarchicalStore<Namespace> dummyNamespacedHierarchicalStoreWithNoParent() {
return new NamespacedHierarchicalStore<>(null, closeAutoCloseables());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2015-2025 the original author or authors.
*
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v2.0 which
* accompanies this distribution and is available at
*
* https://www.eclipse.org/legal/epl-v20.html
*/

package org.junit.jupiter.engine;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor;
import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext;
import org.junit.platform.commons.JUnitException;
import org.junit.platform.engine.ConfigurationParameters;
import org.junit.platform.engine.EngineExecutionListener;
import org.junit.platform.engine.ExecutionRequest;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.launcher.core.NamespacedHierarchicalStoreProviders;

/**
* @since 5.13
*/
public class JupiterEngineTests {

private final TestDescriptor rootTestDescriptor = mock(JupiterEngineDescriptor.class);

private final ConfigurationParameters configurationParameters = mock();

private final EngineExecutionListener engineExecutionListener = mock();

private final ExecutionRequest executionRequest = mock();

private final JupiterTestEngine engine = new JupiterTestEngine();

@BeforeEach
void setUp() {
when(executionRequest.getEngineExecutionListener()).thenReturn(engineExecutionListener);
when(executionRequest.getConfigurationParameters()).thenReturn(configurationParameters);
when(executionRequest.getRootTestDescriptor()).thenReturn(rootTestDescriptor);
}

@Test
void createExecutionContextWithValidRequest() {
when(executionRequest.getRequestLevelStore()).thenReturn(
NamespacedHierarchicalStoreProviders.dummyNamespacedHierarchicalStore());

JupiterEngineExecutionContext context = engine.createExecutionContext(executionRequest);
assertThat(context).isNotNull();
}

@Test
void createExecutionContextWithNoParentsRequestLevelStore() {
when(executionRequest.getRequestLevelStore()).thenReturn(
NamespacedHierarchicalStoreProviders.dummyNamespacedHierarchicalStoreWithNoParent());

assertThatThrownBy(() -> engine.createExecutionContext(executionRequest)).isInstanceOf(
JUnitException.class).hasMessageContaining("Request-level store must have a parent");
}

}

0 comments on commit 9fd3ba2

Please sign in to comment.