Skip to content

Commit

Permalink
Merge pull request #13 from thumbtack/instant
Browse files Browse the repository at this point in the history
MINF-2057 Support Instant class using provided reference date
  • Loading branch information
kelvinwong11 authored Jun 27, 2024
2 parents cd90d3a + df283c2 commit acaa6ce
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private fun generateValueForSimpleField(
java.lang.Byte::class.java -> 0.toByte()
Short::class.java -> 0.toShort()
java.lang.Short::class.java -> 0.toShort()
java.time.Instant::class.java -> Instant.EPOCH
java.time.Instant::class.java -> params.referenceDate?.toInstant() ?: Instant.EPOCH
IntArray::class.java -> intArrayOf(0, 0, 0)
FloatArray::class.java -> floatArrayOf(0f, 0f, 0f)
DoubleArray::class.java -> doubleArrayOf(0.0, 0.0, 0.0)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.thumbtack.kotlin.test

import java.time.Instant
import java.util.Date
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
Expand All @@ -22,6 +24,8 @@ class GenerateTestObjectTest {
val charArray: CharArray,
val shortArray: ShortArray,
val byteArray: ByteArray,
val date: Date,
val instant: Instant,
)

@Test
Expand All @@ -37,6 +41,15 @@ class GenerateTestObjectTest {
testObject.listField.forEachIndexed { index, item ->
assertEquals("listField${index}Value", item)
}
assertEquals(3, testObject.setField.size)
testObject.setField.forEachIndexed { index, item ->
assertEquals("setField${index}Value", item)
}
assertEquals(3, testObject.mapField.size)
testObject.mapField.onEachIndexed { index, entry ->
assertEquals("mapField${index}keyValue", entry.key)
assertEquals("mapField${index}valueValue", entry.value)
}
assertEquals(3, testObject.intArray.size)
assertTrue(testObject.intArray.all { it == 0 })
assertEquals(3, testObject.floatArray.size)
Expand All @@ -51,6 +64,8 @@ class GenerateTestObjectTest {
assertTrue(testObject.byteArray.all { it == 0.toByte() })
assertEquals(3, testObject.booleanArray.size)
assertTrue(testObject.booleanArray.all { !it })
assertEquals(Date(0), testObject.date)
assertEquals(Instant.EPOCH, testObject.instant)
}

@Test
Expand All @@ -62,4 +77,14 @@ class GenerateTestObjectTest {
assertEquals(collectionSize, testObject.setField.size)
assertEquals(collectionSize, testObject.mapField.size)
}

@Test
fun `test referenceDate`() {
val currentDate = Date()
val testObject = SampleClass::class.generateTestObject(referenceDate = currentDate)

assertEquals(currentDate, testObject.date)
assertEquals(currentDate.toInstant(), testObject.instant)
assertEquals(testObject.date.toInstant(), testObject.instant)
}
}

0 comments on commit acaa6ce

Please sign in to comment.