From 85e5cf51a5e1a5c3c71306d9d2fc1c8804516eca Mon Sep 17 00:00:00 2001 From: Sven Strittmatter Date: Fri, 2 Feb 2024 15:39:16 +0100 Subject: [PATCH] #23 Clean Code Signed-off-by: Sven Strittmatter --- .../service/UserProfileService.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/securecodebox/persistence/defectdojo/service/UserProfileService.java b/src/main/java/io/securecodebox/persistence/defectdojo/service/UserProfileService.java index 1ea96d46..2db18d77 100644 --- a/src/main/java/io/securecodebox/persistence/defectdojo/service/UserProfileService.java +++ b/src/main/java/io/securecodebox/persistence/defectdojo/service/UserProfileService.java @@ -13,7 +13,7 @@ import java.util.ArrayList; import java.util.List; -public class UserProfileService extends GenericDefectDojoService { +public final class UserProfileService extends GenericDefectDojoService { public UserProfileService(Config config) { super(config); @@ -31,16 +31,15 @@ protected Class getModelClass() { @Override protected PaginatedResult deserializeList(String response) throws JsonProcessingException { - // GenericDefectDojoService expects that the response from the defectdojo api is a list - // This endpoint returns a single object though, to not break the code this response gets converted to a defectdojo response - UserProfile userProfile = this.objectMapper.readValue(response, new TypeReference<>() { + /* GenericDefectDojoService expects that the response from the defectdojo api is a list. + * This endpoint returns a single object though, to not break the code this response + * gets converted to a defectdojo response. + */ + final var userProfile = this.objectMapper.readValue(response, new TypeReference() { }); - List userProfileList = new ArrayList<>(); - userProfileList.add(userProfile); - - PaginatedResult fakeResult = new PaginatedResult<>(); - fakeResult.setResults(userProfileList); - fakeResult.setCount(1); - return fakeResult; + final var result = new PaginatedResult(); + result.setResults(List.of(userProfile)); + result.setCount(1); + return result; } }