Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static aQute.tester.bundle.engine.BundleEngine.CHECK_UNRESOLVED;
import static org.assertj.core.api.Assertions.allOf;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.platform.commons.util.FunctionUtils.where;
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
Expand All @@ -22,9 +23,12 @@

import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;

import org.assertj.core.api.AutoCloseableSoftAssertions;
import org.assertj.core.api.Condition;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -40,6 +44,7 @@
import org.junit.platform.engine.TestEngine;
import org.junit.platform.engine.TestExecutionResult;
import org.junit.platform.engine.UniqueId;
import org.junit.platform.engine.discovery.ClassSelector;
import org.junit.platform.engine.support.descriptor.EngineDescriptor;
import org.junit.platform.testkit.engine.EngineTestKit;
import org.junit.platform.testkit.engine.EngineTestKit.Builder;
Expand Down Expand Up @@ -119,6 +124,14 @@ public void setUp(TestInfo info) {
}
}

protected void startLaunchpadNoEngines() {
builder = new LaunchpadBuilder();
builder.bndrun("bundleenginetest-noengines.bndrun")
.excludeExport("aQute.tester.bundle.engine")
.excludeExport("aQute.tester.bundle.engine.discovery");
startLaunchpad();
}

protected void startLaunchpad() {
if (DEBUG) {
builder.debug();
Expand Down Expand Up @@ -174,11 +187,7 @@ public void outsideOfFramework_hasInitializationError() throws Exception {
@Test
@Tag(CUSTOM_LAUNCH)
public void withNoEngines_reportsMissingEngines_andSkipsMainTests() throws Exception {
builder = new LaunchpadBuilder();
builder = builder.bndrun("bundleenginetest-noengines.bndrun")
.excludeExport("aQute.tester.bundle.engine")
.excludeExport("aQute.tester.bundle.engine.discovery");
startLaunchpad();
startLaunchpadNoEngines();

Bundle testBundle = testBundler.startTestBundle(JUnit4Test.class);

Expand Down Expand Up @@ -270,11 +279,7 @@ public void execute(ExecutionRequest request) {
@Test
@Tag(CUSTOM_LAUNCH)
public void withEngineWithServiceSpecCommentsAndWhitespace_loadsEngine() throws Exception {
builder = new LaunchpadBuilder();
builder.bndrun("bundleenginetest-noengines.bndrun")
.excludeExport("aQute.tester.bundle.engine")
.excludeExport("aQute.tester.bundle.engine.discovery");
startLaunchpad();
startLaunchpadNoEngines();

Bundle engineBundle = testBundler.bundleWithEE()
.includeResource("META-INF/services/" + TestEngine.class.getName())
Expand Down Expand Up @@ -1126,10 +1131,9 @@ public void testClass_withBothJUnit3And4_raisesAnError() {
.debug(debugStr)
.assertThatEvents()
.haveExactly(1,
event(uniqueIdSubstring(test.getSymbolicName()), testClass(JUnit3And4Test.class),
finishedWithFailure(instanceOf(JUnitException.class),
message(
x -> x.matches("^(?si).*TestCase.*JUnit 4 annotations.*annotations will be ignored.*$")))));
event(uniqueIdSubstring(test.getSymbolicName()), testClass(JUnit3And4Test.class), finishedWithFailure(
instanceOf(JUnitException.class),
message(x -> x.matches("^(?si).*TestCase.*JUnit 4 annotations.*annotations will be ignored.*$")))));

}

Expand Down Expand Up @@ -1178,4 +1182,71 @@ public void testClass_withBothJUnit3AndOtherJUnit_doesntRaiseAnError() {
.assertThatEvents()
.haveExactly(0, finishedWithFailure(instanceOf(JUnitException.class)));
}

public static class SubEngine implements TestEngine {

static EngineDiscoveryRequest request;

@Override
public String getId() {
return "sub-engine";
}

@Override
public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) {
request = discoveryRequest;
return null;
}

@Override
public void execute(ExecutionRequest request) {}
}

@Test
@Tag(CUSTOM_LAUNCH)
public void subRequest_resolvesAndRemovesBundleSelectors() throws Exception {
startLaunchpadNoEngines();

Bundle engineBundle = testBundler.bundleWithEE()
.includeResource("META-INF/services/" + TestEngine.class.getName())
.literal(SubEngine.class.getName())
.addResource(SubEngine.class)
.start();
Bundle testBundle = startTestBundle(JUnit4Test.class);

EngineDiscoveryRequest request;

synchronized (SubEngine.class) {
SubEngine.request = null;

engineInFramework()
.selectors(selectBundle(testBundle))
.execute()
.all()
.debug(debugStr);
request = SubEngine.request;
}
assertThat(request).isNotNull();

Class<?> junit4TestInBundle = testBundle.loadClass(JUnit4Test.class.getName());

List<Class<?>> selectedClasses = new ArrayList<>();

try (AutoCloseableSoftAssertions softly = new AutoCloseableSoftAssertions()) {
softly.assertThat(request.getSelectorsByType(BundleSelector.class)).as("should remove BundleSelectors")
.isEmpty();
List<DiscoverySelector> selectors = request.getSelectorsByType(DiscoverySelector.class);
softly.assertThat(selectors)
.as("size")
.hasSize(1);
List<Class<?>> actualClasses = selectors.stream()
.filter(ClassSelector.class::isInstance)
.map(ClassSelector.class::cast)
.map(classSelector -> classSelector.getJavaClass())
.collect(Collectors.toList());
softly.assertThat(actualClasses)
.as("classes")
.containsExactlyInAnyOrder(junit4TestInBundle);
}
}
}