Merge pull request 'feat(deps): add spotless-maven-plugin 2.43.0 and palantir-java-format 2.50.0' (#21) from spotless 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#21
This commit is contained in:
commit
0c3a30138a
18 changed files with 113 additions and 155 deletions
25
pom.xml
25
pom.xml
|
@ -24,6 +24,8 @@
|
||||||
<compiler-plugin.version>3.13.0</compiler-plugin.version>
|
<compiler-plugin.version>3.13.0</compiler-plugin.version>
|
||||||
<surefire-plugin.version>3.5.2</surefire-plugin.version>
|
<surefire-plugin.version>3.5.2</surefire-plugin.version>
|
||||||
<jacoco-plugin.version>0.8.12</jacoco-plugin.version>
|
<jacoco-plugin.version>0.8.12</jacoco-plugin.version>
|
||||||
|
<spotless-maven-plugin.version>2.43.0</spotless-maven-plugin.version>
|
||||||
|
<palantir-java-format.version>2.50.0</palantir-java-format.version>
|
||||||
|
|
||||||
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
|
||||||
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
|
||||||
|
@ -132,6 +134,29 @@
|
||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>com.diffplug.spotless</groupId>
|
||||||
|
<artifactId>spotless-maven-plugin</artifactId>
|
||||||
|
<version>${spotless-maven-plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>check</goal>
|
||||||
|
</goals>
|
||||||
|
<phase>compile</phase>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
<configuration>
|
||||||
|
<java>
|
||||||
|
<removeUnusedImports/>
|
||||||
|
<palantirJavaFormat>
|
||||||
|
<version>${palantir-java-format.version}</version>
|
||||||
|
<style>PALANTIR</style>
|
||||||
|
<formatJavadoc>false</formatJavadoc>
|
||||||
|
</palantirJavaFormat>
|
||||||
|
</java>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -3,7 +3,6 @@ package ch.phoenixtechnologies.quarkus.commons.clock;
|
||||||
import io.quarkus.arc.DefaultBean;
|
import io.quarkus.arc.DefaultBean;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.enterprise.inject.Produces;
|
import jakarta.enterprise.inject.Produces;
|
||||||
|
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
|
|
||||||
class ClockProducer {
|
class ClockProducer {
|
||||||
|
@ -14,5 +13,4 @@ class ClockProducer {
|
||||||
Clock produceClock() {
|
Clock produceClock() {
|
||||||
return Clock.systemDefaultZone();
|
return Clock.systemDefaultZone();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ch.phoenixtechnologies.quarkus.commons.clock;
|
||||||
|
|
||||||
import io.quarkus.arc.DefaultBean;
|
import io.quarkus.arc.DefaultBean;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package ch.phoenixtechnologies.quarkus.commons.clock;
|
package ch.phoenixtechnologies.quarkus.commons.clock;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.time.Clock;
|
import java.time.Clock;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
class ClockProducerTest {
|
class ClockProducerTest {
|
||||||
|
@ -21,4 +19,4 @@ class ClockProducerTest {
|
||||||
.as("Produced clock's zone should match expected value")
|
.as("Produced clock's zone should match expected value")
|
||||||
.isEqualTo(Clock.systemDefaultZone().getZone());
|
.isEqualTo(Clock.systemDefaultZone().getZone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
package ch.phoenixtechnologies.quarkus.commons.clock;
|
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.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import io.quarkus.test.InjectMock;
|
||||||
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import java.time.Clock;
|
||||||
|
import java.time.Instant;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
class ClockServiceImplTest {
|
class ClockServiceImplTest {
|
||||||
|
|
||||||
|
@ -40,4 +38,4 @@ class ClockServiceImplTest {
|
||||||
.as("Instant should match expected value")
|
.as("Instant should match expected value")
|
||||||
.isEqualTo(expected);
|
.isEqualTo(expected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,5 +9,4 @@ public interface JsonService {
|
||||||
<T> T fromJson(String json, Class<T> clazz);
|
<T> T fromJson(String json, Class<T> clazz);
|
||||||
|
|
||||||
<T> T fromJson(String json, TypeReference<T> typeReference);
|
<T> T fromJson(String json, TypeReference<T> typeReference);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,10 +30,9 @@ class JsonServiceImpl implements JsonService {
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(json, clazz);
|
return objectMapper.readValue(json, clazz);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new IllegalArgumentException("Unable to read object of class [" + clazz.getName()
|
throw new IllegalArgumentException(
|
||||||
+ "] from json String: " + json, e);
|
"Unable to read object of class [" + clazz.getName() + "] from json String: " + json, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -41,8 +40,10 @@ class JsonServiceImpl implements JsonService {
|
||||||
try {
|
try {
|
||||||
return objectMapper.readValue(json, typeReference);
|
return objectMapper.readValue(json, typeReference);
|
||||||
} catch (JsonProcessingException e) {
|
} catch (JsonProcessingException e) {
|
||||||
throw new IllegalArgumentException("Unable to read object of type [" + typeReference.getType().getTypeName()
|
throw new IllegalArgumentException(
|
||||||
+ "] from json String: " + json, e);
|
"Unable to read object of type [" + typeReference.getType().getTypeName() + "] from json String: "
|
||||||
|
+ json,
|
||||||
|
e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,21 @@
|
||||||
package ch.phoenixtechnologies.quarkus.commons.json;
|
package ch.phoenixtechnologies.quarkus.commons.json;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
|
||||||
import jakarta.inject.Inject;
|
|
||||||
import org.assertj.core.api.Assertions;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import java.util.List;
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
class JsonServiceImplTest {
|
class JsonServiceImplTest {
|
||||||
|
|
||||||
public static final TypeReference<List<TestRecord>> TYPE_REFERENCE = new TypeReference<>() {
|
public static final TypeReference<List<TestRecord>> TYPE_REFERENCE = new TypeReference<>() {};
|
||||||
};
|
|
||||||
|
|
||||||
record TestRecord(String name, int age) {
|
record TestRecord(String name, int age) {}
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
JsonServiceImpl jsonService;
|
JsonServiceImpl jsonService;
|
||||||
|
@ -29,9 +26,7 @@ class JsonServiceImplTest {
|
||||||
|
|
||||||
var actual = jsonService.toJson(new TestRecord("John Doe", 30));
|
var actual = jsonService.toJson(new TestRecord("John Doe", 30));
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Json should match expected value").isEqualTo(expected);
|
||||||
.as("Json should match expected value")
|
|
||||||
.isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -41,9 +36,7 @@ class JsonServiceImplTest {
|
||||||
|
|
||||||
var actual = jsonService.fromJson(json, TestRecord.class);
|
var actual = jsonService.fromJson(json, TestRecord.class);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Deserialized object should match expected value").isEqualTo(expected);
|
||||||
.as("Deserialized object should match expected value")
|
|
||||||
.isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -53,7 +46,8 @@ class JsonServiceImplTest {
|
||||||
assertThatThrownBy(() -> jsonService.fromJson(json, TestRecord.class))
|
assertThatThrownBy(() -> jsonService.fromJson(json, TestRecord.class))
|
||||||
.as("Should throw IllegalArgumentException when input is invalid")
|
.as("Should throw IllegalArgumentException when input is invalid")
|
||||||
.isInstanceOf(IllegalArgumentException.class)
|
.isInstanceOf(IllegalArgumentException.class)
|
||||||
.hasMessage("Unable to read object of class [ch.phoenixtechnologies.quarkus.commons.json.JsonServiceImplTest$TestRecord] from json String: {\"name\":\"John Doe\",\"age\":\"30\"");
|
.hasMessage(
|
||||||
|
"Unable to read object of class [ch.phoenixtechnologies.quarkus.commons.json.JsonServiceImplTest$TestRecord] from json String: {\"name\":\"John Doe\",\"age\":\"30\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -75,6 +69,7 @@ class JsonServiceImplTest {
|
||||||
assertThatThrownBy(() -> jsonService.fromJson(json, TYPE_REFERENCE))
|
assertThatThrownBy(() -> jsonService.fromJson(json, TYPE_REFERENCE))
|
||||||
.as("Should throw IllegalArgumentException when input is invalid")
|
.as("Should throw IllegalArgumentException when input is invalid")
|
||||||
.isInstanceOf(IllegalArgumentException.class)
|
.isInstanceOf(IllegalArgumentException.class)
|
||||||
.hasMessage("Unable to read object of type [java.util.List<ch.phoenixtechnologies.quarkus.commons.json.JsonServiceImplTest$TestRecord>] from json String: {\"name\":\"John Doe\",\"age\":30},{\"name\":\"Jane Doe\",\"age\":\"25\"}");
|
.hasMessage(
|
||||||
|
"Unable to read object of type [java.util.List<ch.phoenixtechnologies.quarkus.commons.json.JsonServiceImplTest$TestRecord>] from json String: {\"name\":\"John Doe\",\"age\":30},{\"name\":\"Jane Doe\",\"age\":\"25\"}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,5 +8,4 @@ public interface MessageDigestConfiguration {
|
||||||
|
|
||||||
@WithDefault("SHA-256")
|
@WithDefault("SHA-256")
|
||||||
String defaultAlgorithm();
|
String defaultAlgorithm();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ch.phoenixtechnologies.quarkus.commons.digest;
|
||||||
|
|
||||||
import io.quarkus.arc.DefaultBean;
|
import io.quarkus.arc.DefaultBean;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
|
|
|
@ -1,37 +1,37 @@
|
||||||
package ch.phoenixtechnologies.quarkus.commons.digest;
|
package ch.phoenixtechnologies.quarkus.commons.digest;
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
|
||||||
import jakarta.inject.Inject;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
|
||||||
import org.junit.jupiter.params.provider.ValueSource;
|
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.MessageDigest;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
|
||||||
|
|
||||||
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
|
import jakarta.inject.Inject;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.ValueSource;
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
class MessageDigestServiceImplTest {
|
class MessageDigestServiceImplTest {
|
||||||
|
|
||||||
public static final String INPUT = "test";
|
public static final String INPUT = "test";
|
||||||
public static final byte[] EXPECTED_SHA256_DIGEST = {-97, -122, -48, -127, -120, 76, 125, 101, -102, 47, -22, -96, -59, 90, -48, 21, -93, -65, 79, 27, 43, 11, -126, 44, -47, 93, 108, 21, -80, -16, 10, 8};
|
public static final byte[] EXPECTED_SHA256_DIGEST = {
|
||||||
|
-97, -122, -48, -127, -120, 76, 125, 101, -102, 47, -22, -96, -59, 90, -48, 21, -93, -65, 79, 27, 43, 11, -126,
|
||||||
|
44, -47, 93, 108, 21, -80, -16, 10, 8
|
||||||
|
};
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
MessageDigestServiceImpl service;
|
MessageDigestServiceImpl service;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getInstance() {
|
void getInstance() {
|
||||||
assertThat(service.getInstance())
|
assertThat(service.getInstance()).isInstanceOf(MessageDigest.class);
|
||||||
.isInstanceOf(MessageDigest.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@ValueSource(strings = {"SHA-256", "SHA-512", "MD5"})
|
@ValueSource(strings = {"SHA-256", "SHA-512", "MD5"})
|
||||||
void getInstanceWithAlgorithm(String algorithm) {
|
void getInstanceWithAlgorithm(String algorithm) {
|
||||||
assertThat(service.getInstance(algorithm))
|
assertThat(service.getInstance(algorithm)).isInstanceOf(MessageDigest.class);
|
||||||
.isInstanceOf(MessageDigest.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
|
@ -61,7 +61,6 @@ class MessageDigestServiceImplTest {
|
||||||
assertThat(service.digest(INPUT, StandardCharsets.UTF_8))
|
assertThat(service.digest(INPUT, StandardCharsets.UTF_8))
|
||||||
.as("Digest should match expected value")
|
.as("Digest should match expected value")
|
||||||
.isEqualTo(EXPECTED_SHA256_DIGEST);
|
.isEqualTo(EXPECTED_SHA256_DIGEST);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -78,4 +77,4 @@ class MessageDigestServiceImplTest {
|
||||||
.as("Digest should match expected value")
|
.as("Digest should match expected value")
|
||||||
.isEqualTo(EXPECTED_SHA256_DIGEST);
|
.isEqualTo(EXPECTED_SHA256_DIGEST);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ch.phoenixtechnologies.quarkus.commons.random;
|
||||||
|
|
||||||
import io.quarkus.arc.DefaultBean;
|
import io.quarkus.arc.DefaultBean;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ch.phoenixtechnologies.quarkus.commons.random;
|
||||||
|
|
||||||
import io.quarkus.arc.DefaultBean;
|
import io.quarkus.arc.DefaultBean;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -19,6 +18,4 @@ class RandomProviderImpl implements RandomProvider {
|
||||||
throw new IllegalStateException("Unable to obtain strong SecureRandom instance", e);
|
throw new IllegalStateException("Unable to obtain strong SecureRandom instance", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
package ch.phoenixtechnologies.quarkus.commons.random;
|
package ch.phoenixtechnologies.quarkus.commons.random;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
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;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
class RandomNumberGeneratorImplTest {
|
class RandomNumberGeneratorImplTest {
|
||||||
|
@ -26,9 +25,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateInt();
|
var actual = generator.generateInt();
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated int should match expected value").isEqualTo(-1305521323);
|
||||||
.as("Generated int should match expected value")
|
|
||||||
.isEqualTo(-1305521323);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -37,9 +34,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateInt(40);
|
var actual = generator.generateInt(40);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated int should match expected value").isEqualTo(26);
|
||||||
.as("Generated int should match expected value")
|
|
||||||
.isEqualTo(26);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -48,21 +43,16 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateInt(1, 40);
|
var actual = generator.generateInt(1, 40);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated int should match expected value").isEqualTo(17);
|
||||||
.as("Generated int should match expected value")
|
|
||||||
.isEqualTo(17);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void generateLong() {
|
void generateLong() {
|
||||||
when(provider.get()).thenReturn(getRandom());
|
when(provider.get()).thenReturn(getRandom());
|
||||||
|
|
||||||
var actual = generator.generateLong();
|
var actual = generator.generateLong();
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated long should match expected value").isEqualTo(-5607171386684657918L);
|
||||||
.as("Generated long should match expected value")
|
|
||||||
.isEqualTo(-5607171386684657918L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -71,9 +61,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateLong(40L);
|
var actual = generator.generateLong(40L);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated long should match expected value").isEqualTo(9L);
|
||||||
.as("Generated long should match expected value")
|
|
||||||
.isEqualTo(9L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -82,9 +70,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateLong(1L, 40L);
|
var actual = generator.generateLong(1L, 40L);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated long should match expected value").isEqualTo(23L);
|
||||||
.as("Generated long should match expected value")
|
|
||||||
.isEqualTo(23L);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -93,9 +79,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateFloat();
|
var actual = generator.generateFloat();
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated float should match expected value").isEqualTo(0.6960346f);
|
||||||
.as("Generated float should match expected value")
|
|
||||||
.isEqualTo(0.6960346f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -104,9 +88,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateFloat(0.99f);
|
var actual = generator.generateFloat(0.99f);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated float should match expected value").isEqualTo(0.6890743f);
|
||||||
.as("Generated float should match expected value")
|
|
||||||
.isEqualTo(0.6890743f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -115,9 +97,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateFloat(0.01f, 0.99f);
|
var actual = generator.generateFloat(0.01f, 0.99f);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated float should match expected value").isEqualTo(0.69211394f);
|
||||||
.as("Generated float should match expected value")
|
|
||||||
.isEqualTo(0.69211394f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -126,9 +106,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateDouble();
|
var actual = generator.generateDouble();
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated double should match expected value").isEqualTo(0.6960346394874213d);
|
||||||
.as("Generated double should match expected value")
|
|
||||||
.isEqualTo(0.6960346394874213d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -137,9 +115,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateDouble(0.99d);
|
var actual = generator.generateDouble(0.99d);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated double should match expected value").isEqualTo(0.6890742930925471d);
|
||||||
.as("Generated double should match expected value")
|
|
||||||
.isEqualTo(0.6890742930925471d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -148,9 +124,7 @@ class RandomNumberGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateDouble(0.01d, 0.99d);
|
var actual = generator.generateDouble(0.01d, 0.99d);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated double should match expected value").isEqualTo(0.6921139466976729d);
|
||||||
.as("Generated double should match expected value")
|
|
||||||
.isEqualTo(0.6921139466976729d);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -176,5 +150,4 @@ class RandomNumberGeneratorImplTest {
|
||||||
private static Random getRandom() {
|
private static Random getRandom() {
|
||||||
return new Random(24353L);
|
return new Random(24353L);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
package ch.phoenixtechnologies.quarkus.commons.random;
|
package ch.phoenixtechnologies.quarkus.commons.random;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.security.AccessController;
|
import java.security.AccessController;
|
||||||
import java.security.PrivilegedAction;
|
import java.security.PrivilegedAction;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.security.Security;
|
import java.security.Security;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
@SuppressWarnings("removal")
|
@SuppressWarnings("removal")
|
||||||
|
@ -47,16 +46,13 @@ class RandomProviderImplTest {
|
||||||
|
|
||||||
private static String getSecurityProperty() {
|
private static String getSecurityProperty() {
|
||||||
return AccessController.doPrivileged(
|
return AccessController.doPrivileged(
|
||||||
(PrivilegedAction<String>) () -> Security.getProperty(
|
(PrivilegedAction<String>) () -> Security.getProperty(SECURE_RANDOM_STRONG_ALGORITHMS));
|
||||||
SECURE_RANDOM_STRONG_ALGORITHMS));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setSecurityProperty(String datum) {
|
private static void setSecurityProperty(String datum) {
|
||||||
AccessController.doPrivileged(
|
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
|
||||||
(PrivilegedAction<Void>) () -> {
|
Security.setProperty(SECURE_RANDOM_STRONG_ALGORITHMS, datum);
|
||||||
Security.setProperty(
|
return (Void) null;
|
||||||
SECURE_RANDOM_STRONG_ALGORITHMS, datum);
|
});
|
||||||
return (Void) null;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,5 +33,4 @@ public interface UUIDGenerator {
|
||||||
default UUID generateV5WithX500Namespace(String name) {
|
default UUID generateV5WithX500Namespace(String name) {
|
||||||
return generateV5(NAMESPACE_X500, name);
|
return generateV5(NAMESPACE_X500, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@ package ch.phoenixtechnologies.quarkus.commons.uuid;
|
||||||
import com.fasterxml.uuid.Generators;
|
import com.fasterxml.uuid.Generators;
|
||||||
import io.quarkus.arc.DefaultBean;
|
import io.quarkus.arc.DefaultBean;
|
||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -30,5 +29,4 @@ class UUIDGeneratorImpl implements UUIDGenerator {
|
||||||
public UUID generateV5(UUID namespace, String name) {
|
public UUID generateV5(UUID namespace, String name) {
|
||||||
return Generators.nameBasedGenerator(namespace).generate(name);
|
return Generators.nameBasedGenerator(namespace).generate(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,17 @@
|
||||||
package ch.phoenixtechnologies.quarkus.commons.uuid;
|
package ch.phoenixtechnologies.quarkus.commons.uuid;
|
||||||
|
|
||||||
import ch.phoenixtechnologies.quarkus.commons.uuid.UUIDGeneratorImpl;
|
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.stream.Stream;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.params.ParameterizedTest;
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
import org.junit.jupiter.params.provider.Arguments;
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
import org.junit.jupiter.params.provider.MethodSource;
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
|
||||||
import java.util.Random;
|
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
|
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
class UUIDGeneratorImplTest {
|
class UUIDGeneratorImplTest {
|
||||||
|
|
||||||
|
@ -44,9 +42,7 @@ class UUIDGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateV4(getRandom());
|
var actual = generator.generateV4(getRandom());
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(expected);
|
||||||
.as("Generated UUID should match expected value")
|
|
||||||
.isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -55,9 +51,7 @@ class UUIDGeneratorImplTest {
|
||||||
|
|
||||||
var actual = generator.generateV5("test");
|
var actual = generator.generateV5("test");
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(expected);
|
||||||
.as("Generated UUID should match expected value")
|
|
||||||
.isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Stream<Arguments> generateV5WithNamespace() {
|
public static Stream<Arguments> generateV5WithNamespace() {
|
||||||
|
@ -65,8 +59,7 @@ class UUIDGeneratorImplTest {
|
||||||
Arguments.of(NAMESPACE_DNS, V5_NAME, EXPECTED_V5_DNS),
|
Arguments.of(NAMESPACE_DNS, V5_NAME, EXPECTED_V5_DNS),
|
||||||
Arguments.of(NAMESPACE_URL, V5_NAME, EXPECTED_V5_URL),
|
Arguments.of(NAMESPACE_URL, V5_NAME, EXPECTED_V5_URL),
|
||||||
Arguments.of(NAMESPACE_OID, V5_NAME, EXPECTED_V5_OID),
|
Arguments.of(NAMESPACE_OID, V5_NAME, EXPECTED_V5_OID),
|
||||||
Arguments.of(NAMESPACE_X500, V5_NAME, EXPECTED_V5_X500)
|
Arguments.of(NAMESPACE_X500, V5_NAME, EXPECTED_V5_X500));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@MethodSource
|
@MethodSource
|
||||||
|
@ -74,27 +67,21 @@ class UUIDGeneratorImplTest {
|
||||||
void generateV5WithNamespace(UUID namespace, String name, UUID expected) {
|
void generateV5WithNamespace(UUID namespace, String name, UUID expected) {
|
||||||
var actual = generator.generateV5(namespace, name);
|
var actual = generator.generateV5(namespace, name);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(expected);
|
||||||
.as("Generated UUID should match expected value")
|
|
||||||
.isEqualTo(expected);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void generateV5WithDNSNamespace() {
|
void generateV5WithDNSNamespace() {
|
||||||
var actual = generator.generateV5WithDNSNamespace(V5_NAME);
|
var actual = generator.generateV5WithDNSNamespace(V5_NAME);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(EXPECTED_V5_DNS);
|
||||||
.as("Generated UUID should match expected value")
|
|
||||||
.isEqualTo(EXPECTED_V5_DNS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void generateV5WithURLNamespace() {
|
void generateV5WithURLNamespace() {
|
||||||
var actual = generator.generateV5WithURLNamespace(V5_NAME);
|
var actual = generator.generateV5WithURLNamespace(V5_NAME);
|
||||||
|
|
||||||
assertThat(actual)
|
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(EXPECTED_V5_URL);
|
||||||
.as("Generated UUID should match expected value")
|
|
||||||
.isEqualTo(EXPECTED_V5_URL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -114,5 +101,4 @@ class UUIDGeneratorImplTest {
|
||||||
private static Random getRandom() {
|
private static Random getRandom() {
|
||||||
return new Random(24353L);
|
return new Random(24353L);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue