From 9a57eb591873ec3152018f42b20f744724f5a6af Mon Sep 17 00:00:00 2001 From: metaxiii <16118999+metaXIII@users.noreply.github.com> Date: Wed, 27 May 2026 15:00:41 +0200 Subject: [PATCH] fix: quality gate --- .github/workflows/maven.yaml | 4 -- .../src/main/java/com/metaxiii/fr/Main.java | 2 +- .../test/java/com/metaxiii/fr/MainTest.java | 5 +- .../java/com/metaxiii/fr/GuavaSetsTest.java | 6 +- .../test/java/com/metaxiii/fr/AppTest.java | 6 +- .../src/main/java/com/metaxiii/fr/App.java | 2 +- .../test/java/com/metaxiii/fr/AppTest.java | 2 +- .../src/main/java/com/metaxiii/fr/App.java | 53 +++++---------- .../test/java/com/metaxiii/fr/AppTest.java | 47 ++++--------- .../controller/PostController.java | 3 +- .../controller/ApiExceptionHandlerTest.java | 2 +- .../java/com/metaxiii/fr/GuavaCacheTest.java | 33 ++++++++-- .../java/com/metaxiii/fr/GuavaFileTest.java | 14 +--- .../src/main/java/com/metaxiii/fr/App.java | 8 ++- .../test/java/com/metaxiii/fr/AppTest.java | 66 +++++++++---------- .../src/main/java/com/metaxiii/fr/App.java | 2 +- .../test/java/com/metaxiii/fr/AppTest.java | 2 +- .../test/java/com/metaxiii/fr/AppTest.java | 9 --- .../java/{ => com/metaxiii/fr}/MainTest.java | 6 +- .../java/com/metaxiii/fr/model/HumanTest.java | 24 +++---- .../src/main/java/com/metaxiii/fr/Child.java | 8 ++- .../src/main/java/com/metaxiii/fr/Parent.java | 6 +- 22 files changed, 135 insertions(+), 175 deletions(-) rename partition list in java/src/test/java/{ => com/metaxiii/fr}/MainTest.java (96%) diff --git a/.github/workflows/maven.yaml b/.github/workflows/maven.yaml index 196e5641..89ab4eb6 100644 --- a/.github/workflows/maven.yaml +++ b/.github/workflows/maven.yaml @@ -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 diff --git a/CompletableFuture/src/main/java/com/metaxiii/fr/Main.java b/CompletableFuture/src/main/java/com/metaxiii/fr/Main.java index 568eb583..132b35f7 100644 --- a/CompletableFuture/src/main/java/com/metaxiii/fr/Main.java +++ b/CompletableFuture/src/main/java/com/metaxiii/fr/Main.java @@ -11,7 +11,7 @@ public Future calculateAsync() { try { Thread.sleep(500); // Simuler une tâche longue return "Hello"; - } catch (InterruptedException e) { + } catch (InterruptedException _) { Thread.currentThread().interrupt(); return null; } diff --git a/CompletableFuture/src/test/java/com/metaxiii/fr/MainTest.java b/CompletableFuture/src/test/java/com/metaxiii/fr/MainTest.java index e9058aa7..a279313f 100644 --- a/CompletableFuture/src/test/java/com/metaxiii/fr/MainTest.java +++ b/CompletableFuture/src/test/java/com/metaxiii/fr/MainTest.java @@ -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; @@ -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 @@ -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 diff --git a/Guava - Sets/src/test/java/com/metaxiii/fr/GuavaSetsTest.java b/Guava - Sets/src/test/java/com/metaxiii/fr/GuavaSetsTest.java index 4b7c4b1b..61cceac5 100644 --- a/Guava - Sets/src/test/java/com/metaxiii/fr/GuavaSetsTest.java +++ b/Guava - Sets/src/test/java/com/metaxiii/fr/GuavaSetsTest.java @@ -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; @@ -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 { @@ -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, String> func = input -> Joiner.on(" ").join(input); - final Iterable joined = result.stream().map(func).collect(Collectors.toList()); + final Iterable joined = result.stream().map(func).toList(); assertTrue(Sets.newHashSet(joined).containsAll(List.of("a c", "a d", "b c", "b d"))); } diff --git a/convert-org-w3c-dom-document-string/src/test/java/com/metaxiii/fr/AppTest.java b/convert-org-w3c-dom-document-string/src/test/java/com/metaxiii/fr/AppTest.java index 1d8d604d..a8c813df 100644 --- a/convert-org-w3c-dom-document-string/src/test/java/com/metaxiii/fr/AppTest.java +++ b/convert-org-w3c-dom-document-string/src/test/java/com/metaxiii/fr/AppTest.java @@ -1,4 +1,4 @@ -package com.metaxiii.fr; + package com.metaxiii.fr; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -7,14 +7,14 @@ class AppTest { - private static final String startXml = + private static final String START_XML = """ """; @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 diff --git a/count-number-unique/src/main/java/com/metaxiii/fr/App.java b/count-number-unique/src/main/java/com/metaxiii/fr/App.java index 1e5fb236..cdf81f3d 100644 --- a/count-number-unique/src/main/java/com/metaxiii/fr/App.java +++ b/count-number-unique/src/main/java/com/metaxiii/fr/App.java @@ -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"); } diff --git a/count-number-unique/src/test/java/com/metaxiii/fr/AppTest.java b/count-number-unique/src/test/java/com/metaxiii/fr/AppTest.java index 27105783..043c77e1 100644 --- a/count-number-unique/src/test/java/com/metaxiii/fr/AppTest.java +++ b/count-number-unique/src/test/java/com/metaxiii/fr/AppTest.java @@ -29,6 +29,6 @@ void itShouldCountWithStreamApi() { @Test void itShouldMain() { - assertDoesNotThrow(() -> App.main(new String[] {})); + assertDoesNotThrow(App::main); } } diff --git a/draw-random-hexadecimal-number/src/main/java/com/metaxiii/fr/App.java b/draw-random-hexadecimal-number/src/main/java/com/metaxiii/fr/App.java index 7d149628..20db79e2 100644 --- a/draw-random-hexadecimal-number/src/main/java/com/metaxiii/fr/App.java +++ b/draw-random-hexadecimal-number/src/main/java/com/metaxiii/fr/App.java @@ -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); - } } diff --git a/draw-random-hexadecimal-number/src/test/java/com/metaxiii/fr/AppTest.java b/draw-random-hexadecimal-number/src/test/java/com/metaxiii/fr/AppTest.java index e7f4797e..94f4f7f6 100644 --- a/draw-random-hexadecimal-number/src/test/java/com/metaxiii/fr/AppTest.java +++ b/draw-random-hexadecimal-number/src/test/java/com/metaxiii/fr/AppTest.java @@ -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; @@ -12,8 +11,6 @@ class AppTest { - private App app; - public static Stream argumentsProvider() { return Stream.of(Arguments.of(1, 256), Arguments.of(0, 1024)); } @@ -21,30 +18,23 @@ public static Stream argumentsProvider() { @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 @@ -52,7 +42,7 @@ void itShouldGenerateRandomHexWithCommonsMathRandomDataGenerator(final int len) void itShouldGenerateRandomHexWithCommonsMathRandomDataGeneratorNextIntWithRange( final int lower, final int upper) { assertThat( - app.generateRandomHexWithCommonsMathRandomDataGeneratorNextIntWithRange(lower, upper)) + App.generateRandomHexWithCommonsMathRandomDataGeneratorNextIntWithRange(lower, upper)) .isNotNull(); } @@ -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(); } } diff --git a/entity-dto-conversion-rest-api/src/main/java/com/metaxiii/fr/entitydtoconversionrestapi/controller/PostController.java b/entity-dto-conversion-rest-api/src/main/java/com/metaxiii/fr/entitydtoconversionrestapi/controller/PostController.java index 862992cb..a341b8b3 100644 --- a/entity-dto-conversion-rest-api/src/main/java/com/metaxiii/fr/entitydtoconversionrestapi/controller/PostController.java +++ b/entity-dto-conversion-rest-api/src/main/java/com/metaxiii/fr/entitydtoconversionrestapi/controller/PostController.java @@ -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 @@ -21,7 +20,7 @@ public class PostController { private final ModelMapper modelMapper; @GetMapping("{page}/{size}/{sortDir}/{sort}") - @ResponseBody + public List getPosts( @PathVariable("page") int page, @PathVariable("size") int size, diff --git a/error-handling-for-rest-with-spring/src/test/java/com/metaxiii/fr/errorhandlingforrestwithspring/controller/ApiExceptionHandlerTest.java b/error-handling-for-rest-with-spring/src/test/java/com/metaxiii/fr/errorhandlingforrestwithspring/controller/ApiExceptionHandlerTest.java index 5b8872e7..abcc2e58 100644 --- a/error-handling-for-rest-with-spring/src/test/java/com/metaxiii/fr/errorhandlingforrestwithspring/controller/ApiExceptionHandlerTest.java +++ b/error-handling-for-rest-with-spring/src/test/java/com/metaxiii/fr/errorhandlingforrestwithspring/controller/ApiExceptionHandlerTest.java @@ -17,7 +17,7 @@ class ApiExceptionHandlerTest { private ApiExceptionHandler apiExceptionHandler; @AfterEach - public void endEach() { + void endEach() { this.apiExceptionHandler = null; } diff --git a/guava cache/src/test/java/com/metaxiii/fr/GuavaCacheTest.java b/guava cache/src/test/java/com/metaxiii/fr/GuavaCacheTest.java index d98d9299..8606c163 100644 --- a/guava cache/src/test/java/com/metaxiii/fr/GuavaCacheTest.java +++ b/guava cache/src/test/java/com/metaxiii/fr/GuavaCacheTest.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import com.google.common.base.Ticker; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; @@ -15,6 +16,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,12 +27,12 @@ class GuavaCacheTest { private GuavaCache guavaCache; @BeforeEach - public void initAll() { + void initAll() { guavaCache = new GuavaCache(); } @AfterEach - public void endEach() { + void endEach() { guavaCache = null; } @@ -71,29 +74,33 @@ void whenCacheReachMaxWeight_thenEviction() { } @Test - void whenEntryIdle_thenEviction() throws InterruptedException { + void whenEntryIdle_thenEviction() { + final var ticker = new MutableTicker(); final var cache = CacheBuilder.newBuilder() + .ticker(ticker) .expireAfterAccess(Duration.ofMillis(2)) .build(guavaCache.getLoader()); cache.getUnchecked("hello"); assertEquals(1, cache.size()); cache.getUnchecked("hello"); - Thread.sleep(300); + ticker.advance(300, TimeUnit.MILLISECONDS); cache.getUnchecked("test"); assertEquals(1, cache.size()); assertNull(cache.getIfPresent("hello")); } @Test - void whenEntryLiveTimeExpire_thenEviction() throws InterruptedException { + void whenEntryLiveTimeExpire_thenEviction() { + final var ticker = new MutableTicker(); final var cache = CacheBuilder.newBuilder() + .ticker(ticker) .expireAfterWrite(Duration.ofMillis(2)) .build(guavaCache.getLoader()); cache.getUnchecked("hello"); assertEquals(1, cache.size()); - Thread.sleep(300); + ticker.advance(300, TimeUnit.MILLISECONDS); cache.getUnchecked("test"); assertEquals(1, cache.size()); assertNull(cache.getIfPresent("hello")); @@ -175,4 +182,18 @@ private String getSuffix(final String str) { } return str.substring(lastIndex + 1); } + + private static final class MutableTicker extends Ticker { + + private final AtomicLong nanos = new AtomicLong(); + + @Override + public long read() { + return nanos.get(); + } + + void advance(long time, TimeUnit unit) { + nanos.addAndGet(unit.toNanos(time)); + } + } } diff --git a/guava write and read from file/src/test/java/com/metaxiii/fr/GuavaFileTest.java b/guava write and read from file/src/test/java/com/metaxiii/fr/GuavaFileTest.java index 3e23a077..76ef45f0 100644 --- a/guava write and read from file/src/test/java/com/metaxiii/fr/GuavaFileTest.java +++ b/guava write and read from file/src/test/java/com/metaxiii/fr/GuavaFileTest.java @@ -22,12 +22,12 @@ class GuavaFileTest { private File file; @BeforeEach - public void init() { + void init() { file = new File("test.txt"); } @AfterEach - public void endEach() { + void endEach() { if (file.delete()) { System.out.println("file deleted"); } @@ -36,7 +36,6 @@ public void endEach() { @Test void whenWriteUsingFiles_thenWritten() throws IOException { final var expectedValue = "Hello world"; - final var file = new File("test.txt"); Files.write(expectedValue, file, Charsets.UTF_8); final var result = Files.toString(file, Charsets.UTF_8); assertEquals(expectedValue, result); @@ -71,15 +70,6 @@ void whenWriteUsingByteSink_thenWritten() throws IOException { assertEquals(expectedValue, result); } - @Test - void whenReadUsingFiles_thenRead() throws IOException { - final var expectedValue = "Hello world"; - ByteSink sink = Files.asByteSink(file); - sink.write(expectedValue.getBytes()); - final var result = Files.toString(file, Charsets.UTF_8); - assertEquals(expectedValue, result); - } - @Test void whenReadMultipleLinesUsingFiles_thenRead() throws IOException { final var names = Lists.newArrayList("John", "Jane", "Adam", "Tom"); diff --git a/initial-name/src/main/java/com/metaxiii/fr/App.java b/initial-name/src/main/java/com/metaxiii/fr/App.java index 43afc945..e0effd38 100644 --- a/initial-name/src/main/java/com/metaxiii/fr/App.java +++ b/initial-name/src/main/java/com/metaxiii/fr/App.java @@ -8,6 +8,8 @@ public class App { + private static final String ALPHABETIQUE_REGEX = "[a-zA-Z].*"; + String getInitialUsingLoop(final String name) { if (name == null || name.isEmpty()) { return ""; @@ -15,7 +17,7 @@ String getInitialUsingLoop(final String name) { final String[] parts = name.split("\\s+"); final StringBuilder initials = new StringBuilder(); for (final String part : parts) { - if (part.matches("[a-zA-Z].*")) { + if (part.matches(ALPHABETIQUE_REGEX)) { initials.append(part.charAt(0)); } } @@ -40,7 +42,7 @@ String getInitialUsingStreamsAPI(final String name) { return ""; } return Arrays.stream(name.split("\\s+")) - .filter(part -> part.matches("[a-zA-Z].*")) + .filter(part -> part.matches(ALPHABETIQUE_REGEX)) .map(part -> part.substring(0, 1)) .collect(Collectors.joining()) .toUpperCase(); @@ -54,7 +56,7 @@ String getInitialUsingStringTokenizer(final String name) { final StringBuilder initials = new StringBuilder(); while (tokenizer.hasMoreTokens()) { final String part = tokenizer.nextToken(); - if (part.matches("[a-zA-Z].*")) { + if (part.matches(ALPHABETIQUE_REGEX)) { initials.append(part.charAt(0)); } } diff --git a/initial-name/src/test/java/com/metaxiii/fr/AppTest.java b/initial-name/src/test/java/com/metaxiii/fr/AppTest.java index 4539890e..9b8f3479 100644 --- a/initial-name/src/test/java/com/metaxiii/fr/AppTest.java +++ b/initial-name/src/test/java/com/metaxiii/fr/AppTest.java @@ -11,20 +11,20 @@ class AppTest { private App app; @BeforeEach - public void beforeEach() { + void beforeEach() { app = new App(); } @ParameterizedTest @CsvSource({ - "John F Kennedy,JFK", - ",''", - "'',''", - "Not Correct 88text,NC", - "michael jackson,MJ", - "123,''", - "123 234A,''", - "1test 2test, ''", + "John F Kennedy,JFK", + ",''", + "'',''", + "Not Correct 88text,NC", + "michael jackson,MJ", + "123,''", + "123 234A,''", + "1test 2test, ''", }) void getInitialFromName_usingLoop(final String input, final String expected) { final String initial = app.getInitialUsingLoop(input); @@ -33,14 +33,14 @@ void getInitialFromName_usingLoop(final String input, final String expected) { @ParameterizedTest @CsvSource({ - "John F Kennedy,JFK", - ",''", - "'',''", - "Not Correct 88text,NC", - "michael jackson,MJ", - "123,''", - "123 234A,''", - "1test 2test, ''", + "John F Kennedy,JFK", + ",''", + "'',''", + "Not Correct 88text,NC", + "michael jackson,MJ", + "123,''", + "123 234A,''", + "1test 2test, ''", }) void getInitialUsingRegex(final String input, final String expected) { final String initial = app.getInitialUsingRegex(input); @@ -49,14 +49,14 @@ void getInitialUsingRegex(final String input, final String expected) { @ParameterizedTest @CsvSource({ - "John F Kennedy,JFK", - ",''", - "'',''", - "Not Correct 88text,NC", - "michael jackson,MJ", - "123,''", - "123 234A,''", - "1test 2test, ''", + "John F Kennedy,JFK", + ",''", + "'',''", + "Not Correct 88text,NC", + "michael jackson,MJ", + "123,''", + "123 234A,''", + "1test 2test, ''", }) void getInitialUsingStreamsAPI(final String input, final String expected) { final String initial = app.getInitialUsingStreamsAPI(input); @@ -65,14 +65,14 @@ void getInitialUsingStreamsAPI(final String input, final String expected) { @ParameterizedTest @CsvSource({ - "John F Kennedy,JFK", - ",''", - "'',''", - "Not Correct 88text,NC", - "michael jackson,MJ", - "123,''", - "123 234A,''", - "1test 2test, ''", + "John F Kennedy,JFK", + ",''", + "'',''", + "Not Correct 88text,NC", + "michael jackson,MJ", + "123,''", + "123 234A,''", + "1test 2test, ''", }) void getInitialUsingStringTokenizer(final String input, final String expected) { final String initial = app.getInitialUsingStringTokenizer(input); diff --git a/intro-jfreechart/src/main/java/com/metaxiii/fr/App.java b/intro-jfreechart/src/main/java/com/metaxiii/fr/App.java index 7d1ba096..f165b1ba 100644 --- a/intro-jfreechart/src/main/java/com/metaxiii/fr/App.java +++ b/intro-jfreechart/src/main/java/com/metaxiii/fr/App.java @@ -28,7 +28,7 @@ public class App { private static final String MONTH = "Month"; private static final String PROFIT = "Profit"; - public static void main(final String[] args) { + public static void main() { final DefaultCategoryDataset dataset = new DefaultCategoryDataset(); dataset.addValue(200, SALES, JANUARY); dataset.addValue(150, SALES, FEBRUARY); diff --git a/intro-jfreechart/src/test/java/com/metaxiii/fr/AppTest.java b/intro-jfreechart/src/test/java/com/metaxiii/fr/AppTest.java index 5fd1739c..a2947e87 100644 --- a/intro-jfreechart/src/test/java/com/metaxiii/fr/AppTest.java +++ b/intro-jfreechart/src/test/java/com/metaxiii/fr/AppTest.java @@ -8,6 +8,6 @@ class AppTest { @Test void itShouldApp() { - assertDoesNotThrow(() -> App.main(new String[] {})); + assertDoesNotThrow(App::main); } } diff --git a/open-html/src/test/java/com/metaxiii/fr/AppTest.java b/open-html/src/test/java/com/metaxiii/fr/AppTest.java index b10ee577..eaa010de 100644 --- a/open-html/src/test/java/com/metaxiii/fr/AppTest.java +++ b/open-html/src/test/java/com/metaxiii/fr/AppTest.java @@ -21,15 +21,6 @@ void beforeEach() throws Exception { absolutePath = file.getAbsolutePath(); } - // Test work but not passing on github actions - // @Test - // void givenHtmlFile_whenUsingDesktopClass_thenOpenFileInDefaultBrowser() - // throws IOException { - // final var htmlFile = new File(absolutePath); - // Desktop.getDesktop().browse(htmlFile.toURI()); - // assertTrue(true); - // } - @Test void givenHtmlFile_whenUsingProcessBuilder_thenOpenFileInDefaultBrowser() throws IOException { final ProcessBuilder pb; diff --git a/partition list in java/src/test/java/MainTest.java b/partition list in java/src/test/java/com/metaxiii/fr/MainTest.java similarity index 96% rename from partition list in java/src/test/java/MainTest.java rename to partition list in java/src/test/java/com/metaxiii/fr/MainTest.java index 3c1ab7c7..3520a7d8 100644 --- a/partition list in java/src/test/java/MainTest.java +++ b/partition list in java/src/test/java/com/metaxiii/fr/MainTest.java @@ -1,3 +1,5 @@ +package com.metaxiii.fr; + import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.common.collect.Iterables; @@ -66,7 +68,7 @@ void givenList_whenParitioningIntoSublistsUsingPartitionBy_thenCorrect() { } @Test - public final void givenList_whenParitioningIntoNSublistsUsingGroupingBy_thenCorrect() { + void givenList_whenParitioningIntoNSublistsUsingGroupingBy_thenCorrect() { List intList = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8); Map> groups = intList.stream().collect(Collectors.groupingBy(s -> (s - 1) / 3)); @@ -90,7 +92,7 @@ void givenList_whenSplittingBySeparator_thenCorrect() { List> subSets = IntStream.range(0, indexes.length - 1) .mapToObj(i -> intList.subList(indexes[i] + 1, indexes[i + 1])) - .collect(Collectors.toList()); + .toList(); List lastPartition = subSets.get(2); List expectedLastPartition = Lists.newArrayList(7, 8); assertEquals(3, subSets.size()); diff --git a/powerful_comparison_with_lambdas/src/test/java/com/metaxiii/fr/model/HumanTest.java b/powerful_comparison_with_lambdas/src/test/java/com/metaxiii/fr/model/HumanTest.java index 11a627f0..9aade2d0 100644 --- a/powerful_comparison_with_lambdas/src/test/java/com/metaxiii/fr/model/HumanTest.java +++ b/powerful_comparison_with_lambdas/src/test/java/com/metaxiii/fr/model/HumanTest.java @@ -14,7 +14,7 @@ class HumanTest { @Test - public void givenPreLambda_whenSortingEntitiesByName_thenCorrectlySorted() { + void givenPreLambda_whenSortingEntitiesByName_thenCorrectlySorted() { final ArrayList humans = new ArrayList<>(List.of(new Human("Sarah", 10), new Human("Jack", 12))); Collections.sort( @@ -29,35 +29,35 @@ public int compare(Human h1, Human h2) { } @Test - public void whenSortingEntitiesByName_thenCorrectlySorted() { + void whenSortingEntitiesByName_thenCorrectlySorted() { List humans = new ArrayList<>(List.of(new Human("Sarah", 10), new Human("Jack", 12))); humans.sort((Human h1, Human h2) -> h1.getName().compareTo(h2.getName())); assertEquals(humans.get(0), new Human("Jack", 12)); } @Test - public void givenLambdaShortForm_whenSortingEntitiesByName_thenCorrectlySorted() { + void givenLambdaShortForm_whenSortingEntitiesByName_thenCorrectlySorted() { List humans = new ArrayList<>(List.of(new Human("Sarah", 10), new Human("Jack", 12))); humans.sort((h1, h2) -> h1.getName().compareTo(h2.getName())); assertEquals(humans.get(0), new Human("Jack", 12)); } @Test - public void givenMethodDefinition_whenSortingEntitiesByNameThenAge_thenCorrectlySorted() { + void givenMethodDefinition_whenSortingEntitiesByNameThenAge_thenCorrectlySorted() { List humans = new ArrayList<>(List.of(new Human("Sarah", 10), new Human("Jack", 12))); humans.sort(Human::compareByNameThenAge); assertEquals(humans.get(0), new Human("Jack", 12)); } @Test - public void givenInstanceMethod_whenSortingEntitiesByName_thenCorrectlySorted() { + void givenInstanceMethod_whenSortingEntitiesByName_thenCorrectlySorted() { List humans = new ArrayList<>(List.of(new Human("Sarah", 10), new Human("Jack", 12))); Collections.sort(humans, Comparator.comparing(Human::getName)); assertEquals(humans.get(0), new Human("Jack", 12)); } @Test - public void whenSortingEntitiesByNameReversed_thenCorrectlySorted() { + void whenSortingEntitiesByNameReversed_thenCorrectlySorted() { List humans = new ArrayList<>(List.of(new Human("Sarah", 10), new Human("Jack", 12))); Comparator comparator = (h1, h2) -> h1.getName().compareTo(h2.getName()); humans.sort(comparator.reversed()); @@ -65,7 +65,7 @@ public void whenSortingEntitiesByNameReversed_thenCorrectlySorted() { } @Test - public void whenSortingEntitiesByNameThenAge_thenCorrectlySorted() { + void whenSortingEntitiesByNameThenAge_thenCorrectlySorted() { List humans = new ArrayList<>( List.of(new Human("Sarah", 10), new Human("Sarah", 10), new Human("Zack", 12))); @@ -81,7 +81,7 @@ public void whenSortingEntitiesByNameThenAge_thenCorrectlySorted() { } @Test - public void givenComposition_whenSortingEntitiesByNameThenAge_thenCorrectlySorted() { + void givenComposition_whenSortingEntitiesByNameThenAge_thenCorrectlySorted() { List humans = new ArrayList<>( List.of(new Human("Sarah", 10), new Human("Sarah", 12), new Human("Zack", 12))); @@ -138,7 +138,7 @@ void givenStreamComparatorOrdering_whenSortingEntitiesByNameReversed_thenCorrect } @Test - public void givenANullElement_whenSortingEntitiesByName_thenThrowsNPE() { + void givenANullElement_whenSortingEntitiesByName_thenThrowsNPE() { final var humans = new ArrayList(); humans.add(null); humans.add(new Human("Jack", 12)); @@ -150,7 +150,7 @@ public void givenANullElement_whenSortingEntitiesByName_thenThrowsNPE() { } @Test - public void givenANullElement_whenSortingEntitiesByNameManually_thenMovesTheNullToLast() { + void givenANullElement_whenSortingEntitiesByNameManually_thenMovesTheNullToLast() { final var humans = new ArrayList(); humans.add(null); humans.add(new Human("Jack", 12)); @@ -170,7 +170,7 @@ public void givenANullElement_whenSortingEntitiesByNameManually_thenMovesTheNull } @Test - public void givenANullElement_whenSortingEntitiesByName_thenMovesTheNullToLast() { + void givenANullElement_whenSortingEntitiesByName_thenMovesTheNullToLast() { final var humans = new ArrayList(); humans.add(null); humans.add(new Human("Jack", 12)); @@ -182,7 +182,7 @@ public void givenANullElement_whenSortingEntitiesByName_thenMovesTheNullToLast() } @Test - public void givenANullElement_whenSortingEntitiesByName_thenMovesTheNullToStart() { + void givenANullElement_whenSortingEntitiesByName_thenMovesTheNullToStart() { final var humans = new ArrayList(); humans.add(null); humans.add(new Human("Jack", 12)); diff --git a/statements_before_super/src/main/java/com/metaxiii/fr/Child.java b/statements_before_super/src/main/java/com/metaxiii/fr/Child.java index db9341a4..6dc0afdf 100644 --- a/statements_before_super/src/main/java/com/metaxiii/fr/Child.java +++ b/statements_before_super/src/main/java/com/metaxiii/fr/Child.java @@ -1,14 +1,18 @@ package com.metaxiii.fr; +import java.util.logging.Logger; + public class Child extends Parent { + private static final Logger LOGGER = Logger.getLogger(Child.class.getName()); + Child() { super(); - System.out.println("Child constructor"); + LOGGER.info("Child constructor"); additionalInitialization(); } private void additionalInitialization() { - System.out.println("Additional initialization in Child"); + LOGGER.info("Additional initialization in Child"); } } diff --git a/statements_before_super/src/main/java/com/metaxiii/fr/Parent.java b/statements_before_super/src/main/java/com/metaxiii/fr/Parent.java index cfe61523..89d699f4 100644 --- a/statements_before_super/src/main/java/com/metaxiii/fr/Parent.java +++ b/statements_before_super/src/main/java/com/metaxiii/fr/Parent.java @@ -1,8 +1,12 @@ package com.metaxiii.fr; +import java.util.logging.Logger; + public class Parent { + private static final Logger LOGGER = Logger.getLogger(Parent.class.getName()); + Parent() { - System.out.println("Parent constructor"); + LOGGER.info("Parent constructor"); } }