Skip to content

Commit

Permalink
adding a unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-peluso committed Jan 27, 2025
1 parent a931788 commit c230bed
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions sdk/core/src/test/java/com/klaviyo/core/config/SystemClockTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,34 @@
package com.klaviyo.core.config

import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
import java.util.TimeZone
import junit.framework.TestCase.assertEquals
import org.junit.After
import org.junit.Assert
import org.junit.Before
import org.junit.Test

class SystemClockTest {

private var defaultLocale: Locale? = null

@Before
fun setUp() {
// Save the original default locale
defaultLocale = Locale.getDefault()

// Set default locale to Arabic
Locale.setDefault(Locale("ar"))
}

@After
fun tearDown() {
// Restore the original default locale after test
defaultLocale?.let { Locale.setDefault(it) }
}

@Test
fun `Clock uses proper date format`() {
val regex7 = "^\\d{4}(-\\d\\d(-\\d\\d(T\\d\\d:\\d\\d(:\\d\\d)?(\\.\\d+)?(([+-]\\d\\d:*\\d\\d)|Z)?)?)?)?\$".toRegex()
Expand Down Expand Up @@ -36,4 +60,20 @@ class SystemClockTest {
Thread.sleep(20L)
Assert.assertEquals(1, counter)
}

@Test
fun `Clock uses English locale for date formatting`() {
val expectedFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH).apply {
timeZone = TimeZone.getTimeZone("UTC")
}

// Use a known timestamp for test consistency
val testTimestamp = 0L
val expectedOutput = expectedFormat.format(Date(testTimestamp))

// using the utility
val actualOutput = SystemClock.isoTime(testTimestamp)

assertEquals(expectedOutput, actualOutput)
}
}

0 comments on commit c230bed

Please sign in to comment.