samir
06/25/2018, 11:31 AMclass Temp1 {
@Test
fun someTest() {
val timestamp = Instant.now().toEpochMilli()
println(timestamp) //real value
}
@Test
fun someOtherTest() {
mockkStatic(Instant::class)
every { Instant.now().toEpochMilli() } returns 123
val timestamp = Instant.now().toEpochMilli()
println(timestamp) //123
unmockStatic(Instant::class)
}
}
class Temp1 {
@BeforeAll
fun setup() {
mockkStatic(Instant::class)
}
@BeforeEach
fun beforeEach() {
clearStaticMocks(Instant::class)
}
@Test
fun someTest() {
every { Instant.now().toEpochMilli() } returns 123
val timestamp = Instant.now().toEpochMilli()
println(timestamp) //123
}
@Test
fun someOtherTest() {
every { Instant.now().toEpochMilli() } returns 456
val timestamp = Instant.now().toEpochMilli() //456
}
}