Skip to content

Commit 5f61b6c

Browse files
authored
Replace EverNote with Android WorkManager
1 parent 3eff84c commit 5f61b6c

File tree

4 files changed

+137
-209
lines changed

4 files changed

+137
-209
lines changed

core/build.gradle

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,11 @@ tasks.matching { it.name.startsWith("connected") || it.name.startsWith("test")}.
4848
dependencies {
4949
api "com.cloudinary:cloudinary-core:${cloudinaryLibsVersion}"
5050

51-
implementation 'androidx.core:core:1.6.0'
51+
implementation 'androidx.core:core:1.7.0'
5252
implementation 'androidx.appcompat:appcompat:1.3.0'
5353
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
5454
implementation 'com.google.android.material:material:1.4.0'
55-
implementation('com.evernote:android-job:1.4.2', {
56-
exclude group: 'com.android.support', module: 'support-compat'
57-
})
55+
implementation 'androidx.work:work-runtime:2.7.1'
5856

5957
testImplementation 'androidx.test.ext:junit:1.1.3'
6058
testImplementation "com.cloudinary:cloudinary-test-common:${cloudinaryLibsVersion}"

core/src/androidTest/java/com/cloudinary/android/AndroidJobStrategyTest.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,42 @@
22

33

44
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner;
5+
import androidx.test.internal.util.ReflectionUtil;
6+
import androidx.work.BackoffPolicy;
7+
import androidx.work.Constraints;
8+
import androidx.work.OneTimeWorkRequest;
9+
import androidx.work.WorkManager;
10+
import androidx.work.WorkRequest;
11+
import androidx.work.impl.model.WorkSpec;
512

613
import com.cloudinary.android.payload.FilePayload;
7-
import com.evernote.android.job.JobRequest;
8-
9-
import junit.framework.Assert;
1014

15+
import org.junit.Assert;
1116
import org.junit.Test;
1217
import org.junit.runner.RunWith;
1318

1419
import java.io.IOException;
20+
import java.lang.reflect.Field;
21+
import java.lang.reflect.ParameterizedType;
1522

1623
@RunWith(AndroidJUnit4ClassRunner.class)
1724
public class AndroidJobStrategyTest extends AbstractTest {
1825

1926
@Test
20-
public void testAdapter() throws InterruptedException, IOException {
27+
public void testAdapter() throws InterruptedException, IOException, NoSuchFieldException, IllegalAccessException {
2128
FilePayload payload = buildPayload();
2229

2330
int tenMinutes = 10 * 60 * 1000;
2431
UploadRequest<FilePayload> request = buildUploadRequest(payload, tenMinutes);
2532

26-
JobRequest adapted = AndroidJobStrategy.adapt(request);
33+
WorkRequest adapted = AndroidJobStrategy.adapt(request);
34+
Class obj = adapted.getClass().getSuperclass();
35+
Field field = obj.getDeclaredField("mWorkSpec");
36+
field.setAccessible(true);
37+
Assert.assertEquals(true, adapted.getWorkSpec().constraints.requiresCharging());
38+
Assert.assertEquals(false, adapted.getWorkSpec().constraints.requiresDeviceIdle());
39+
Assert.assertEquals(10000, adapted.getWorkSpec().backoffDelayDuration);
40+
Assert.assertEquals(BackoffPolicy.LINEAR, adapted.getWorkSpec().backoffPolicy);
2741

28-
Assert.assertEquals(20, adapted.getStartMs());
29-
Assert.assertEquals(tenMinutes, adapted.getEndMs());
30-
Assert.assertEquals(true, adapted.requiresCharging());
31-
Assert.assertEquals(false, adapted.requiresDeviceIdle());
32-
Assert.assertEquals(100, adapted.getBackoffMs());
33-
Assert.assertEquals(JobRequest.BackoffPolicy.LINEAR, adapted.getBackoffPolicy());
34-
Assert.assertEquals(9, adapted.getExtras().get("maxErrorRetries"));
3542
}
3643
}

0 commit comments

Comments
 (0)