-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return nulls from MultibindingWorkerFactory for non-existent Worker c…
…lasses instead of throwing exceptions (#96)
- Loading branch information
Showing
2 changed files
with
67 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
whetstone-worker/src/test/java/com/deliveryhero/whetstone/worker/LoadClassTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.deliveryhero.whetstone.worker | ||
|
||
import android.content.Context | ||
import androidx.work.Worker | ||
import androidx.work.WorkerParameters | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNull | ||
|
||
internal class LoadClassTest { | ||
@Test | ||
fun `loadClass returns null for non-existing class`() { | ||
val result = MultibindingWorkerFactory.loadClass( | ||
this.javaClass.classLoader!!, | ||
"non.existent.worker.Class" | ||
) | ||
assertNull(result) | ||
} | ||
|
||
@Test | ||
fun `loadClass returns null for class which is not ListenableWorker subclass`() { | ||
val result = MultibindingWorkerFactory.loadClass( | ||
this.javaClass.classLoader!!, | ||
"com.deliveryhero.whetstone.worker.LoadClassTest\$TestClass" | ||
) | ||
assertNull(result) | ||
} | ||
|
||
@Test | ||
fun `loadClass returns class for existing classname`() { | ||
val result = MultibindingWorkerFactory.loadClass( | ||
this.javaClass.classLoader!!, | ||
"com.deliveryhero.whetstone.worker.LoadClassTest\$TestWorker" | ||
) | ||
assertEquals(TestWorker::class.java, result) | ||
} | ||
|
||
private class TestWorker( | ||
context: Context, | ||
workerParams: WorkerParameters, | ||
) : Worker(context, workerParams) { | ||
override fun doWork(): Result { | ||
TODO("Not implemented") | ||
} | ||
} | ||
|
||
@Suppress("unused") | ||
private class TestClass | ||
} |