Skip to content
Merged
Show file tree
Hide file tree
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
26 changes: 16 additions & 10 deletions java-reporter-junit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.testomat</groupId>
<artifactId>java-reporter-junit</artifactId>
<version>0.7.2</version>
<version>0.7.5</version>
<packaging>jar</packaging>

<name>Testomat.io Java Reporter JUnit</name>
Expand Down Expand Up @@ -37,7 +37,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<checkstyle-maven-plugin.version>3.6.0</checkstyle-maven-plugin.version>

<junit.version>5.10.0</junit.version>
<junit.version>5.9.2</junit.version>

<maven.compiler.plugin.version>3.11.0</maven.compiler.plugin.version>
<maven.source.plugin.version>3.3.0</maven.source.plugin.version>
Expand All @@ -49,13 +49,12 @@
<dependency>
<groupId>io.testomat</groupId>
<artifactId>java-reporter-core</artifactId>
<version>0.7.2</version>
<version>0.7.5</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
Expand All @@ -76,12 +75,6 @@
<version>5.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand All @@ -92,6 +85,19 @@
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-core</artifactId>
<version>3.27.0</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>1.9.2</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<optional>true</optional>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package io.testomat.junit.filter;

import io.testomat.core.annotation.TestId;
import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;
import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor;
import org.junit.platform.engine.FilterResult;
import org.junit.platform.engine.TestDescriptor;
import org.junit.platform.launcher.PostDiscoveryFilter;

public class TestIdFilter implements PostDiscoveryFilter {
private static final String SPLIT_REGEX = ",";
private static final String IDS_PROPERTY_NAME = "ids";

private final Set<String> allowedIds;

public TestIdFilter() {
String idsProperty = System.getProperty(IDS_PROPERTY_NAME);

if (idsProperty != null && !idsProperty.isEmpty()) {
allowedIds = new HashSet<>();
for (String id : idsProperty.split(SPLIT_REGEX)) {
allowedIds.add(id.trim());
}
} else {
allowedIds = null;
}
}

@Override
public FilterResult apply(TestDescriptor testDescriptor) {
if (allowedIds == null) {
return FilterResult.included("No ids filter specified");
}

if (testDescriptor instanceof TestMethodTestDescriptor) {
TestMethodTestDescriptor methodDescriptor = (TestMethodTestDescriptor) testDescriptor;
Method testMethod = methodDescriptor.getTestMethod();

TestId testIdAnnotation = testMethod.getAnnotation(TestId.class);

if (testIdAnnotation != null) {
return getFilterResult(testIdAnnotation);
} else {
return FilterResult.included(
"Test method without @TestId annotation is allowed when filtering by IDs");
}
}

return FilterResult.included("Not a test method");
}

private FilterResult getFilterResult(TestId testIdAnnotation) {
String testId = testIdAnnotation.value();
boolean isAllowed = allowedIds.contains(testId);

if (isAllowed) {
return FilterResult.included("Test ID " + testId + " is in allowed list");
} else {
return FilterResult.excluded("Test ID " + testId + " is not in allowed list");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.testomat.junit.filter.TestIdFilter