refactor(test): replace inputs with test profiles
This commit is contained in:
@@ -490,7 +490,7 @@ public abstract class IntegrationTest extends TestUtils {
|
||||
this.useEclipseCompiler = true;
|
||||
}
|
||||
|
||||
protected void useTargetJavaVersion(int version) {
|
||||
public void useTargetJavaVersion(int version) {
|
||||
Assumptions.assumeTrue(JavaUtils.checkJavaVersion(version), "skip test for higher java version");
|
||||
this.targetJavaVersion = version;
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package jadx.tests.api.extensions.inputs;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
public enum InputPlugin implements Consumer<IntegrationTest> {
|
||||
DEX {
|
||||
@Override
|
||||
public void accept(IntegrationTest test) {
|
||||
test.useDexInput();
|
||||
}
|
||||
},
|
||||
JAVA {
|
||||
@Override
|
||||
public void accept(IntegrationTest test) {
|
||||
test.useJavaInput();
|
||||
}
|
||||
};
|
||||
}
|
||||
+13
-14
@@ -1,9 +1,8 @@
|
||||
package jadx.tests.api.extensions.inputs;
|
||||
package jadx.tests.api.extensions.profiles;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -19,38 +18,38 @@ import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import static org.junit.platform.commons.util.AnnotationUtils.isAnnotated;
|
||||
|
||||
public class JadxInputPluginsExtension implements TestTemplateInvocationContextProvider {
|
||||
public class JadxTestProfilesExtension implements TestTemplateInvocationContextProvider {
|
||||
|
||||
@Override
|
||||
public boolean supportsTestTemplate(ExtensionContext context) {
|
||||
return isAnnotated(context.getTestMethod(), TestWithInputPlugins.class);
|
||||
return isAnnotated(context.getTestMethod(), TestWithProfiles.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<TestTemplateInvocationContext> provideTestTemplateInvocationContexts(ExtensionContext context) {
|
||||
Preconditions.condition(IntegrationTest.class.isAssignableFrom(context.getRequiredTestClass()),
|
||||
"@TestWithInputPlugins should be used only in IntegrationTest subclasses");
|
||||
"@TestWithProfiles should be used only in IntegrationTest subclasses");
|
||||
|
||||
Method testMethod = context.getRequiredTestMethod();
|
||||
boolean testAnnAdded = AnnotationUtils.findAnnotation(testMethod, Test.class).isPresent();
|
||||
Preconditions.condition(!testAnnAdded, "@Test annotation should be removed");
|
||||
|
||||
TestWithInputPlugins inputPluginAnn = AnnotationUtils.findAnnotation(testMethod, TestWithInputPlugins.class).get();
|
||||
return Stream.of(inputPluginAnn.value())
|
||||
TestWithProfiles profilesAnn = AnnotationUtils.findAnnotation(testMethod, TestWithProfiles.class).get();
|
||||
return Stream.of(profilesAnn.value())
|
||||
.sorted()
|
||||
.map(RunWithInputPlugin::new);
|
||||
.map(RunWithProfile::new);
|
||||
}
|
||||
|
||||
private static class RunWithInputPlugin implements TestTemplateInvocationContext {
|
||||
private final InputPlugin plugin;
|
||||
private static class RunWithProfile implements TestTemplateInvocationContext {
|
||||
private final TestProfile testProfile;
|
||||
|
||||
public RunWithInputPlugin(InputPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
public RunWithProfile(TestProfile testProfile) {
|
||||
this.testProfile = testProfile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDisplayName(int invocationIndex) {
|
||||
return plugin.name().toLowerCase(Locale.ROOT) + " input";
|
||||
return testProfile.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -59,7 +58,7 @@ public class JadxInputPluginsExtension implements TestTemplateInvocationContextP
|
||||
}
|
||||
|
||||
private BeforeTestExecutionCallback beforeTest() {
|
||||
return execContext -> plugin.accept((IntegrationTest) execContext.getRequiredTestInstance());
|
||||
return execContext -> testProfile.accept((IntegrationTest) execContext.getRequiredTestInstance());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package jadx.tests.api.extensions.profiles;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
public enum TestProfile implements Consumer<IntegrationTest> {
|
||||
DX_J8("dx-java-8", test -> {
|
||||
test.useTargetJavaVersion(8);
|
||||
test.useDexInput();
|
||||
}),
|
||||
D8_J11("d8-java-11", test -> {
|
||||
test.useTargetJavaVersion(11);
|
||||
test.useDexInput();
|
||||
}),
|
||||
JAVA8("java-8", test -> {
|
||||
test.useTargetJavaVersion(8);
|
||||
test.useJavaInput();
|
||||
}),
|
||||
JAVA11("java-11", test -> {
|
||||
test.useTargetJavaVersion(11);
|
||||
test.useJavaInput();
|
||||
});
|
||||
|
||||
private final String description;
|
||||
private final Consumer<IntegrationTest> setup;
|
||||
|
||||
TestProfile(String description, Consumer<IntegrationTest> setup) {
|
||||
this.description = description;
|
||||
this.setup = setup;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(IntegrationTest integrationTest) {
|
||||
this.setup.accept(integrationTest);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package jadx.tests.api.extensions.inputs;
|
||||
package jadx.tests.api.extensions.profiles;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -9,10 +9,10 @@ import org.junit.jupiter.api.TestTemplate;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@TestTemplate
|
||||
@ExtendWith(JadxInputPluginsExtension.class)
|
||||
@ExtendWith(JadxTestProfilesExtension.class)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.METHOD, ElementType.TYPE })
|
||||
public @interface TestWithInputPlugins {
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface TestWithProfiles {
|
||||
|
||||
InputPlugin[] value();
|
||||
TestProfile[] value();
|
||||
}
|
||||
@@ -2,8 +2,8 @@ package jadx.tests.integration.debuginfo;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
import jadx.tests.api.extensions.inputs.InputPlugin;
|
||||
import jadx.tests.api.extensions.inputs.TestWithInputPlugins;
|
||||
import jadx.tests.api.extensions.profiles.TestProfile;
|
||||
import jadx.tests.api.extensions.profiles.TestWithProfiles;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class TestLineNumbers3 extends IntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestWithInputPlugins({ InputPlugin.DEX, InputPlugin.JAVA })
|
||||
@TestWithProfiles({ TestProfile.DX_J8, TestProfile.JAVA8 })
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
assertThat(cls).code().containsOne("super(message == null ? \"\" : message.toString());");
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package jadx.tests.integration.invoke;
|
||||
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
import jadx.tests.api.extensions.inputs.InputPlugin;
|
||||
import jadx.tests.api.extensions.inputs.TestWithInputPlugins;
|
||||
import jadx.tests.api.extensions.profiles.TestProfile;
|
||||
import jadx.tests.api.extensions.profiles.TestWithProfiles;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
@@ -19,7 +19,7 @@ public class TestSuperInvoke2 extends IntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestWithInputPlugins({ InputPlugin.DEX, InputPlugin.JAVA })
|
||||
@TestWithProfiles({ TestProfile.DX_J8, TestProfile.JAVA8 })
|
||||
public void test() {
|
||||
noDebugInfo();
|
||||
assertThat(getClassNode(TestCls.class))
|
||||
|
||||
@@ -3,8 +3,8 @@ package jadx.tests.integration.others;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import jadx.tests.api.RaungTest;
|
||||
import jadx.tests.api.extensions.inputs.InputPlugin;
|
||||
import jadx.tests.api.extensions.inputs.TestWithInputPlugins;
|
||||
import jadx.tests.api.extensions.profiles.TestProfile;
|
||||
import jadx.tests.api.extensions.profiles.TestWithProfiles;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
@@ -52,7 +52,7 @@ public class TestStringConcatJava11 extends RaungTest {
|
||||
"return str + \"test\" + str + \"7\";"); // dynamic concat add const to string recipe
|
||||
}
|
||||
|
||||
@TestWithInputPlugins({ InputPlugin.DEX, InputPlugin.JAVA })
|
||||
@TestWithProfiles({ TestProfile.DX_J8, TestProfile.JAVA8 })
|
||||
public void testJava11() {
|
||||
useTargetJavaVersion(11);
|
||||
noDebugInfo();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package jadx.tests.integration.trycatch;
|
||||
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
import jadx.tests.api.extensions.inputs.InputPlugin;
|
||||
import jadx.tests.api.extensions.inputs.TestWithInputPlugins;
|
||||
import jadx.tests.api.extensions.profiles.TestProfile;
|
||||
import jadx.tests.api.extensions.profiles.TestWithProfiles;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class TestTryCatch9 extends IntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestWithInputPlugins({ InputPlugin.DEX, InputPlugin.JAVA })
|
||||
@TestWithProfiles({ TestProfile.DX_J8, TestProfile.JAVA8 })
|
||||
public void test() {
|
||||
assertThat(getClassNode(TestCls.class))
|
||||
.code()
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package jadx.tests.integration.trycatch;
|
||||
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
import jadx.tests.api.extensions.inputs.InputPlugin;
|
||||
import jadx.tests.api.extensions.inputs.TestWithInputPlugins;
|
||||
import jadx.tests.api.extensions.profiles.TestProfile;
|
||||
import jadx.tests.api.extensions.profiles.TestWithProfiles;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
@@ -43,7 +43,7 @@ public class TestTryCatchFinally13 extends IntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestWithInputPlugins({ InputPlugin.DEX, InputPlugin.JAVA })
|
||||
@TestWithProfiles({ TestProfile.DX_J8, TestProfile.JAVA8 })
|
||||
public void test() {
|
||||
assertThat(getClassNode(TestCls.class))
|
||||
.code()
|
||||
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
package jadx.tests.integration.variables;
|
||||
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
import jadx.tests.api.extensions.inputs.InputPlugin;
|
||||
import jadx.tests.api.extensions.inputs.TestWithInputPlugins;
|
||||
import jadx.tests.api.extensions.profiles.TestProfile;
|
||||
import jadx.tests.api.extensions.profiles.TestWithProfiles;
|
||||
|
||||
import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat;
|
||||
|
||||
@@ -21,7 +21,7 @@ public class TestVariablesInInlinedAssign extends IntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestWithInputPlugins({ InputPlugin.DEX, InputPlugin.JAVA })
|
||||
@TestWithProfiles({ TestProfile.DX_J8, TestProfile.JAVA8 })
|
||||
public void test() {
|
||||
assertThat(getClassNode(TestCls.class))
|
||||
.code()
|
||||
|
||||
Reference in New Issue
Block a user