Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: Utils test implemented in core module #420

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions engine/src/test/java/com/google/android/fhir/UtilTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ package com.google.android.fhir

import android.os.Build
import com.google.common.truth.Truth.assertThat
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.Locale
import junit.framework.TestCase
import org.hl7.fhir.r4.model.IdType
import org.hl7.fhir.r4.model.OperationOutcome
Expand All @@ -31,6 +35,19 @@ import org.robolectric.annotation.Config
@Config(sdk = [Build.VERSION_CODES.P])
class UtilTest : TestCase() {

@Test
fun shouldFormatDate() {
val fixedDate = "Sat Jun 05 16:17:31 +0530 2021"
val formatter = DateTimeFormatter.ofPattern("EE MMM dd HH:mm:ss ZZ yyyy")
val parsedDate = ZonedDateTime.parse(fixedDate, formatter)

val simpleDateFormat =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssXXXXX", Locale.getDefault())
.withZone(ZoneId.systemDefault())
val expectedResult = simpleDateFormat.format(parsedDate.toInstant())
assertThat(parsedDate.toString()).isEqualTo(expectedResult)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@Ana2k Ana2k Jul 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these are the changes for the same.
The tests passed on my end.
Let me know if any issues exist or more changes are required.
@maimoonak tagging you to update about previous PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not see the Date.toTimeZoneString method being called here. How is it being tested?

}

@Test
fun logicalId_patient_missing_id_shouldReturnEmptyString() {
val patient = Patient()
Expand Down