added clock service module
All checks were successful
Build, test and publish the Quarkus libraries / build (push) Successful in 10m19s
All checks were successful
Build, test and publish the Quarkus libraries / build (push) Successful in 10m19s
This commit is contained in:
parent
6e2ce2d489
commit
d4edd00f0f
9 changed files with 161 additions and 26 deletions
|
@ -0,0 +1,24 @@
|
|||
package ch.phoenixtechnologies.quarkus.commons.clock;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Clock;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@QuarkusTest
|
||||
class ClockProducerTest {
|
||||
|
||||
@Inject
|
||||
Clock clock;
|
||||
|
||||
@Test
|
||||
void produceClock() {
|
||||
assertThat(clock.getZone())
|
||||
.as("Produced clock's zone should match expected value")
|
||||
.isEqualTo(Clock.systemDefaultZone().getZone());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package ch.phoenixtechnologies.quarkus.commons.clock;
|
||||
|
||||
import io.quarkus.test.InjectMock;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.mockito.InjectSpy;
|
||||
import jakarta.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.Instant;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@QuarkusTest
|
||||
class ClockServiceImplTest {
|
||||
|
||||
@Inject
|
||||
ClockService clockService;
|
||||
|
||||
@InjectMock
|
||||
Clock clock;
|
||||
|
||||
@Test
|
||||
void instant() {
|
||||
var expected = Instant.ofEpochMilli(1729280640915L);
|
||||
when(clock.instant()).thenReturn(expected);
|
||||
|
||||
assertThat(clockService.instant())
|
||||
.as("Instant should match expected value")
|
||||
.isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
void currentTimeMillis() {
|
||||
var expected = 1729280640915L;
|
||||
when(clock.millis()).thenReturn(expected);
|
||||
|
||||
assertThat(clockService.currentTimeMillis())
|
||||
.as("Instant should match expected value")
|
||||
.isEqualTo(expected);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue