Skip to content

Commit

Permalink
Merge pull request #19 from michaeladler/master
Browse files Browse the repository at this point in the history
Fix issue #18:  Unable to execute a single test in latest IntelliJ
  • Loading branch information
aaschmid committed Apr 25, 2014
2 parents b2b298a + 076288d commit e289206
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
bin/
build/
out/
target/
.classpath
.gradle
.idea
Expand Down
66 changes: 66 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.tngtech.java.junit</groupId>
<artifactId>dataprovider</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>dataprovider</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<profiles>
<profile>
<id>CategoryOne</id>
<properties>
<testcase.groups>com.tngtech.test.java.junit.dataprovider.category.CategoryOne</testcase.groups>
</properties>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<groups>${testcase.groups}</groups>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>2.0.1</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.9.5</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.junit.Test;
Expand All @@ -30,6 +31,12 @@ public class DataProviderRunner extends BlockJUnit4ClassRunner {
*/
List<FrameworkMethod> computedTestMethods;

/**
* A list of filter packages which must not be wrapped by DataProviderRunner
* (this is a workaround for some plugins, e.g. the maven-surefire-plugin).
*/
private static final List<String> BLACKLISTED_FILTER_PACKAGES = Arrays.asList("org.apache.maven.surefire");

/**
* Creates a DataProviderRunner to run supplied {@code clazz}.
*
Expand All @@ -43,7 +50,7 @@ public DataProviderRunner(Class<?> clazz) throws InitializationError {
@Override
public void filter(Filter filter) throws NoTestsRemainException {
Filter useFilter;
if (!(filter instanceof CategoryFilter) && filter.getClass().getName().startsWith("org.junit")) {
if (!(filter instanceof CategoryFilter) && !isFilterBlackListed(filter)) {
useFilter = new DataProviderFilter(filter);
} else {
useFilter = filter;
Expand Down Expand Up @@ -281,4 +288,14 @@ List<FrameworkMethod> explodeTestMethod(FrameworkMethod testMethod, FrameworkMet
TestClass getTestClassInt() {
return getTestClass();
}

private boolean isFilterBlackListed(Filter filter) {
String className = filter.getClass().getName();
for (String blacklistedPackage: BLACKLISTED_FILTER_PACKAGES) {
if (className.startsWith(blacklistedPackage)) {
return true;
}
}
return false;
}
}

0 comments on commit e289206

Please sign in to comment.