Skip to content

Commit 6816927

Browse files
jaredsburrowsvanniktech
authored andcommitted
Rename generation to generationplugin, add tests for all task generation cases (#71)
1 parent a59770f commit 6816927

File tree

11 files changed

+282
-17
lines changed

11 files changed

+282
-17
lines changed

.editorconfig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# EditorConfig helps developers define and maintain consistent
2+
# coding styles between different editors and IDEs
3+
# editorconfig.org
4+
5+
# top-most EditorConfig file
6+
root = true
7+
8+
[*]
9+
# Change these settings to your own preference
10+
indent_style = space
11+
indent_size = 2
12+
13+
# We recommend you to keep these unchanged
14+
end_of_line = lf
15+
charset = utf-8
16+
trim_trailing_whitespace = true
17+
insert_final_newline = true

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies {
2727
compile 'com.android.tools.build:gradle:2.3.3'
2828

2929
testCompile 'junit:junit:4.12'
30+
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4', { exclude module: "groovy-all" } // Use localGroovy()
3031
}
3132

3233
sourceCompatibility = JavaVersion.VERSION_1_7
@@ -75,4 +76,4 @@ artifacts {
7576
archives sourcesJar
7677
}
7778

78-
apply from: file('gradle/gradle-mvn-push.gradle')
79+
apply from: file('gradle/gradle-mvn-push.gradle')

src/main/groovy/com/vanniktech/android/junit/jacoco/Generation.groovy renamed to src/main/groovy/com/vanniktech/android/junit/jacoco/GenerationPlugin.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import org.gradle.api.Plugin
55
import org.gradle.api.Project
66
import org.gradle.testing.jacoco.tasks.JacocoReport
77

8-
class Generation implements Plugin<Project> {
8+
class GenerationPlugin implements Plugin<Project> {
99
@Override
1010
void apply(final Project rootProject) {
1111
rootProject.extensions.create('junitJacoco', JunitJacocoExtension)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
implementation-class=com.vanniktech.android.junit.jacoco.Generation
1+
implementation-class=com.vanniktech.android.junit.jacoco.GenerationPlugin
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
package com.vanniktech.android.junit.jacoco
2+
3+
import com.android.build.gradle.internal.SdkHandler
4+
import org.gradle.testfixtures.ProjectBuilder
5+
import spock.lang.Specification
6+
import spock.lang.Unroll
7+
8+
final class GenerationPluginSpec extends Specification {
9+
final static ANDROID_PLUGINS = ["com.android.application", "com.android.library", "com.android.test"]
10+
final static COMPILE_SDK_VERSION = 25
11+
final static BUILD_TOOLS_VERSION = "25.0.2"
12+
final static APPLICATION_ID = "com.example"
13+
// Test fixture that emulates a local android sdk
14+
final static TEST_ANDROID_SDK = getClass().getResource("/android-sdk/").toURI()
15+
def project
16+
17+
def "setup"() {
18+
project = ProjectBuilder.builder().build()
19+
20+
// Set mock test sdk, we only need to test the plugins tasks
21+
SdkHandler.sTestSdkFolder = project.file TEST_ANDROID_SDK
22+
}
23+
24+
@Unroll "#projectPlugin project"() {
25+
given:
26+
project.apply plugin: projectPlugin
27+
28+
when:
29+
project.apply plugin: "com.vanniktech.android.junit.jacoco"
30+
31+
then:
32+
noExceptionThrown()
33+
34+
where:
35+
projectPlugin << ANDROID_PLUGINS
36+
}
37+
38+
def "android - all tasks created"() {
39+
given:
40+
project.apply plugin: "com.android.application"
41+
project.apply plugin: "com.vanniktech.android.junit.jacoco"
42+
project.android {
43+
compileSdkVersion COMPILE_SDK_VERSION
44+
buildToolsVersion BUILD_TOOLS_VERSION
45+
46+
defaultConfig {
47+
applicationId APPLICATION_ID
48+
}
49+
}
50+
51+
when:
52+
project.evaluate()
53+
54+
then:
55+
project.tasks.getByName("jacocoTestReportDebug")
56+
}
57+
58+
def "android [buildTypes] - all tasks created"() {
59+
given:
60+
project.apply plugin: "com.android.application"
61+
project.apply plugin: "com.vanniktech.android.junit.jacoco"
62+
project.android {
63+
compileSdkVersion COMPILE_SDK_VERSION
64+
buildToolsVersion BUILD_TOOLS_VERSION
65+
66+
defaultConfig {
67+
applicationId APPLICATION_ID
68+
}
69+
70+
buildTypes {
71+
debug {}
72+
release {}
73+
}
74+
}
75+
76+
when:
77+
project.evaluate()
78+
79+
then:
80+
project.tasks.getByName("jacocoTestReportDebug")
81+
project.tasks.getByName("jacocoTestReportRelease")
82+
}
83+
84+
def "android [buildTypes + productFlavors] - all tasks created"() {
85+
given:
86+
project.apply plugin: "com.android.application"
87+
project.apply plugin: "com.vanniktech.android.junit.jacoco"
88+
project.android {
89+
compileSdkVersion COMPILE_SDK_VERSION
90+
buildToolsVersion BUILD_TOOLS_VERSION
91+
92+
defaultConfig {
93+
applicationId APPLICATION_ID
94+
}
95+
96+
buildTypes {
97+
debug {}
98+
release {}
99+
}
100+
101+
productFlavors {
102+
flavor1 {}
103+
flavor2 {}
104+
}
105+
}
106+
107+
when:
108+
project.evaluate()
109+
110+
then:
111+
project.tasks.getByName("jacocoTestReportFlavor1Debug")
112+
project.tasks.getByName("jacocoTestReportFlavor1Release")
113+
project.tasks.getByName("jacocoTestReportFlavor2Debug")
114+
project.tasks.getByName("jacocoTestReportFlavor2Release")
115+
}
116+
117+
def "android [buildTypes + productFlavors + flavorDimensions] - all tasks created"() {
118+
given:
119+
project.apply plugin: "com.android.application"
120+
project.apply plugin: "com.vanniktech.android.junit.jacoco"
121+
project.android {
122+
compileSdkVersion COMPILE_SDK_VERSION
123+
buildToolsVersion BUILD_TOOLS_VERSION
124+
125+
defaultConfig {
126+
applicationId APPLICATION_ID
127+
}
128+
129+
buildTypes {
130+
debug {}
131+
release {}
132+
}
133+
134+
flavorDimensions "a", "b"
135+
136+
productFlavors {
137+
flavor1 { dimension "a" }
138+
flavor2 { dimension "a" }
139+
flavor3 { dimension "b" }
140+
flavor4 { dimension "b" }
141+
}
142+
}
143+
144+
when:
145+
project.evaluate()
146+
147+
then:
148+
project.tasks.getByName("jacocoTestReportFlavor1Flavor3Debug")
149+
project.tasks.getByName("jacocoTestReportFlavor1Flavor3Release")
150+
project.tasks.getByName("jacocoTestReportFlavor2Flavor4Debug")
151+
project.tasks.getByName("jacocoTestReportFlavor2Flavor4Release")
152+
}
153+
}

src/test/groovy/com/vanniktech/android/junit/jacoco/GenerationTest.groovy

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class GenerationTest {
1313
public void addJacocoAndroidAppWithFlavors() {
1414
def androidAppProject = ProjectHelper.prepare(ANDROID_APPLICATION).withRedBlueFlavors().get()
1515

16-
Generation.addJacoco(androidAppProject, new JunitJacocoExtension())
16+
GenerationPlugin.addJacoco(androidAppProject, new JunitJacocoExtension())
1717

1818
assertJacocoAndroidWithFlavors(androidAppProject)
1919
}
@@ -22,7 +22,7 @@ public class GenerationTest {
2222
public void addJacocoAndroidLibraryWithFlavors() {
2323
def androidLibraryProject = ProjectHelper.prepare(ANDROID_LIBRARY).withRedBlueFlavors().get()
2424

25-
Generation.addJacoco(androidLibraryProject, new JunitJacocoExtension())
25+
GenerationPlugin.addJacoco(androidLibraryProject, new JunitJacocoExtension())
2626

2727
assertJacocoAndroidWithFlavors(androidLibraryProject)
2828
}
@@ -31,7 +31,7 @@ public class GenerationTest {
3131
public void addJacocoAndroidApp() {
3232
def androidAppProject = ProjectHelper.prepare(ANDROID_APPLICATION).get()
3333

34-
Generation.addJacoco(androidAppProject, new JunitJacocoExtension())
34+
GenerationPlugin.addJacoco(androidAppProject, new JunitJacocoExtension())
3535

3636
assertJacocoAndroidWithoutFlavors(androidAppProject)
3737
}
@@ -40,7 +40,7 @@ public class GenerationTest {
4040
public void addJacocoAndroidLibrary() {
4141
def androidLibraryProject = ProjectHelper.prepare(ANDROID_LIBRARY).get()
4242

43-
Generation.addJacoco(androidLibraryProject, new JunitJacocoExtension())
43+
GenerationPlugin.addJacoco(androidLibraryProject, new JunitJacocoExtension())
4444

4545
assertJacocoAndroidWithoutFlavors(androidLibraryProject)
4646
}
@@ -49,7 +49,7 @@ public class GenerationTest {
4949
public void addJacocoJava() {
5050
def javaProject = ProjectHelper.prepare(JAVA).get()
5151

52-
Generation.addJacoco(javaProject, new JunitJacocoExtension())
52+
GenerationPlugin.addJacoco(javaProject, new JunitJacocoExtension())
5353

5454
assertJacocoJava(javaProject)
5555
}
@@ -62,9 +62,9 @@ public class GenerationTest {
6262
def androidLibraryProject = ProjectHelper.prepare(ANDROID_LIBRARY).get()
6363
def javaProject = ProjectHelper.prepare(JAVA).get()
6464

65-
Generation.addJacoco(androidAppProject, extension)
66-
Generation.addJacoco(androidLibraryProject, extension)
67-
Generation.addJacoco(javaProject, extension)
65+
GenerationPlugin.addJacoco(androidAppProject, extension)
66+
GenerationPlugin.addJacoco(androidLibraryProject, extension)
67+
GenerationPlugin.addJacoco(javaProject, extension)
6868

6969
assert androidAppProject.jacoco.toolVersion == extension.jacocoVersion
7070
assert androidLibraryProject.jacoco.toolVersion == extension.jacocoVersion
@@ -82,7 +82,7 @@ public class GenerationTest {
8282
for (final def project : projects) {
8383
extension.ignoreProjects = [project.name]
8484

85-
assert !Generation.addJacoco(project, extension)
85+
assert !GenerationPlugin.addJacoco(project, extension)
8686
assert !project.plugins.hasPlugin(JacocoPlugin)
8787
}
8888
}
@@ -91,7 +91,7 @@ public class GenerationTest {
9191
public void androidAppBuildExecutesJacocoTask() {
9292
def androidAppProject = ProjectHelper.prepare(ANDROID_APPLICATION).get()
9393

94-
Generation.addJacoco(androidAppProject, new JunitJacocoExtension())
94+
GenerationPlugin.addJacoco(androidAppProject, new JunitJacocoExtension())
9595

9696
assert taskDependsOn(androidAppProject.check, 'jacocoTestReportDebug')
9797
assert taskDependsOn(androidAppProject.check, 'jacocoTestReportRelease')
@@ -101,7 +101,7 @@ public class GenerationTest {
101101
public void androidLibraryBuildExecutesJacocoTask() {
102102
def androidLibraryProject = ProjectHelper.prepare(ANDROID_LIBRARY).get()
103103

104-
Generation.addJacoco(androidLibraryProject, new JunitJacocoExtension())
104+
GenerationPlugin.addJacoco(androidLibraryProject, new JunitJacocoExtension())
105105

106106
assert taskDependsOn(androidLibraryProject.check, 'jacocoTestReportDebug')
107107
assert taskDependsOn(androidLibraryProject.check, 'jacocoTestReportRelease')
@@ -111,7 +111,7 @@ public class GenerationTest {
111111
public void javaBuildExecutesJacocoTask() {
112112
def javaProject = ProjectHelper.prepare(JAVA).get()
113113

114-
Generation.addJacoco(javaProject, new JunitJacocoExtension())
114+
GenerationPlugin.addJacoco(javaProject, new JunitJacocoExtension())
115115

116116
assert taskDependsOn(javaProject.check, 'jacocoTestReport')
117117
}
@@ -270,7 +270,7 @@ public class GenerationTest {
270270

271271
@Test
272272
public void getExcludesDefault() {
273-
final def excludes = Generation.getExcludes(new JunitJacocoExtension())
273+
final def excludes = GenerationPlugin.getExcludes(new JunitJacocoExtension())
274274

275275
assert excludes.size == 18
276276
assert excludes.contains('**/R.class')
@@ -299,7 +299,7 @@ public class GenerationTest {
299299
extension.excludes = new ArrayList<>()
300300
extension.excludes.add("**/*.java")
301301

302-
final def excludes = Generation.getExcludes(extension)
302+
final def excludes = GenerationPlugin.getExcludes(extension)
303303

304304
assert excludes == extension.excludes
305305
}

src/test/resources/android-sdk/build-tools/25.0.2/source.properties

Lines changed: 7 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
8933bad161af4178b1185d1a37fbf41ea5269c55

src/test/resources/android-sdk/platform-tools/source.properties

Lines changed: 7 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
# begin build properties
3+
# autogenerated by buildinfo.sh
4+
ro.build.id=NYC
5+
ro.build.display.id=sdk_phone_armv7-userdebug 7.1.1 NYC 3544217 test-keys
6+
ro.build.version.incremental=3544217
7+
ro.build.version.sdk=25
8+
ro.build.version.preview_sdk=0
9+
ro.build.version.codename=REL
10+
ro.build.version.all_codenames=REL
11+
ro.build.version.release=7.1.1
12+
ro.build.version.security_patch=2017-01-05
13+
ro.build.version.base_os=
14+
ro.build.date=Mon Dec 5 06:31:50 UTC 2016
15+
ro.build.date.utc=1480919510
16+
ro.build.type=userdebug
17+
ro.build.tags=test-keys
18+
ro.build.flavor=sdk_phone_armv7-userdebug
19+
ro.product.model=sdk_phone_armv7
20+
ro.product.name=sdk_phone_armv7
21+
ro.product.board=
22+
# ro.product.cpu.abi and ro.product.cpu.abi2 are obsolete,
23+
# use ro.product.cpu.abilist instead.
24+
ro.product.cpu.abi=armeabi-v7a
25+
ro.product.cpu.abi2=armeabi
26+
ro.product.cpu.abilist=armeabi-v7a,armeabi
27+
ro.product.cpu.abilist32=armeabi-v7a,armeabi
28+
ro.product.cpu.abilist64=
29+
ro.product.locale=en-US
30+
ro.wifi.channels=
31+
ro.board.platform=
32+
# ro.build.product is obsolete; use ro.product.device
33+
# Do not try to parse description, fingerprint, or thumbprint
34+
ro.build.description=sdk_phone_armv7-userdebug 7.1.1 NYC 3544217 test-keys
35+
ro.build.fingerprint=Android/sdk_phone_armv7/generic:7.1.1/NYC/3544217:userdebug/test-keys
36+
ro.build.characteristics=emulator
37+
# end build properties
38+
#
39+
# from build/target/board/generic/system.prop
40+
#
41+
#
42+
# system.prop for generic sdk
43+
#
44+
45+
rild.libpath=/system/lib/libreference-ril.so
46+
rild.libargs=-d /dev/ttyS0
47+
48+
#
49+
# ADDITIONAL_BUILD_PROPERTIES
50+
#
51+
ro.config.notification_sound=OnTheHunt.ogg
52+
ro.config.alarm_alert=Alarm_Classic.ogg
53+
persist.sys.dalvik.vm.lib.2=libart.so
54+
dalvik.vm.isa.arm.variant=generic
55+
dalvik.vm.isa.arm.features=default
56+
dalvik.vm.lockprof.threshold=500
57+
xmpp.auto-presence=true
58+
ro.config.nocheckin=yes
59+
net.bt.name=Android
60+
dalvik.vm.stack-trace-file=/data/anr/traces.txt
61+
ro.build.user=generic
62+
ro.build.host=generic
63+
ro.product.brand=generic
64+
ro.product.manufacturer=generic
65+
ro.product.device=generic
66+
ro.build.product=generic

0 commit comments

Comments
 (0)