From 2b1732b545207e19d15299667754dd486299e924 Mon Sep 17 00:00:00 2001 From: ViktorDolzenko Date: Mon, 16 Feb 2026 13:29:34 +0200 Subject: [PATCH 1/3] Greeting task --- .../features/greeting/GreetingController.java | 25 +++++++++++++++++++ .../features/greeting/GreetingService.java | 22 ++++++++++++++++ .../GreetingServiceIntegrationTest.java | 18 ++++++++++--- 3 files changed, 61 insertions(+), 4 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..0f7f163 --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java @@ -0,0 +1,25 @@ +package lv.ctco.springboottemplate.features.greeting; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; + +@RestController +@RequestMapping("/api/greeting") +@Tag(name = "Greeting Controller", description = "Greeting management endpoints") + +public class GreetingController { + private final GreetingService greetingService; + + public GreetingController(GreetingService greetingService) { + this.greetingService = greetingService; + } + + @GetMapping + @Operation(summary = "Get greeting") + public String getGreeting() { + 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..6869efa --- /dev/null +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java @@ -0,0 +1,22 @@ +package lv.ctco.springboottemplate.features.greeting; + +import org.springframework.stereotype.Service; +import lv.ctco.springboottemplate.features.todo.TodoService; + +@Service +public class GreetingService { + + private final TodoService todoService; + + public GreetingService(TodoService todoService) { + this.todoService = todoService; + } + + public String greet() { + long openTasks = todoService.getAllTodos().stream().filter(todo -> !todo.completed()).count(); + + String suffix = openTasks == 1 ? "task" : "tasks"; + + return "Hello from Spring! You have " + openTasks + " open " + suffix + "."; + } + } \ No newline at end of file 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..05200aa 100644 --- a/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java +++ b/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java @@ -1,9 +1,21 @@ package lv.ctco.springboottemplate.features.greeting; +import static org.assertj.core.api.Assertions.assertThat; + +import java.util.List; + +import lv.ctco.springboottemplate.features.greeting.GreetingService; +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.Disabled; +import org.junit.jupiter.api.BeforeEach; +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; import org.springframework.test.context.TestConstructor; +import org.testcontainers.containers.MongoDBContainer; +import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; /** @@ -15,12 +27,11 @@ *

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"); @@ -94,5 +105,4 @@ void should_ignore_null_todos_or_null_completed_flags() { // then assertThat(message).contains("1 open task"); } - */ } From 43e66f4c597c7ac469c64a1d065f607b0db09db8 Mon Sep 17 00:00:00 2001 From: ViktorDolzenko Date: Tue, 17 Feb 2026 10:31:30 +0200 Subject: [PATCH 2/3] spotlessApply --- .../features/greeting/GreetingController.java | 23 ++++++++-------- .../features/greeting/GreetingService.java | 26 +++++++++---------- .../GreetingServiceIntegrationTest.java | 4 --- 3 files changed, 24 insertions(+), 29 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 0f7f163..a1c6f93 100644 --- a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingController.java @@ -1,25 +1,24 @@ 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.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Operation; @RestController @RequestMapping("/api/greeting") @Tag(name = "Greeting Controller", description = "Greeting management endpoints") - 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") - public String getGreeting() { - return greetingService.greet(); - } + @GetMapping + @Operation(summary = "Get greeting") + public String getGreeting() { + 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 6869efa..ff2cb60 100644 --- a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java @@ -1,22 +1,22 @@ package lv.ctco.springboottemplate.features.greeting; -import org.springframework.stereotype.Service; import lv.ctco.springboottemplate.features.todo.TodoService; +import org.springframework.stereotype.Service; -@Service -public class GreetingService { +@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 openTasks = todoService.getAllTodos().stream().filter(todo -> !todo.completed()).count(); + public String greet() { + long openTasks = todoService.getAllTodos().stream().filter(todo -> !todo.completed()).count(); - String suffix = openTasks == 1 ? "task" : "tasks"; + String suffix = openTasks == 1 ? "task" : "tasks"; - return "Hello from Spring! You have " + openTasks + " open " + suffix + "."; - } - } \ No newline at end of file + return "Hello from Spring! You have " + openTasks + " open " + suffix + "."; + } +} 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 05200aa..0a5be73 100644 --- a/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java +++ b/src/test/java/lv/ctco/springboottemplate/features/greeting/GreetingServiceIntegrationTest.java @@ -3,8 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.List; - -import lv.ctco.springboottemplate.features.greeting.GreetingService; import lv.ctco.springboottemplate.features.todo.Todo; import lv.ctco.springboottemplate.features.todo.TodoRepository; import lv.ctco.springboottemplate.features.todo.TodoService; @@ -31,8 +29,6 @@ @TestConstructor(autowireMode = TestConstructor.AutowireMode.ALL) class GreetingServiceIntegrationTest { - - @Container static MongoDBContainer mongoDBContainer = new MongoDBContainer("mongo:6.0.8"); @DynamicPropertySource From 02922ccaae52a2c7de56e6e9076bf9f8b83a4444 Mon Sep 17 00:00:00 2001 From: ViktorDolzenko Date: Tue, 17 Feb 2026 13:45:40 +0200 Subject: [PATCH 3/3] Changed to concatination for string.format --- .../springboottemplate/features/greeting/GreetingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ff2cb60..0a194da 100644 --- a/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java +++ b/src/main/java/lv/ctco/springboottemplate/features/greeting/GreetingService.java @@ -17,6 +17,6 @@ public String greet() { String suffix = openTasks == 1 ? "task" : "tasks"; - return "Hello from Spring! You have " + openTasks + " open " + suffix + "."; + return String.format("Hello from Spring! You have %d open %s.", openTasks, suffix); } }