Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#40: Do not discover plain classes without tests
------------------------------------------------------------------------ On behalf of the community, the JUnit Lambda Team thanks msg systems ag (http://www.msg-systems.com) for supporting the JUnit crowdfunding campaign! ------------------------------------------------------------------------
- Loading branch information
1 parent
0fd7630
commit 9a57fa3
Showing
7 changed files
with
128 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
junit4-engine/src/main/java/org/junit/gen5/engine/junit4/IsJUnit4TestMethod.java
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
.../java/org/junit/gen5/engine/junit4/discovery/DefensiveAllDefaultPossibilitiesBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,52 @@ | |||
/* | |||
* Copyright 2015-2016 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|||
package org.junit.gen5.engine.junit4.discovery; | |||
|
|||
import java.lang.reflect.Method; | |||
import java.util.List; | |||
import java.util.function.Predicate; | |||
|
|||
import org.junit.gen5.commons.util.ReflectionUtils; | |||
import org.junit.internal.builders.AllDefaultPossibilitiesBuilder; | |||
import org.junit.internal.builders.JUnit4Builder; | |||
import org.junit.runner.Runner; | |||
|
|||
class DefensiveAllDefaultPossibilitiesBuilder extends AllDefaultPossibilitiesBuilder { | |||
|
|||
private final DefensiveJUnit4Builder defensiveJUnit4Builder = new DefensiveJUnit4Builder(); | |||
|
|||
DefensiveAllDefaultPossibilitiesBuilder() { | |||
super(true); | |||
} | |||
|
|||
@Override | |||
protected JUnit4Builder junit4Builder() { | |||
return defensiveJUnit4Builder; | |||
} | |||
|
|||
private static class DefensiveJUnit4Builder extends JUnit4Builder { | |||
|
|||
private final Predicate<Method> hasTestAnnotation = new IsPotentialJUnit4TestMethod(); | |||
|
|||
@Override | |||
public Runner runnerForClass(Class<?> testClass) throws Throwable { | |||
if (containsTestMethods(testClass)) { | |||
return super.runnerForClass(testClass); | |||
} | |||
return null; | |||
} | |||
|
|||
private boolean containsTestMethods(Class<?> testClass) { | |||
List<Method> testMethods = ReflectionUtils.findMethods(testClass, hasTestAnnotation); | |||
return !testMethods.isEmpty(); | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...ine/src/main/java/org/junit/gen5/engine/junit4/discovery/IsPotentialJUnit4TestMethod.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
/* | |||
* Copyright 2015-2016 the original author or authors. | |||
* | |||
* All rights reserved. This program and the accompanying materials are | |||
* made available under the terms of the Eclipse Public License v1.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v10.html | |||
*/ | |||
|
|||
package org.junit.gen5.engine.junit4.discovery; | |||
|
|||
import java.lang.reflect.Method; | |||
import java.util.function.Predicate; | |||
|
|||
import org.junit.Test; | |||
|
|||
/** | |||
* @since 5.0 | |||
*/ | |||
class IsPotentialJUnit4TestMethod implements Predicate<Method> { | |||
|
|||
@Override | |||
public boolean test(Method method) { | |||
// Don't use AnnotationUtils.hasAnnotation since JUnit 4 does not support | |||
// meta-annotations | |||
return method.isAnnotationPresent(Test.class); | |||
} | |||
|
|||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters