Skip to content

Commit

Permalink
Add unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Santosh Pingle committed May 28, 2024
1 parent c5deeeb commit 6d535d5
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,26 @@ class FhirEngineImplTest {
.inOrder()
}

@Test
fun `test consolidate() is called`() = runBlocking {
assertThat(services.database.getLocalChangesCount()).isEqualTo(1)
fhirEngine
.syncUpload(UploadStrategy.SingleResourcePost) {
flowOf(
UploadRequestResult.Success(
listOf(
ResourceUploadResponseMapping(
it,
TEST_PATIENT_1,
),
),
),
)
}
.collect {}
assertThat(services.database.getLocalChangesCount()).isEqualTo(0)
}

companion object {
private const val TEST_PATIENT_1_ID = "test_patient_1"
private var TEST_PATIENT_1 =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.android.fhir.sync.upload

import androidx.test.core.app.ApplicationProvider
import com.google.android.fhir.FhirServices
import kotlin.test.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class ResourceConsolidatorFactoryTest {
private val services =
FhirServices.builder(ApplicationProvider.getApplicationContext()).inMemory().build()

@Test
fun `return HttpPostResourceConsolidator instance `() {
val httpPostResourceConsolidator =
ResourceConsolidatorFactory.byHttpVerb(
UploadStrategy.SingleResourcePost.requestGeneratorMode,
services.database,
)
assertTrue(httpPostResourceConsolidator is HttpPostResourceConsolidator)
}

@Test
fun `return DefaultResourceConsolidator instance `() {
val httpPostResourceConsolidator =
ResourceConsolidatorFactory.byHttpVerb(
UploadStrategy.AllChangesSquashedBundlePut.requestGeneratorMode,
services.database,
)
assertTrue(httpPostResourceConsolidator is DefaultResourceConsolidator)
}
}

0 comments on commit 6d535d5

Please sign in to comment.