Skip to content

Commit

Permalink
Drop support of legacy JUnit: 4.4 - 4.8 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst committed Jun 20, 2022
1 parent 08839a3 commit 27a1fb8
Show file tree
Hide file tree
Showing 32 changed files with 237 additions and 905 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ ext{
objenesisVersion = "3.2"
javassistVersion = "3.27.0-GA"
junitVersion = "4.12"
junitRulesVersion = "4.8.2"
testngVersion = "6.9.10"
xstreamVersion = "1.4.10"
mockitoVersion = "4.3.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@
import org.junit.runner.notification.RunNotifier;
import org.powermock.modules.junit4.common.internal.PowerMockJUnitRunnerDelegate;
import org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner;
import org.powermock.modules.junit4.common.internal.impl.JUnitVersion;
import org.powermock.modules.junit4.internal.impl.DelegatingPowerMockRunner;
import org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl;
import org.powermock.modules.junit4.internal.impl.PowerMockJUnit47RunnerDelegateImpl;
import org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl;
import org.powermock.modules.junit4.internal.impl.PowerMockJUnit4RunnerDelegateImpl;
import org.powermock.reflect.Whitebox;

import java.lang.annotation.Annotation;
Expand All @@ -40,13 +37,7 @@ private static Class<? extends PowerMockJUnitRunnerDelegate> getRunnerDelegateIm
return DelegatingPowerMockRunner.class;
}

Class<? extends PowerMockJUnitRunnerDelegate> concreteClass = PowerMockJUnit44RunnerDelegateImpl.class;
if(JUnitVersion.isGreaterThanOrEqualTo("4.9")) {
concreteClass = PowerMockJUnit49RunnerDelegateImpl.class;
} else if( JUnitVersion.isGreaterThanOrEqualTo("4.7") ) {
concreteClass = PowerMockJUnit47RunnerDelegateImpl.class;
}
return concreteClass;
return PowerMockJUnit4RunnerDelegateImpl.class;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@
*/
package org.powermock.modules.junit4;

import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.AllTests;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.JUnit4;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
import org.powermock.modules.junit4.common.internal.impl.JUnitVersion;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand Down Expand Up @@ -62,11 +57,7 @@ private static Runner createDefaultRunner(Class<?> testClass)
} catch (NoSuchMethodException thereIsNoSuiteMethod) {
/* Continue below ... */
}
if (JUnitVersion.isGreaterThanOrEqualTo("4.5")) {
return SinceJUnit_4_5.createRunnerDelegate(testClass);
} else {
return new BlockJUnit4ClassRunner(testClass);
}
return new JUnit4(testClass);
}

@Override
Expand All @@ -79,22 +70,4 @@ public void run(RunNotifier notifier) {
wrappedDefaultRunner.run(notifier);
}
}

/**
* Stuff that needs to be handled in a separate class, because it
* deals with API that did not exist before JUnit-4.5. Having this inside
* {@link DefaultJUnitRunner} would cause runtime error when JUnit-4.4
* or earlier is used.
*/
public class SinceJUnit_4_5 {
static Runner createRunnerDelegate(Class<?> testClass) throws InitializationError {
return new JUnit4(testClass);
}
public static Class[] runnerAlternativeConstructorParams() {
return new Class[] {Class.class, RunnerBuilder.class};
}
public static Object newRunnerBuilder() {
return new AllDefaultPossibilitiesBuilder(false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@

import org.junit.Test;
import org.junit.experimental.theories.Theory;
import org.junit.internal.builders.AllDefaultPossibilitiesBuilder;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.manipulation.Filter;
import org.junit.runner.manipulation.Filterable;
import org.junit.runner.manipulation.NoTestsRemainException;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.RunnerBuilder;
import org.powermock.core.spi.PowerMockTestListener;
import org.powermock.core.testlisteners.GlobalNotificationBuildSupport;
import org.powermock.modules.junit4.PowerMockRunnerDelegate;
import org.powermock.modules.junit4.PowerMockRunnerDelegate.SinceJUnit_4_5;
import org.powermock.modules.junit4.common.internal.PowerMockJUnitRunnerDelegate;
import org.powermock.modules.junit4.common.internal.impl.JUnitVersion;
import org.powermock.reflect.Whitebox;
Expand Down Expand Up @@ -105,14 +106,12 @@ public Runner call() throws Exception {
new Class[] {Class.class},
new Object[] {testClass});
} catch (ConstructorNotFoundException rootProblem) {
if (testClass.isAnnotationPresent(PowerMockRunnerDelegate.class)
&& JUnitVersion.isGreaterThanOrEqualTo("4.5")) {
if (testClass.isAnnotationPresent(PowerMockRunnerDelegate.class)) {
try {
return Whitebox.invokeConstructor(testClass.getAnnotation(PowerMockRunnerDelegate.class).value(),
SinceJUnit_4_5.runnerAlternativeConstructorParams(),
new Class[] { Class.class, RunnerBuilder.class },
new Object[] {
testClass,
SinceJUnit_4_5.newRunnerBuilder()
testClass, new AllDefaultPossibilitiesBuilder(false)
});
} catch (ConstructorNotFoundException ignoredWorkAroundFailure) {
}
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 27a1fb8

Please sign in to comment.