Skip to content

Commit d2f3a51

Browse files
authored
fix: include annotated methods in parameterized classes when filtering with test-targets (#2537)
* fix: include annotated methods in parameterized classes when filtering with test-targets * test: add extra tests and associated resources
1 parent 1e0f124 commit d2f3a51

39 files changed

+608
-10
lines changed
Binary file not shown.
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
}
5+
6+
android {
7+
namespace = "flank.shard.annotationbug"
8+
compileSdk = 34
9+
10+
defaultConfig {
11+
applicationId = "flank.shard.annotationbug"
12+
minSdk = 24
13+
targetSdk = 34
14+
versionCode = 1
15+
versionName = "1.0"
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
}
19+
20+
buildTypes {
21+
release {
22+
isMinifyEnabled = false
23+
proguardFiles(
24+
getDefaultProguardFile("proguard-android-optimize.txt"),
25+
"proguard-rules.pro"
26+
)
27+
}
28+
}
29+
compileOptions {
30+
sourceCompatibility = JavaVersion.VERSION_1_8
31+
targetCompatibility = JavaVersion.VERSION_1_8
32+
}
33+
kotlinOptions {
34+
jvmTarget = "1.8"
35+
}
36+
}
37+
38+
dependencies {
39+
40+
implementation("androidx.core:core-ktx:1.12.0")
41+
implementation("androidx.appcompat:appcompat:1.6.1")
42+
implementation("com.google.android.material:material:1.11.0")
43+
testImplementation("junit:junit:4.13.2")
44+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
45+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package flank.shard.annotationbug
2+
3+
@Target(
4+
AnnotationTarget.ANNOTATION_CLASS,
5+
AnnotationTarget.FUNCTION,
6+
AnnotationTarget.PROPERTY_GETTER,
7+
AnnotationTarget.PROPERTY_SETTER
8+
)
9+
@Retention(
10+
AnnotationRetention.RUNTIME
11+
)
12+
annotation class Annotation
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package flank.shard.annotationbug
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import org.junit.Assert
5+
import org.junit.Test
6+
import org.junit.runner.RunWith
7+
import org.junit.runners.Parameterized
8+
9+
@RunWith(Parameterized::class)
10+
class FooAnnotatedParameterizedTest {
11+
@Test
12+
@FooAnnotation
13+
fun useAppContext() {
14+
// Context of the app under test.
15+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
16+
Assert.assertEquals("flank.shard.annotationbug", appContext.packageName)
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package flank.shard.annotationbug
2+
3+
@Target(
4+
AnnotationTarget.ANNOTATION_CLASS,
5+
AnnotationTarget.FUNCTION,
6+
AnnotationTarget.PROPERTY_GETTER,
7+
AnnotationTarget.PROPERTY_SETTER
8+
)
9+
@Retention(
10+
AnnotationRetention.RUNTIME
11+
)
12+
13+
annotation class FooAnnotation()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package flank.shard.annotationbug
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class InstrumentedAnnotatedTest {
18+
@Test
19+
@Annotation
20+
fun useAppContext() {
21+
// Context of the app under test.
22+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
23+
assertEquals("flank.shard.annotationbug", appContext.packageName)
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package flank.shard.annotationbug
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class InstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("flank.shard.annotationbug", appContext.packageName)
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package flank.shard.annotationbug
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
5+
import org.junit.Test
6+
import org.junit.runner.RunWith
7+
8+
import org.junit.Assert.*
9+
import org.junit.runners.Parameterized
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(Parameterized::class)
17+
class ParameterizedAnnotatedTest {
18+
@Test
19+
@Annotation
20+
fun useAppContext() {
21+
// Context of the app under test.
22+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
23+
assertEquals("flank.shard.annotationbug", appContext.packageName)
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package flank.shard.annotationbug
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
5+
import org.junit.Test
6+
import org.junit.runner.RunWith
7+
8+
import org.junit.Assert.*
9+
import org.junit.runners.Parameterized
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(Parameterized::class)
17+
class ParameterizedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("flank.shard.annotationbug", appContext.packageName)
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.Flankshardannotationbug"
14+
tools:targetApi="31" />
15+
16+
</manifest>

0 commit comments

Comments
 (0)