From 604378844e1487158ec13e7b4d33a2dafe61a001 Mon Sep 17 00:00:00 2001 From: alexander Date: Sun, 10 Aug 2025 11:39:34 +0300 Subject: [PATCH 1/2] feat(greeting): Create the "Greeting" Feature --- .../features/greeting/GreetingController.java | 22 +++++++++++++++++++ .../features/greeting/GreetingService.java | 22 +++++++++++++++++++ .../GreetingServiceIntegrationTest.java | 19 +++++++++++----- 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java create mode 100644 src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java diff --git a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java new file mode 100644 index 0000000..e371374 --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java @@ -0,0 +1,22 @@ +package lv.ctco.springboottemplate.features.greeting; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.web.bind.annotation.*; + +@RestController +@RequestMapping("/api/greeting") +@Tag(name = "Greeting Controller", description = "Greeting endpoint") +public class GreetingController { + private final GreetingService greetingService; + + public GreetingController(GreetingService greetingService) { + this.greetingService = greetingService; + } + + @GetMapping + @Operation(summary = "Get greeting message") + public String getAllTodos() { + return greetingService.greet(); + } +} diff --git a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java new file mode 100644 index 0000000..d411889 --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java @@ -0,0 +1,22 @@ +package lv.ctco.springboottemplate.features.greeting; + +import lv.ctco.springboottemplate.features.todo.TodoService; +import org.springframework.stereotype.Service; + +@Service +public class GreetingService { + private final TodoService todoService; + + public GreetingService(TodoService todoService) { + this.todoService = todoService; + } + + public String greet() { + long openTasksCount = this.todoService.getAllTodos() + .stream() + .filter(task -> !task.completed()) + .count(); + + return String.format("Hello from Spring! You have %d open tasks.", openTasksCount); + } +} diff --git a/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java b/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java index eda5f13..34a77c9 100644 --- a/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java +++ b/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java @@ -1,11 +1,23 @@ package lv.ctco.springboottemplate.features.greeting; +import lv.ctco.springboottemplate.features.todo.Todo; +import lv.ctco.springboottemplate.features.todo.TodoRepository; import lv.ctco.springboottemplate.features.todo.TodoService; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; import org.springframework.test.context.TestConstructor; +import org.testcontainers.containers.MongoDBContainer; +import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + /** * Integration test for {@link GreetingService}. * @@ -15,14 +27,12 @@ *

Initially marked {@link Disabled} to be enabled by the developer after implementation. */ @SpringBootTest -@Disabled("Enable after implementing GreetingService using TodoService") @Testcontainers @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) class GreetingServiceIntegrationTest { - /* - - @Container static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:6.0.8"); + @Container + static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:6.0.8"); @DynamicPropertySource static void setProperties(DynamicPropertyRegistry registry) { @@ -94,5 +104,4 @@ void should_ignore_null_todos_or_null_completed_flags() { // then assertThat(message).contains("1 open task"); } - */ } From 6991e9e56deedeb0f817068c0c1df23b0fd64893 Mon Sep 17 00:00:00 2001 From: alexander Date: Wed, 20 Aug 2025 20:10:40 +0300 Subject: [PATCH 2/2] spotless --- .../features/greeting/GreetingController.java | 18 ++++++++--------- .../features/greeting/GreetingService.java | 20 +++++++++---------- .../GreetingServiceIntegrationTest.java | 12 +++++------ 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java index e371374..e80c6df 100644 --- a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java @@ -8,15 +8,15 @@ @RequestMapping("/api/greeting") @Tag(name = "Greeting Controller", description = "Greeting endpoint") public class GreetingController { - private final GreetingService greetingService; + private final GreetingService greetingService; - public GreetingController(GreetingService greetingService) { - this.greetingService = greetingService; - } + public GreetingController(GreetingService greetingService) { + this.greetingService = greetingService; + } - @GetMapping - @Operation(summary = "Get greeting message") - public String getAllTodos() { - return greetingService.greet(); - } + @GetMapping + @Operation(summary = "Get greeting message") + public String getAllTodos() { + return greetingService.greet(); + } } diff --git a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java index d411889..97a0c65 100644 --- a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java @@ -5,18 +5,16 @@ @Service public class GreetingService { - private final TodoService todoService; + private final TodoService todoService; - public GreetingService(TodoService todoService) { - this.todoService = todoService; - } + public GreetingService(TodoService todoService) { + this.todoService = todoService; + } - public String greet() { - long openTasksCount = this.todoService.getAllTodos() - .stream() - .filter(task -> !task.completed()) - .count(); + public String greet() { + long openTasksCount = + this.todoService.getAllTodos().stream().filter(task -> !task.completed()).count(); - return String.format("Hello from Spring! You have %d open tasks.", openTasksCount); - } + return String.format("Hello from Spring! You have %d open tasks.", openTasksCount); + } } diff --git a/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java b/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java index 34a77c9..70f17a7 100644 --- a/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java +++ b/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java @@ -1,11 +1,14 @@ package lv.ctco.springboottemplate.features.greeting; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; import lv.ctco.springboottemplate.features.todo.Todo; import lv.ctco.springboottemplate.features.todo.TodoRepository; import lv.ctco.springboottemplate.features.todo.TodoService; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.DynamicPropertySource; @@ -14,10 +17,6 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - /** * Integration test for {@link GreetingService}. * @@ -31,8 +30,7 @@ @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) class GreetingServiceIntegrationTest { - @Container - static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:6.0.8"); + @Container static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:6.0.8"); @DynamicPropertySource static void setProperties(DynamicPropertyRegistry registry) {