Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- run: |
echo "Environment: $ENVIRONMENT"
env:
ENVIRONMENT: ${{ inputs.environment }}
- uses: actions/checkout@v6
with:
fetch-depth: 0
Expand Down
2 changes: 1 addition & 1 deletion CompletableFuture/src/main/java/com/metaxiii/fr/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public Future<String> calculateAsync() {
try {
Thread.sleep(500); // Simuler une tâche longue
return "Hello";
} catch (InterruptedException e) {
} catch (InterruptedException _) {
Thread.currentThread().interrupt();
return null;
}
Expand Down
5 changes: 3 additions & 2 deletions CompletableFuture/src/test/java/com/metaxiii/fr/MainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;
Expand All @@ -36,7 +37,7 @@ void whenAddingThenAcceptToFuture_thenFunctionExecutesAfterComputationIsFinished
final var completableFuture = CompletableFuture.supplyAsync(() -> "Hello");
final var future =
completableFuture.thenAccept(s -> System.out.println("Computation returned: " + s));
assertDoesNotThrow(() -> future.get());
assertDoesNotThrow((Executable) future::get);
}

@Test
Expand Down Expand Up @@ -64,7 +65,7 @@ void whenAddingThenApplyToFuture_thenFunctionExecutesAfterComputationIsFinished(
void whenAddingThenRunToFuture_thenFunctionExecutesAfterComputationIsFinished() {
final var completableFuture = CompletableFuture.supplyAsync(() -> "Hello");
final var future = completableFuture.thenRun(() -> System.out.println("Computation finished."));
assertDoesNotThrow(() -> future.get());
assertDoesNotThrow((Executable) future::get);
}

@Test
Expand Down
6 changes: 2 additions & 4 deletions Guava - Sets/src/test/java/com/metaxiii/fr/GuavaSetsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.google.common.collect.ContiguousSet;
import com.google.common.collect.DiscreteDomain;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Lists;
import com.google.common.collect.Multiset;
Expand All @@ -17,7 +16,6 @@
import com.google.common.collect.TreeRangeSet;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;

class GuavaSetsTest {
Expand All @@ -26,10 +24,10 @@ class GuavaSetsTest {
void whenCalculatingCartesianProductOfSets_thenCorrect() {
final var first = ImmutableSet.of('a', 'b');
final var second = ImmutableSet.of('c', 'd');
final var result = Sets.cartesianProduct(ImmutableList.of(first, second));
final var result = Sets.cartesianProduct(List.of(first, second));

final Function<List<Character>, String> func = input -> Joiner.on(" ").join(input);
final Iterable<String> joined = result.stream().map(func).collect(Collectors.toList());
final Iterable<String> joined = result.stream().map(func).toList();
assertTrue(Sets.newHashSet(joined).containsAll(List.of("a c", "a d", "b c", "b d")));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.metaxiii.fr;
package com.metaxiii.fr;

import static org.junit.jupiter.api.Assertions.assertEquals;

Expand All @@ -7,14 +7,14 @@

class AppTest {

private static final String startXml =
private static final String START_XML =
"""
<?xml version="1.0" encoding="UTF-8" standalone="no"?>""";

@Test
void givenXMLDocument_thenConvertToStringSuccessfully() throws Exception {
final Document document = App.getDocument();
assertEquals(startXml + App.FRUIT_XML, App.toString(document));
assertEquals(START_XML + App.FRUIT_XML, App.toString(document));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion count-number-unique/src/main/java/com/metaxiii/fr/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class App {

private static final Logger LOGGER = Logger.getLogger(App.class.getName());

public static void main(final String[] args) {
public static void main() {
LOGGER.info("Hello world");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ void itShouldCountWithStreamApi() {

@Test
void itShouldMain() {
assertDoesNotThrow(() -> App.main(new String[] {}));
assertDoesNotThrow(App::main);
}
}
Original file line number Diff line number Diff line change
@@ -1,79 +1,56 @@
package com.metaxiii.fr;

import java.security.SecureRandom;
import java.util.Random;
import org.apache.commons.math3.random.RandomDataGenerator;

public class App {
public final class App {

String generateRandomHexUsingRandomNextIntWithInRange(final int lower, final int upper) {
final var random = getRandom();
final var randomInt = random.nextInt(upper - lower) + lower;
return Integer.toHexString(randomInt);
}
private static final SecureRandom SECURE_RANDOM = new SecureRandom();

@SuppressWarnings({"java:S2245"})
private static Random getRandom() {
return new Random();
private App() {
}

String generateRandomHexUsingSecureRandomNextInt() {
final var secureRandom = new SecureRandom();
final var randomInt = secureRandom.nextInt();
public static String generateRandomHexUsingRandomNextIntWithInRange(final int lower, final int upper) {
final var randomInt = SECURE_RANDOM.nextInt(upper - lower) + lower;
return Integer.toHexString(randomInt);
}

String generateRandomHexUsingSecureRandomNextIntWithInRange(final int lower, final int upper) {
final var secureRandom = new SecureRandom();
final var randomInt = secureRandom.nextInt(upper - lower) + lower;
public static String generateRandomHexUsingSecureRandomNextInt() {
final var randomInt = SECURE_RANDOM.nextInt();
return Integer.toHexString(randomInt);
}

String generateRandomHexUsingSecureRandomNextLong() {
final var secureRandom = new SecureRandom();
final var randomLong = secureRandom.nextLong();
public static String generateRandomHexUsingSecureRandomNextLong() {
final var randomLong = SECURE_RANDOM.nextLong();
return Long.toHexString(randomLong);
}

String generateRandomHexWithCommonsMathRandomDataGenerator(final int len) {
public static String generateRandomHexWithCommonsMathRandomDataGenerator(final int len) {
final var randomDataGenerator = new RandomDataGenerator();
return randomDataGenerator.nextHexString(len);
}

String generateRandomHexWithCommonsMathRandomDataGeneratorNextIntWithRange(
public static String generateRandomHexWithCommonsMathRandomDataGeneratorNextIntWithRange(
final int lower, final int upper) {
final var randomDataGenerator = new RandomDataGenerator();
final var randomInt = randomDataGenerator.nextInt(lower, upper);
return Integer.toHexString(randomInt);
}

String generateRandomHexWithCommonsMathRandomDataGeneratorSecureNextIntWithRange(
public static String generateRandomHexWithCommonsMathRandomDataGeneratorSecureNextIntWithRange(
final int lower, final int upper) {
final var randomDataGenerator = new RandomDataGenerator();
final var randomInt = randomDataGenerator.nextSecureInt(lower, upper);
return Integer.toHexString(randomInt);
}

String generateRandomHexWithStringFormatter() {
final var random = getRandom();
final var randomInt = random.nextInt();
public static String generateRandomHexWithStringFormatter() {
final var randomInt = SECURE_RANDOM.nextInt();
return String.format("%02x", randomInt);
}

String generateSecureRandomHexWithCommonsMathRandomDataGenerator(final int len) {
public static String generateSecureRandomHexWithCommonsMathRandomDataGenerator(final int len) {
final var randomDataGenerator = new RandomDataGenerator();
return randomDataGenerator.nextSecureHexString(len);
}

String generateUnboundedRandomHexUsingRandomNextInt() {
final var random = getRandom();
final var randomInt = random.nextInt();
return Integer.toHexString(randomInt);
}

String generateUnboundedRandomHexUsingRandomNextLong() {
final var random = getRandom();
final var randomLong = random.nextLong();
return Long.toHexString(randomLong);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
Expand All @@ -12,47 +11,38 @@

class AppTest {

private App app;

public static Stream<Arguments> argumentsProvider() {
return Stream.of(Arguments.of(1, 256), Arguments.of(0, 1024));
}

@ParameterizedTest
@MethodSource(value = "argumentsProvider")
void itShouldGenerateRandomHexUsingRandomNextIntWithInRange(final int lower, final int upper) {
assertThat(app.generateRandomHexUsingRandomNextIntWithInRange(lower, upper)).isNotNull();
assertThat(App.generateRandomHexUsingRandomNextIntWithInRange(lower, upper)).isNotNull();
}

@Test
void itShouldGenerateRandomHexUsingSecureRandomNextInt() {
assertThat(app.generateRandomHexUsingSecureRandomNextInt()).isNotNull();
}

@ParameterizedTest
@MethodSource(value = "argumentsProvider")
void itShouldGenerateRandomHexUsingSecureRandomNextIntWithInRange(
final int lower, final int upper) {
assertThat(app.generateRandomHexUsingSecureRandomNextIntWithInRange(lower, upper)).isNotNull();
assertThat(App.generateRandomHexUsingSecureRandomNextInt()).isNotNull();
}

@Test
void itShouldGenerateRandomHexUsingSecureRandomNextLong() {
assertThat(app.generateRandomHexUsingSecureRandomNextLong()).isNotNull();
assertThat(App.generateRandomHexUsingSecureRandomNextLong()).isNotNull();
}

@ParameterizedTest
@ValueSource(ints = {1, 2, 3, 4, 5, 6, 7, 8, 9})
@ValueSource(ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9 })
void itShouldGenerateRandomHexWithCommonsMathRandomDataGenerator(final int len) {
assertThat(app.generateRandomHexWithCommonsMathRandomDataGenerator(len)).isNotNull();
assertThat(App.generateRandomHexWithCommonsMathRandomDataGenerator(len)).isNotNull();
}

@ParameterizedTest
@MethodSource(value = "argumentsProvider")
void itShouldGenerateRandomHexWithCommonsMathRandomDataGeneratorNextIntWithRange(
final int lower, final int upper) {
assertThat(
app.generateRandomHexWithCommonsMathRandomDataGeneratorNextIntWithRange(lower, upper))
App.generateRandomHexWithCommonsMathRandomDataGeneratorNextIntWithRange(lower, upper))
.isNotNull();
}

Expand All @@ -61,34 +51,19 @@ void itShouldGenerateRandomHexWithCommonsMathRandomDataGeneratorNextIntWithRange
void itShouldGenerateRandomHexWithCommonsMathRandomDataGeneratorSecureNextIntWithRange(
final int lower, final int upper) {
assertThat(
app.generateRandomHexWithCommonsMathRandomDataGeneratorSecureNextIntWithRange(
lower, upper))
App.generateRandomHexWithCommonsMathRandomDataGeneratorSecureNextIntWithRange(
lower, upper))
.isNotNull();
}

@Test
void itShouldGenerateRandomHexWithStringFormatter() {
assertThat(app.generateRandomHexWithStringFormatter()).isNotNull();
assertThat(App.generateRandomHexWithStringFormatter()).isNotNull();
}

@ParameterizedTest
@ValueSource(ints = {1, 2, 3, 4, 5, 6, 7, 8, 9})
@ValueSource(ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9 })
void itShouldGenerateSecureRandomHexWithCommonsMathRandomDataGenerator(final int len) {
assertThat(app.generateSecureRandomHexWithCommonsMathRandomDataGenerator(len)).isNotNull();
}

@Test
void itShouldGenerateUnboundedRandomHexUsingRandomNextInt() {
assertThat(app.generateUnboundedRandomHexUsingRandomNextInt()).isNotNull();
}

@Test
void itShouldGenerateUnboundedRandomHexUsingRandomNextLong() {
assertThat(app.generateUnboundedRandomHexUsingRandomNextLong()).isNotNull();
}

@BeforeEach
void setUp() {
app = new App();
assertThat(App.generateSecureRandomHexWithCommonsMathRandomDataGenerator(len)).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.modelmapper.ModelMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
Expand All @@ -21,7 +20,7 @@ public class PostController {
private final ModelMapper modelMapper;

@GetMapping("{page}/{size}/{sortDir}/{sort}")
@ResponseBody

public List<PostDto> getPosts(
@PathVariable("page") int page,
@PathVariable("size") int size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApiExceptionHandlerTest {
private ApiExceptionHandler apiExceptionHandler;

@AfterEach
public void endEach() {
void endEach() {
this.apiExceptionHandler = null;
}

Expand Down
Loading