Skip to content

Commit cae89c3

Browse files
committed
Merge branch 'master' of github.com:PolymerLabs/arcs into r2p
2 parents 0360752 + e587539 commit cae89c3

File tree

9 files changed

+518
-304
lines changed

9 files changed

+518
-304
lines changed

javatests/arcs/android/host/AndroidAllocatorTest.kt

-24
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ package arcs.android.host
1313

1414
import android.content.Context
1515
import androidx.lifecycle.Lifecycle
16-
import androidx.test.core.app.ActivityScenario
1716
import androidx.test.core.app.ApplicationProvider
1817
import androidx.test.ext.junit.runners.AndroidJUnit4
1918
import androidx.work.testing.WorkManagerTestInitHelper
@@ -26,12 +25,9 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
2625
import kotlinx.coroutines.GlobalScope
2726
import kotlinx.coroutines.launch
2827
import kotlinx.coroutines.runBlocking
29-
import kotlinx.coroutines.test.TestCoroutineScope
30-
import kotlinx.coroutines.test.runBlockingTest
3128
import org.junit.Before
3229
import org.junit.runner.RunWith
3330
import org.robolectric.Robolectric
34-
import kotlin.coroutines.CoroutineContext
3531

3632
/**
3733
* These tests are the same as [AllocatorTestBase] but run with Android Services,
@@ -82,24 +78,4 @@ open class AndroidAllocatorTest : AllocatorTestBase() {
8278
writingService = Robolectric.setupService(TestWritingExternalHostService::class.java)
8379
super.setUp()
8480
}
85-
86-
override fun runAllocatorTest(
87-
coroutineContext: CoroutineContext,
88-
testBody: suspend TestCoroutineScope.() -> Unit
89-
) = runBlockingTest(coroutineContext) {
90-
val scenario = ActivityScenario.launch(TestActivity::class.java)
91-
92-
scenario.moveToState(Lifecycle.State.STARTED)
93-
94-
val activityJob = launch {
95-
scenario.onActivity { activity ->
96-
runBlocking {
97-
this@runBlockingTest.testBody()
98-
}
99-
scenario.close()
100-
}
101-
}
102-
103-
activityJob.join()
104-
}
10581
}

javatests/arcs/android/host/AndroidEntityHandleManagerTest.kt

+21-32
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package arcs.android.host
22

33
import android.app.Application
44
import androidx.lifecycle.Lifecycle
5-
import androidx.test.core.app.ActivityScenario
5+
import androidx.lifecycle.LifecycleOwner
6+
import androidx.lifecycle.LifecycleRegistry
67
import androidx.test.core.app.ApplicationProvider
78
import androidx.test.ext.junit.runners.AndroidJUnit4
89
import androidx.work.testing.WorkManagerTestInitHelper
@@ -27,8 +28,6 @@ import arcs.sdk.android.storage.service.testutil.TestBindingDelegate
2728
import com.google.common.truth.Truth.assertThat
2829
import kotlinx.coroutines.launch
2930
import kotlinx.coroutines.runBlocking
30-
import kotlinx.coroutines.test.TestCoroutineScope
31-
import kotlinx.coroutines.test.runBlockingTest
3231
import org.junit.Before
3332
import org.junit.Test
3433
import org.junit.runner.RunWith
@@ -38,12 +37,15 @@ typealias Person = TestParticleInternal1
3837

3938
@Suppress("EXPERIMENTAL_API_USAGE")
4039
@RunWith(AndroidJUnit4::class)
41-
class AndroidEntityHandleManagerTest {
40+
class AndroidEntityHandleManagerTest : LifecycleOwner {
4241
private lateinit var app: Application
42+
private lateinit var lifecycle: LifecycleRegistry
43+
override fun getLifecycle() = lifecycle
4344

4445
val entity1 = Person("Jason", 21.0, false)
4546
val entity2 = Person("Jason", 22.0, true)
4647
lateinit var handleHolder: TestParticleHandles
48+
private lateinit var handleManager: EntityHandleManager
4749

4850
private val schema = Schema(
4951
listOf(SchemaName("Person")),
@@ -69,37 +71,24 @@ class AndroidEntityHandleManagerTest {
6971
@Before
7072
fun setUp() {
7173
app = ApplicationProvider.getApplicationContext()
72-
app.setTheme(R.style.Theme_AppCompat);
74+
lifecycle = LifecycleRegistry(this).apply {
75+
setCurrentState(Lifecycle.State.CREATED)
76+
setCurrentState(Lifecycle.State.STARTED)
77+
setCurrentState(Lifecycle.State.RESUMED)
78+
}
7379

7480
// Initialize WorkManager for instrumentation tests.
7581
WorkManagerTestInitHelper.initializeTestWorkManager(app)
7682

7783
handleHolder = TestParticleHandles()
78-
}
7984

80-
fun handleManagerTest(
81-
block: suspend TestCoroutineScope.(EntityHandleManager) -> Unit
82-
) = runBlockingTest {
83-
val scenario = ActivityScenario.launch(TestActivity::class.java)
84-
85-
scenario.moveToState(Lifecycle.State.STARTED)
86-
87-
val activityJob = launch {
88-
scenario.onActivity { activity ->
89-
val hf = AndroidHandleManager(
90-
lifecycle = activity.lifecycle, context = activity,
91-
connectionFactory = DefaultConnectionFactory(
92-
activity, TestBindingDelegate(app), coroutineContext
93-
),
94-
coroutineContext = coroutineContext
95-
)
96-
runBlocking {
97-
this@runBlockingTest.block(EntityHandleManager(hf))
98-
}
99-
scenario.close()
100-
}
101-
}
102-
activityJob.join()
85+
handleManager = EntityHandleManager(
86+
AndroidHandleManager(
87+
lifecycle = lifecycle,
88+
context = app,
89+
connectionFactory = DefaultConnectionFactory(app, TestBindingDelegate(app))
90+
)
91+
)
10392
}
10493

10594
private fun expectHandleException(handleName: String, block: () -> Unit) {
@@ -110,7 +99,7 @@ class AndroidEntityHandleManagerTest {
11099
}
111100

112101
@Test
113-
fun handle_uninitializedThrowsException() = handleManagerTest {
102+
fun handle_uninitializedThrowsException() = runBlocking {
114103
expectHandleException("writeHandle") {
115104
handleHolder.writeHandle
116105
}
@@ -161,7 +150,7 @@ class AndroidEntityHandleManagerTest {
161150
)
162151

163152
@Test
164-
fun singletonHandle_writeFollowedByReadWithOnUpdate() = handleManagerTest { handleManager ->
153+
fun singletonHandle_writeFollowedByReadWithOnUpdate() = runBlocking {
165154
val writeHandle = createSingletonHandle(
166155
handleManager,
167156
"writeHandle",
@@ -208,7 +197,7 @@ class AndroidEntityHandleManagerTest {
208197
}
209198

210199
@Test
211-
fun setHandle_writeFollowedByReadWithOnUpdate() = handleManagerTest { handleManager ->
200+
fun setHandle_writeFollowedByReadWithOnUpdate() = runBlocking<Unit> {
212201
val writeSetHandle = createSetHandle(
213202
handleManager,
214203
"writeSetHandle",

javatests/arcs/android/host/AndroidManifest.xml

-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
</intent-filter>
1616
</service>
1717
<service android:name="arcs.sdk.android.service.StorageService" android:exported="false"/>
18-
<activity android:name="arcs.android.host.TestActivity" >
19-
<intent-filter>
20-
<action android:name="android.intent.action.MAIN"/>
21-
<category android:name="android.intent.category.LAUNCHER"/>
22-
</intent-filter>
23-
</activity>
2418
</application>
2519

2620
</manifest>

javatests/arcs/android/host/BUILD

-11
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@ licenses(["notice"])
99

1010
package(default_visibility = ["//visibility:public"])
1111

12-
kt_android_library(
13-
name = "test_app",
14-
testonly = 1,
15-
srcs = ["TestActivity.kt"],
16-
manifest = ":AndroidManifest.xml",
17-
deps = [
18-
"//third_party/java/androidx/appcompat",
19-
],
20-
)
21-
2212
arcs_kt_android_test_suite(
2313
name = "host",
2414
srcs = glob(["*Test.kt"]),
@@ -27,7 +17,6 @@ arcs_kt_android_test_suite(
2717
deps = [
2818
":schemas",
2919
":services",
30-
":test_app",
3120
"//java/arcs/android/crdt",
3221
"//java/arcs/android/host",
3322
"//java/arcs/android/sdk/host",

javatests/arcs/android/host/TestActivity.kt

-5
This file was deleted.

javatests/arcs/android/storage/handle/AndroidHandleManagerTest.kt

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.app.Application
44
import androidx.lifecycle.Lifecycle
55
import androidx.lifecycle.LifecycleOwner
66
import androidx.lifecycle.LifecycleRegistry
7-
import androidx.test.core.app.ActivityScenario
87
import androidx.test.core.app.ApplicationProvider
98
import androidx.test.ext.junit.runners.AndroidJUnit4
109
import androidx.work.testing.WorkManagerTestInitHelper

javatests/arcs/core/allocator/AllocatorTestBase.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import arcs.core.testutil.assertSuspendingThrows
2626
import arcs.core.type.Type
2727
import arcs.jvm.host.ExplicitHostRegistry
2828
import com.google.common.truth.Truth.assertThat
29+
import kotlinx.coroutines.CoroutineScope
2930
import kotlinx.coroutines.ExperimentalCoroutinesApi
3031
import kotlinx.coroutines.runBlocking
3132
import kotlinx.coroutines.test.TestCoroutineScope
@@ -73,8 +74,8 @@ open class AllocatorTestBase {
7374
open val storageCapability = Capabilities.TiedToRuntime
7475
open fun runAllocatorTest(
7576
coroutineContext: CoroutineContext = EmptyCoroutineContext,
76-
testBody: suspend TestCoroutineScope.() -> Unit
77-
) = runBlockingTest(coroutineContext, testBody)
77+
testBody: suspend CoroutineScope.() -> Unit
78+
) = runBlocking(coroutineContext) { testBody() }
7879

7980
open suspend fun hostRegistry(): HostRegistry {
8081
val registry = ExplicitHostRegistry()

0 commit comments

Comments
 (0)