From 58014ee3d4f6b27a6bbcb37c0ae6a305cf1c3c5b Mon Sep 17 00:00:00 2001 From: Stefan Birkner Date: Wed, 5 Jul 2017 22:39:54 +0200 Subject: [PATCH] Extract isNotEngineId and isForVintageEngine Improve readability of the resolve method. --- .../discovery/UniqueIdSelectorResolver.java | 44 +++++++++++++------ 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/junit-vintage-engine/src/main/java/org/junit/vintage/engine/discovery/UniqueIdSelectorResolver.java b/junit-vintage-engine/src/main/java/org/junit/vintage/engine/discovery/UniqueIdSelectorResolver.java index 84b8b610dbbf..5756035d2b7e 100644 --- a/junit-vintage-engine/src/main/java/org/junit/vintage/engine/discovery/UniqueIdSelectorResolver.java +++ b/junit-vintage-engine/src/main/java/org/junit/vintage/engine/discovery/UniqueIdSelectorResolver.java @@ -11,7 +11,6 @@ package org.junit.vintage.engine.discovery; import static java.lang.String.format; -import static java.util.function.Predicate.isEqual; import static org.junit.vintage.engine.descriptor.VintageTestDescriptor.ENGINE_ID; import static org.junit.vintage.engine.descriptor.VintageTestDescriptor.SEGMENT_TYPE_RUNNER; @@ -38,25 +37,42 @@ class UniqueIdSelectorResolver extends DiscoverySelectorResolver format("Unresolvable Unique ID (%s): Cannot resolve the engine's unique ID", uniqueId)); } - else { - uniqueId.getEngineId().filter(isEqual(ENGINE_ID)).ifPresent( - engineId -> determineTestClassName(uniqueId).ifPresent( - testClassName -> resolveIntoFilteredTestClass(testClassName, uniqueId, collector))); - } + return !isEngineId; } - private void resolveIntoFilteredTestClass(String testClassName, UniqueId uniqueId, TestClassCollector collector) { - Optional> testClass = ReflectionUtils.loadClass(testClassName); - if (testClass.isPresent()) { - collector.addFiltered(testClass.get(), new UniqueIdFilter(uniqueId)); - } - else { - logger.warning(() -> format("Unresolvable Unique ID (%s): Unknown class %s", uniqueId, testClassName)); + private boolean isForVintageEngine(UniqueId uniqueId) { + // @formatter:off + return uniqueId.getEngineId() + .map(engineId -> engineId.equals(ENGINE_ID)) + .orElse(false); + // @formatter:on + } + + private void resolveIntoFilteredTestClass(UniqueId uniqueId, TestClassCollector collector) { + // @formatter:off + determineTestClassName(uniqueId) + .flatMap(testClassName -> loadTestClass(testClassName, uniqueId)) + .ifPresent(testClass -> collector.addFiltered(testClass, new UniqueIdFilter(uniqueId))); + // @formatter:on + } + + private Optional> loadTestClass(String className, UniqueId uniqueId) { + Optional> testClass = ReflectionUtils.loadClass(className); + if (!testClass.isPresent()) { + logger.warning(() -> format("Unresolvable Unique ID (%s): Unknown class %s", uniqueId, className)); } + return testClass; } private Optional determineTestClassName(UniqueId uniqueId) {