diff --git a/database/build.gradle b/database/build.gradle index d67b86c464..0bd96c99ff 100644 --- a/database/build.gradle +++ b/database/build.gradle @@ -20,9 +20,6 @@ android { } dependencies { - // shared needed for OpenForTesting - implementation project(':shared') - api "androidx.core:core-ktx:$core_version" api "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" @@ -48,5 +45,5 @@ dependencies { allOpen { // allows mocking for classes w/o directly opening them for release builds - annotation 'info.nightscout.androidaps.annotations.OpenForTesting' + annotation 'info.nightscout.androidaps.annotations.DbOpenForTesting' } \ No newline at end of file diff --git a/database/src/debug/java/info/nightscout/androidaps/annotations/DbOpenForTesting.kt b/database/src/debug/java/info/nightscout/androidaps/annotations/DbOpenForTesting.kt new file mode 100644 index 0000000000..deca64872c --- /dev/null +++ b/database/src/debug/java/info/nightscout/androidaps/annotations/DbOpenForTesting.kt @@ -0,0 +1,15 @@ +package info.nightscout.androidaps.annotations + +/** + * This is the actual annotation that makes the class open. Don't use it directly, only through [DbOpenForTesting] + * which has a NOOP replacement in production. + */ +@Target(AnnotationTarget.ANNOTATION_CLASS) +annotation class DbOpenClass + +/** + * Annotate a class with [DbOpenForTesting] if it should be extendable for testing. + */ +@DbOpenClass +@Target(AnnotationTarget.CLASS) +annotation class DbOpenForTesting \ No newline at end of file diff --git a/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt b/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt index dd2d33806d..1019581b80 100644 --- a/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt +++ b/database/src/main/java/info/nightscout/androidaps/database/AppRepository.kt @@ -1,6 +1,6 @@ package info.nightscout.androidaps.database -import info.nightscout.androidaps.annotations.OpenForTesting +import info.nightscout.androidaps.annotations.DbOpenForTesting import info.nightscout.androidaps.database.data.NewEntries import info.nightscout.androidaps.database.embedments.InterfaceIDs import info.nightscout.androidaps.database.entities.* @@ -19,7 +19,7 @@ import javax.inject.Inject import javax.inject.Singleton import kotlin.math.roundToInt -@OpenForTesting +@DbOpenForTesting @Singleton class AppRepository @Inject internal constructor( internal val database: AppDatabase ) { diff --git a/database/src/release/java/info/nightscout/androidaps/annotations/DbOpenForTesting.kt b/database/src/release/java/info/nightscout/androidaps/annotations/DbOpenForTesting.kt new file mode 100644 index 0000000000..66704666fe --- /dev/null +++ b/database/src/release/java/info/nightscout/androidaps/annotations/DbOpenForTesting.kt @@ -0,0 +1,8 @@ +package info.nightscout.androidaps.annotations + +/** + * Annotate a class with [DbOpenForTesting] if it should be extendable for testing. + * In production the class remains final. + */ +@Target(AnnotationTarget.CLASS) +annotation class DbOpenForTesting \ No newline at end of file