From ab8e7935b0ea12fff5dd45fdef6c2cc36748722d Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Wed, 6 Jan 2021 05:22:23 +0530 Subject: [PATCH] Add WorkManagerTestRule. --- app/build.gradle | 8 +++- .../fdroid/fdroid/WorkManagerTestRule.java | 35 ++++++++++++++++++ gradle/verification-keyring.gpg | Bin 217236 -> 220017 bytes gradle/verification-metadata.xml | 21 ++++++++++- 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 app/src/androidTest/java/org/fdroid/fdroid/WorkManagerTestRule.java diff --git a/app/build.gradle b/app/build.gradle index a179fe9f9..d72191717 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -135,6 +135,10 @@ android { } } +ext { + work_version = '2.4.0' +} + dependencies { implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.preference:preference:1.1.1' @@ -145,7 +149,7 @@ dependencies { implementation 'androidx.vectordrawable:vectordrawable:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.palette:palette:1.0.0' - implementation 'androidx.work:work-runtime:2.4.0' + implementation "androidx.work:work-runtime:$work_version" implementation 'com.google.android.material:material:1.1.0' @@ -177,6 +181,7 @@ dependencies { testImplementation 'org.hamcrest:hamcrest:2.2' testImplementation 'org.bouncycastle:bcprov-jdk15on:1.65' + androidTestImplementation 'androidx.arch.core:core-testing:2.1.0' androidTestImplementation 'androidx.test:core:1.3.0' androidTestImplementation 'androidx.test:runner:1.3.0' androidTestImplementation 'androidx.test:rules:1.3.0' @@ -184,6 +189,7 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' + androidTestImplementation "androidx.work:work-testing:$work_version" } checkstyle { diff --git a/app/src/androidTest/java/org/fdroid/fdroid/WorkManagerTestRule.java b/app/src/androidTest/java/org/fdroid/fdroid/WorkManagerTestRule.java new file mode 100644 index 000000000..a2091588b --- /dev/null +++ b/app/src/androidTest/java/org/fdroid/fdroid/WorkManagerTestRule.java @@ -0,0 +1,35 @@ +package org.fdroid.fdroid; + +import android.app.Instrumentation; +import android.content.Context; +import android.util.Log; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.work.Configuration; +import androidx.work.WorkManager; +import androidx.work.testing.SynchronousExecutor; +import androidx.work.testing.WorkManagerTestInitHelper; + +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; + +public class WorkManagerTestRule extends TestWatcher { + private Context targetContext; + private Context testContext; + private Configuration configuration; + private WorkManager workManager; + + @Override + protected void starting(Description description) { + final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation(); + targetContext = instrumentation.getTargetContext(); + testContext = instrumentation.getContext(); + configuration = new Configuration.Builder() + .setMinimumLoggingLevel(Log.DEBUG) + .setExecutor(new SynchronousExecutor()) + .build(); + + WorkManagerTestInitHelper.initializeTestWorkManager(targetContext, configuration); + workManager = WorkManager.getInstance(targetContext); + } +} diff --git a/gradle/verification-keyring.gpg b/gradle/verification-keyring.gpg index f506bf2774fc067aa5257b4b22a15e1d11ae333a..6349fbeee46b66c0d845e4fe5e1c1fc0b90a422d 100644 GIT binary patch delta 2792 zcmV5s+g-{wR!a{VUF{7ENrvqixOb|MP> z|KM3Tj>=Q8A!`pZeI9?KW3nkN#QD9mIh1F;k&gfo0RRECC_-s&baG*NAShyaAWBAZ zZ)YhWJYs2XbaG*NKw@cbbaG*NE@N+PK8XS|1P}oV038+~1pdE>D0u)0%0tG*4YRFG z?3aRrWd#CX;oN5c3JDOitxW8ff`etp6%YLzN5zvJdKj4yF!6sO+xcw$h$r`RI~n4y z3+S%U0{#fXb_92#|B8CKYAFXHejAe4$w_Xa_#SeTytWFyuKC2=gYiitTXM~?Xg;#Sdqan(& ziql2hUoXZ%-o<}zrLPtQbm=@2x&Mv8X3OJ8MkJ?eSQ?Io&8Ul+u|G$g(bcb_(S#F5 zU1D%~Pi_2bFZad?rcQy&JpI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ZG0vikf3JDN5oZ*tx0jpumk`MryA@A|L zxWqmfm9pHKBh|hL3s}(OV-;tCc1CCk?^R2=dq;kwpaxZ`$T^ zVe*z%evi1*i=z;n$RlJV=_(nj7V6s?(|{`LD11ibYJO{eSla)S3&W%U-Nw7p!GnKo z)1NT{uws%=2#$AxY>Goyk#FShNz`kFe-Lp;*wQGKp{b-ptijy?F3s~gWIQP5aV@R} zo_>9TL^}V#+t)SITT~Q5XtI{^ZF@?-eZ;VYp&%rzvNuX?lZH0#w35KSeXB8ybf(ReDsnjlp~e}81K zp<5NF?ApRT>{IqbB#^r395a0?4(mYJDk$f~r~!Z&GwlhKq_DtLN77+~JSecmEY7=t zO_Yi;LLJ1;yC#b$f#Ma9pW3rul}y-$@3g&E&i^Y?+CVl-DD=bQu)rVHkIDoVl$%5z zhJ!E(VSm)DEEmxYyR2xRiGCURN)LwMtPpV>sbUowdc!R%Auwip9o&GmLC;-rRnSnA u+^Ut~NQtg6Grzd%eI%5zbo@d72l^1al{eA_u}yyy_2EB+Bt)9oBT;|rO-NP% delta 15 Wcmeykjd#jI-i8*&7N#xCQvv`tLIxcG diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml index d5aae5a02..5ce758fee 100644 --- a/gradle/verification-metadata.xml +++ b/gradle/verification-metadata.xml @@ -63,6 +63,7 @@ + @@ -86,7 +87,10 @@ - + + + + @@ -166,6 +170,11 @@ + + + + + @@ -648,6 +657,16 @@ + + + + + + + + + +