diff --git a/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt index 097cde704e..cd42d0269b 100644 --- a/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt +++ b/implementation/src/main/java/info/nightscout/implementation/queue/CommandQueueImplementation.kt @@ -99,7 +99,7 @@ class CommandQueueImplementation @Inject constructor( ) : CommandQueue { private val disposable = CompositeDisposable() - private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) + internal var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) private val queue = LinkedList() @Volatile private var thread: QueueThread? = null diff --git a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt index 95471d7e49..e416baeae5 100644 --- a/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt +++ b/implementation/src/test/java/info/nightscout/implementation/queue/CommandQueueImplementationTest.kt @@ -1,6 +1,7 @@ package info.nightscout.implementation.queue import android.content.Context +import android.os.Handler import android.os.PowerManager import dagger.android.AndroidInjector import dagger.android.HasAndroidInjector @@ -42,7 +43,9 @@ import org.junit.Before import org.junit.Test import org.mockito.Mock import org.mockito.Mockito.anyLong +import org.mockito.Mockito.mock import org.mockito.Mockito.`when` +import org.mockito.invocation.InvocationOnMock import java.util.Calendar class CommandQueueImplementationTest : TestBaseWithProfile() { @@ -162,6 +165,13 @@ class CommandQueueImplementationTest : TestBaseWithProfile() { dateUtil, repository, fabricPrivacy, config, androidPermission, activityNames ) + val handler = mock(Handler::class.java) + `when`(handler.post(anyObject())).thenAnswer { invocation: InvocationOnMock -> + (invocation.arguments[0] as Runnable).run() + true + } + commandQueue.handler = handler + // start with empty queue Assert.assertEquals(0, commandQueue.size())