Merge pull request 'added clock service module' (#3) from dev into main
Some checks failed
Build, test and publish the Quarkus libraries / build (push) Has been cancelled
Some checks failed
Build, test and publish the Quarkus libraries / build (push) Has been cancelled
Reviewed-on: phoenix/quarkus-commons#3
This commit is contained in:
commit
e9da1d0fae
9 changed files with 161 additions and 26 deletions
22
pom.xml
22
pom.xml
|
@ -9,6 +9,7 @@
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
|
<module>quarkus-clock-service</module>
|
||||||
<module>quarkus-random-generator</module>
|
<module>quarkus-random-generator</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
@ -59,11 +60,32 @@
|
||||||
<groupId>io.quarkus</groupId>
|
<groupId>io.quarkus</groupId>
|
||||||
<artifactId>quarkus-arc</artifactId>
|
<artifactId>quarkus-arc</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj-core.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.quarkus</groupId>
|
<groupId>io.quarkus</groupId>
|
||||||
<artifactId>quarkus-junit5</artifactId>
|
<artifactId>quarkus-junit5</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-junit5-mockito</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-jacoco</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
16
quarkus-clock-service/pom.xml
Normal file
16
quarkus-clock-service/pom.xml
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>ch.phoenixtechnologies.quarkus</groupId>
|
||||||
|
<artifactId>quarkus-commons</artifactId>
|
||||||
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>quarkus-clock-service</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
</project>
|
|
@ -0,0 +1,18 @@
|
||||||
|
package ch.phoenixtechnologies.quarkus.commons.clock;
|
||||||
|
|
||||||
|
import io.quarkus.arc.DefaultBean;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
import jakarta.enterprise.inject.Produces;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
|
|
||||||
|
class ClockProducer {
|
||||||
|
|
||||||
|
@Produces
|
||||||
|
@DefaultBean
|
||||||
|
@ApplicationScoped
|
||||||
|
Clock produceClock() {
|
||||||
|
return Clock.systemDefaultZone();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
package ch.phoenixtechnologies.quarkus.commons.clock;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
public interface ClockService {
|
||||||
|
|
||||||
|
Instant instant();
|
||||||
|
|
||||||
|
long currentTimeMillis();
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package ch.phoenixtechnologies.quarkus.commons.clock;
|
||||||
|
|
||||||
|
import io.quarkus.arc.DefaultBean;
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
@DefaultBean
|
||||||
|
@ApplicationScoped
|
||||||
|
class ClockServiceImpl implements ClockService {
|
||||||
|
|
||||||
|
private final Clock clock;
|
||||||
|
|
||||||
|
ClockServiceImpl(Clock clock) {
|
||||||
|
this.clock = clock;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Instant instant() {
|
||||||
|
return clock.instant();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long currentTimeMillis() {
|
||||||
|
return clock.millis();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -20,31 +20,6 @@
|
||||||
<artifactId>java-uuid-generator</artifactId>
|
<artifactId>java-uuid-generator</artifactId>
|
||||||
<version>${java-uuid-generator.version}</version>
|
<version>${java-uuid-generator.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.assertj</groupId>
|
|
||||||
<artifactId>assertj-core</artifactId>
|
|
||||||
<version>${assertj-core.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.quarkus</groupId>
|
|
||||||
<artifactId>quarkus-junit5-component</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.quarkus</groupId>
|
|
||||||
<artifactId>quarkus-junit5-mockito</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.quarkus</groupId>
|
|
||||||
<artifactId>quarkus-jacoco</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-junit-jupiter</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package ch.phoenixtechnologies.quarkus.commons.random;
|
package ch.phoenixtechnologies.quarkus.commons.random;
|
||||||
|
|
||||||
import io.quarkus.test.component.QuarkusComponentTest;
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import io.quarkus.test.junit.mockito.InjectSpy;
|
import io.quarkus.test.junit.mockito.InjectSpy;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue