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

Reviewed-on: phoenix/quarkus-commons#21
This commit is contained in:
Jorge Bornhausen 2024-11-11 08:30:43 +00:00
commit 0c3a30138a
18 changed files with 113 additions and 155 deletions

25
pom.xml
View file

@ -24,6 +24,8 @@
<compiler-plugin.version>3.13.0</compiler-plugin.version>
<surefire-plugin.version>3.5.2</surefire-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.group-id>io.quarkus.platform</quarkus.platform.group-id>
@ -132,6 +134,29 @@
</systemPropertyVariables>
</configuration>
</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>
</build>
</project>

View file

@ -3,7 +3,6 @@ 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 {
@ -14,5 +13,4 @@ class ClockProducer {
Clock produceClock() {
return Clock.systemDefaultZone();
}
}

View file

@ -2,7 +2,6 @@ package ch.phoenixtechnologies.quarkus.commons.clock;
import io.quarkus.arc.DefaultBean;
import jakarta.enterprise.context.ApplicationScoped;
import java.time.Clock;
import java.time.Instant;

View file

@ -1,13 +1,11 @@
package ch.phoenixtechnologies.quarkus.commons.clock;
import static org.assertj.core.api.Assertions.assertThat;
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.*;
import org.junit.jupiter.api.Test;
@QuarkusTest
class ClockProducerTest {
@ -21,4 +19,4 @@ class ClockProducerTest {
.as("Produced clock's zone should match expected value")
.isEqualTo(Clock.systemDefaultZone().getZone());
}
}
}

View file

@ -1,17 +1,15 @@
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;
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
class ClockServiceImplTest {
@ -40,4 +38,4 @@ class ClockServiceImplTest {
.as("Instant should match expected value")
.isEqualTo(expected);
}
}
}

View file

@ -9,5 +9,4 @@ public interface JsonService {
<T> T fromJson(String json, Class<T> clazz);
<T> T fromJson(String json, TypeReference<T> typeReference);
}

View file

@ -30,10 +30,9 @@ class JsonServiceImpl implements JsonService {
try {
return objectMapper.readValue(json, clazz);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Unable to read object of class [" + clazz.getName()
+ "] from json String: " + json, e);
throw new IllegalArgumentException(
"Unable to read object of class [" + clazz.getName() + "] from json String: " + json, e);
}
}
@Override
@ -41,8 +40,10 @@ class JsonServiceImpl implements JsonService {
try {
return objectMapper.readValue(json, typeReference);
} catch (JsonProcessingException e) {
throw new IllegalArgumentException("Unable to read object of type [" + typeReference.getType().getTypeName()
+ "] from json String: " + json, e);
throw new IllegalArgumentException(
"Unable to read object of type [" + typeReference.getType().getTypeName() + "] from json String: "
+ json,
e);
}
}
}

View file

@ -1,24 +1,21 @@
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.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
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
JsonServiceImpl jsonService;
@ -29,9 +26,7 @@ class JsonServiceImplTest {
var actual = jsonService.toJson(new TestRecord("John Doe", 30));
assertThat(actual)
.as("Json should match expected value")
.isEqualTo(expected);
assertThat(actual).as("Json should match expected value").isEqualTo(expected);
}
@Test
@ -41,9 +36,7 @@ class JsonServiceImplTest {
var actual = jsonService.fromJson(json, TestRecord.class);
assertThat(actual)
.as("Deserialized object should match expected value")
.isEqualTo(expected);
assertThat(actual).as("Deserialized object should match expected value").isEqualTo(expected);
}
@Test
@ -53,7 +46,8 @@ class JsonServiceImplTest {
assertThatThrownBy(() -> jsonService.fromJson(json, TestRecord.class))
.as("Should throw IllegalArgumentException when input is invalid")
.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
@ -75,6 +69,7 @@ class JsonServiceImplTest {
assertThatThrownBy(() -> jsonService.fromJson(json, TYPE_REFERENCE))
.as("Should throw IllegalArgumentException when input is invalid")
.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\"}");
}
}
}

View file

@ -8,5 +8,4 @@ public interface MessageDigestConfiguration {
@WithDefault("SHA-256")
String defaultAlgorithm();
}

View file

@ -2,7 +2,6 @@ package ch.phoenixtechnologies.quarkus.commons.digest;
import io.quarkus.arc.DefaultBean;
import jakarta.enterprise.context.ApplicationScoped;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

View file

@ -1,37 +1,37 @@
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.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
class MessageDigestServiceImplTest {
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
MessageDigestServiceImpl service;
@Test
void getInstance() {
assertThat(service.getInstance())
.isInstanceOf(MessageDigest.class);
assertThat(service.getInstance()).isInstanceOf(MessageDigest.class);
}
@ParameterizedTest
@ValueSource(strings = {"SHA-256", "SHA-512", "MD5"})
void getInstanceWithAlgorithm(String algorithm) {
assertThat(service.getInstance(algorithm))
.isInstanceOf(MessageDigest.class);
assertThat(service.getInstance(algorithm)).isInstanceOf(MessageDigest.class);
}
@ParameterizedTest
@ -61,7 +61,6 @@ class MessageDigestServiceImplTest {
assertThat(service.digest(INPUT, StandardCharsets.UTF_8))
.as("Digest should match expected value")
.isEqualTo(EXPECTED_SHA256_DIGEST);
}
@Test
@ -78,4 +77,4 @@ class MessageDigestServiceImplTest {
.as("Digest should match expected value")
.isEqualTo(EXPECTED_SHA256_DIGEST);
}
}
}

View file

@ -2,7 +2,6 @@ package ch.phoenixtechnologies.quarkus.commons.random;
import io.quarkus.arc.DefaultBean;
import jakarta.enterprise.context.ApplicationScoped;
import java.math.BigInteger;
import java.util.Random;

View file

@ -2,7 +2,6 @@ package ch.phoenixtechnologies.quarkus.commons.random;
import io.quarkus.arc.DefaultBean;
import jakarta.enterprise.context.ApplicationScoped;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Random;
@ -19,6 +18,4 @@ class RandomProviderImpl implements RandomProvider {
throw new IllegalStateException("Unable to obtain strong SecureRandom instance", e);
}
}
}

View file

@ -1,15 +1,14 @@
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.mockito.InjectSpy;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.math.BigInteger;
import java.util.Random;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.Test;
@QuarkusTest
class RandomNumberGeneratorImplTest {
@ -26,9 +25,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateInt();
assertThat(actual)
.as("Generated int should match expected value")
.isEqualTo(-1305521323);
assertThat(actual).as("Generated int should match expected value").isEqualTo(-1305521323);
}
@Test
@ -37,9 +34,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateInt(40);
assertThat(actual)
.as("Generated int should match expected value")
.isEqualTo(26);
assertThat(actual).as("Generated int should match expected value").isEqualTo(26);
}
@Test
@ -48,21 +43,16 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateInt(1, 40);
assertThat(actual)
.as("Generated int should match expected value")
.isEqualTo(17);
assertThat(actual).as("Generated int should match expected value").isEqualTo(17);
}
@Test
void generateLong() {
when(provider.get()).thenReturn(getRandom());
var actual = generator.generateLong();
assertThat(actual)
.as("Generated long should match expected value")
.isEqualTo(-5607171386684657918L);
assertThat(actual).as("Generated long should match expected value").isEqualTo(-5607171386684657918L);
}
@Test
@ -71,9 +61,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateLong(40L);
assertThat(actual)
.as("Generated long should match expected value")
.isEqualTo(9L);
assertThat(actual).as("Generated long should match expected value").isEqualTo(9L);
}
@Test
@ -82,9 +70,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateLong(1L, 40L);
assertThat(actual)
.as("Generated long should match expected value")
.isEqualTo(23L);
assertThat(actual).as("Generated long should match expected value").isEqualTo(23L);
}
@Test
@ -93,9 +79,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateFloat();
assertThat(actual)
.as("Generated float should match expected value")
.isEqualTo(0.6960346f);
assertThat(actual).as("Generated float should match expected value").isEqualTo(0.6960346f);
}
@Test
@ -104,9 +88,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateFloat(0.99f);
assertThat(actual)
.as("Generated float should match expected value")
.isEqualTo(0.6890743f);
assertThat(actual).as("Generated float should match expected value").isEqualTo(0.6890743f);
}
@Test
@ -115,9 +97,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateFloat(0.01f, 0.99f);
assertThat(actual)
.as("Generated float should match expected value")
.isEqualTo(0.69211394f);
assertThat(actual).as("Generated float should match expected value").isEqualTo(0.69211394f);
}
@Test
@ -126,9 +106,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateDouble();
assertThat(actual)
.as("Generated double should match expected value")
.isEqualTo(0.6960346394874213d);
assertThat(actual).as("Generated double should match expected value").isEqualTo(0.6960346394874213d);
}
@Test
@ -137,9 +115,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateDouble(0.99d);
assertThat(actual)
.as("Generated double should match expected value")
.isEqualTo(0.6890742930925471d);
assertThat(actual).as("Generated double should match expected value").isEqualTo(0.6890742930925471d);
}
@Test
@ -148,9 +124,7 @@ class RandomNumberGeneratorImplTest {
var actual = generator.generateDouble(0.01d, 0.99d);
assertThat(actual)
.as("Generated double should match expected value")
.isEqualTo(0.6921139466976729d);
assertThat(actual).as("Generated double should match expected value").isEqualTo(0.6921139466976729d);
}
@Test
@ -176,5 +150,4 @@ class RandomNumberGeneratorImplTest {
private static Random getRandom() {
return new Random(24353L);
}
}
}

View file

@ -1,16 +1,15 @@
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 jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.SecureRandom;
import java.security.Security;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.junit.jupiter.api.Test;
@QuarkusTest
@SuppressWarnings("removal")
@ -47,16 +46,13 @@ class RandomProviderImplTest {
private static String getSecurityProperty() {
return AccessController.doPrivileged(
(PrivilegedAction<String>) () -> Security.getProperty(
SECURE_RANDOM_STRONG_ALGORITHMS));
(PrivilegedAction<String>) () -> Security.getProperty(SECURE_RANDOM_STRONG_ALGORITHMS));
}
private static void setSecurityProperty(String datum) {
AccessController.doPrivileged(
(PrivilegedAction<Void>) () -> {
Security.setProperty(
SECURE_RANDOM_STRONG_ALGORITHMS, datum);
return (Void) null;
});
AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
Security.setProperty(SECURE_RANDOM_STRONG_ALGORITHMS, datum);
return (Void) null;
});
}
}
}

View file

@ -33,5 +33,4 @@ public interface UUIDGenerator {
default UUID generateV5WithX500Namespace(String name) {
return generateV5(NAMESPACE_X500, name);
}
}

View file

@ -3,7 +3,6 @@ package ch.phoenixtechnologies.quarkus.commons.uuid;
import com.fasterxml.uuid.Generators;
import io.quarkus.arc.DefaultBean;
import jakarta.enterprise.context.ApplicationScoped;
import java.util.Random;
import java.util.UUID;
@ -30,5 +29,4 @@ class UUIDGeneratorImpl implements UUIDGenerator {
public UUID generateV5(UUID namespace, String name) {
return Generators.nameBasedGenerator(namespace).generate(name);
}
}

View file

@ -1,19 +1,17 @@
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 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.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
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
class UUIDGeneratorImplTest {
@ -44,9 +42,7 @@ class UUIDGeneratorImplTest {
var actual = generator.generateV4(getRandom());
assertThat(actual)
.as("Generated UUID should match expected value")
.isEqualTo(expected);
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(expected);
}
@Test
@ -55,9 +51,7 @@ class UUIDGeneratorImplTest {
var actual = generator.generateV5("test");
assertThat(actual)
.as("Generated UUID should match expected value")
.isEqualTo(expected);
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(expected);
}
public static Stream<Arguments> generateV5WithNamespace() {
@ -65,8 +59,7 @@ class UUIDGeneratorImplTest {
Arguments.of(NAMESPACE_DNS, V5_NAME, EXPECTED_V5_DNS),
Arguments.of(NAMESPACE_URL, V5_NAME, EXPECTED_V5_URL),
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
@ -74,27 +67,21 @@ class UUIDGeneratorImplTest {
void generateV5WithNamespace(UUID namespace, String name, UUID expected) {
var actual = generator.generateV5(namespace, name);
assertThat(actual)
.as("Generated UUID should match expected value")
.isEqualTo(expected);
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(expected);
}
@Test
void generateV5WithDNSNamespace() {
var actual = generator.generateV5WithDNSNamespace(V5_NAME);
assertThat(actual)
.as("Generated UUID should match expected value")
.isEqualTo(EXPECTED_V5_DNS);
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(EXPECTED_V5_DNS);
}
@Test
void generateV5WithURLNamespace() {
var actual = generator.generateV5WithURLNamespace(V5_NAME);
assertThat(actual)
.as("Generated UUID should match expected value")
.isEqualTo(EXPECTED_V5_URL);
assertThat(actual).as("Generated UUID should match expected value").isEqualTo(EXPECTED_V5_URL);
}
@Test
@ -114,5 +101,4 @@ class UUIDGeneratorImplTest {
private static Random getRandom() {
return new Random(24353L);
}
}
}