Skip to content

Commit

Permalink
Add mockable Android JAR dependencies automatically. Fixes #91
Browse files Browse the repository at this point in the history
  • Loading branch information
koral-- committed Nov 6, 2023
1 parent 1eff476 commit 22252ac
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MockableAndroidJarFunctionalSpec extends AbstractPitestFunctionalSpec {
dependencies {
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.json:json:20180813'
}
""".stripIndent()
and:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Test;

import pitest.test.Library;
import org.json.JSONObject;

import static org.junit.Assert.*;

Expand All @@ -12,4 +13,10 @@ public void testSomeLibraryMethod() {
Library classUnderTest = new Library();
assertTrue("someLibraryMethod should return 'true'", classUnderTest.someLibraryMethod());
}

@Test
public void testJSON() throws Exception {
JSONObject jsonObject = new JSONObject("{\"id\": 123}");
assertEquals("123", jsonObject.optString("id"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ class PitestPlugin implements Plugin<Project> {
variants.all { BaseVariant variant ->
PitestTask variantTask = project.tasks.create("${PITEST_TASK_NAME}${variant.name.capitalize()}", PitestTask)

boolean includeMockableAndroidJar = !pitestExtension.excludeMockableAndroidJar.getOrElse(false)
if (includeMockableAndroidJar) {
addMockableAndroidJarDependencies()
}

Task mockableAndroidJarTask
if (ANDROID_GRADLE_PLUGIN_VERSION_NUMBER < new Semver("3.2.0")) {
mockableAndroidJarTask = project.tasks.findByName("mockableAndroidJar")
Expand All @@ -153,7 +158,7 @@ class PitestPlugin implements Plugin<Project> {
configureTaskDefault(variantTask, variant, mockableAndroidJarTask.outputJar)
}

if (!pitestExtension.excludeMockableAndroidJar.getOrElse(false)) {
if (includeMockableAndroidJar) {
variantTask.dependsOn mockableAndroidJarTask
}

Expand All @@ -169,6 +174,18 @@ class PitestPlugin implements Plugin<Project> {
}
}

private void addMockableAndroidJarDependencies() {
//according to https://search.maven.org/artifact/com.google.android/android/4.1.1.4/jar
project.buildscript.dependencies {
"$PITEST_TEST_COMPILE_CONFIGURATION_NAME" "org.json:json:20080701"
"$PITEST_TEST_COMPILE_CONFIGURATION_NAME" "xpp3:xpp3:1.1.4c"
"$PITEST_TEST_COMPILE_CONFIGURATION_NAME" "xerces:xmlParserAPIs:2.6.2"
"$PITEST_TEST_COMPILE_CONFIGURATION_NAME" "org.khronos:opengl-api:gl1.1-android-2.1_r1"
"$PITEST_TEST_COMPILE_CONFIGURATION_NAME" "org.apache.httpcomponents:httpclient:4.0.1"
"$PITEST_TEST_COMPILE_CONFIGURATION_NAME" "commons-logging:commons-logging:1.1.1"
}
}

@SuppressWarnings("BuilderMethodWithSideEffects")
private void createConfigurations() {
[PITEST_CONFIGURATION_NAME, PITEST_TEST_COMPILE_CONFIGURATION_NAME].each { configuration ->
Expand Down

0 comments on commit 22252ac

Please sign in to comment.