Skip to content

Commit

Permalink
Log warning when trying to resolve the engine's unique ID
Browse files Browse the repository at this point in the history
Issue: #40
  • Loading branch information
marcphilipp committed Jan 25, 2016
1 parent 97a4f6e commit 62fcc33
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
Expand Up @@ -42,4 +42,21 @@ void logsWarningOnUnloadableTestClass() {
logRecord.getMessage());
}

@Test
void logsWarningForEngineUniqueId() {
String uniqueId = "junit4";
RecordCollectingLogger logger = new RecordCollectingLogger();
UniqueIdSelector selector = UniqueIdSelector.forUniqueId(uniqueId);
TestClassCollector collector = new TestClassCollector();

new UniqueIdSelectorResolver(logger).resolve(selector, collector);

Set<TestClassRequest> requests = collector.toRequests(c -> true);
assertThat(requests).isEmpty();
assertThat(logger.getLogRecords()).hasSize(1);
LogRecord logRecord = getOnlyElement(logger.getLogRecords());
assertEquals(Level.WARNING, logRecord.getLevel());
assertEquals("Unresolvable Unique ID (junit4): Cannot resolve the engine's unique ID", logRecord.getMessage());
}

}
Expand Up @@ -12,17 +12,18 @@

import static java.lang.String.format;
import static org.junit.gen5.engine.junit4.descriptor.JUnit4TestDescriptor.DEFAULT_SEPARATOR;
import static org.junit.gen5.engine.junit4.descriptor.JUnit4TestDescriptor.ENGINE_ID;

import java.util.Optional;
import java.util.logging.Logger;

import org.junit.gen5.commons.util.ReflectionUtils;
import org.junit.gen5.engine.discovery.UniqueIdSelector;
import org.junit.gen5.engine.junit4.descriptor.JUnit4TestDescriptor;
import org.junit.gen5.engine.junit4.descriptor.RunnerTestDescriptor;

class UniqueIdSelectorResolver extends DiscoverySelectorResolver<UniqueIdSelector> {

private static final String ENGINE_PREFIX = ENGINE_ID + RunnerTestDescriptor.SEPARATOR;
private final Logger logger;

UniqueIdSelectorResolver(Logger logger) {
Expand All @@ -33,16 +34,23 @@ class UniqueIdSelectorResolver extends DiscoverySelectorResolver<UniqueIdSelecto
@Override
void resolve(UniqueIdSelector selector, TestClassCollector collector) {
String uniqueId = selector.getUniqueId();
String enginePrefix = JUnit4TestDescriptor.ENGINE_ID + RunnerTestDescriptor.SEPARATOR;
if (uniqueId.startsWith(enginePrefix)) {
String testClassName = determineTestClassName(uniqueId, enginePrefix);
Optional<Class<?>> 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));
}
if (ENGINE_ID.equals(uniqueId)) {
logger.warning(
() -> format("Unresolvable Unique ID (%s): Cannot resolve the engine's unique ID", uniqueId));
}
else if (uniqueId.startsWith(ENGINE_PREFIX)) {
String testClassName = determineTestClassName(uniqueId, ENGINE_PREFIX);
resolveIntoFilteredTestClass(testClassName, uniqueId, collector);
}
}

private void resolveIntoFilteredTestClass(String testClassName, String uniqueId, TestClassCollector collector) {
Optional<Class<?>> 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));
}
}

Expand Down

0 comments on commit 62fcc33

Please sign in to comment.