refactor: Removed Interface `ChatHomeService`
authorKai Moritz <kai@juplo.de>
Mon, 21 Aug 2023 16:25:20 +0000 (18:25 +0200)
committerKai Moritz <kai@juplo.de>
Mon, 21 Aug 2023 18:39:30 +0000 (20:39 +0200)
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ChatHomeService.java [deleted file]
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/InMemoryChatHomeService.java
src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHome.java
src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractInMemoryStorageIT.java
src/test/java/de/juplo/kafka/chat/backend/persistence/AbstractStorageStrategyIT.java
src/test/java/de/juplo/kafka/chat/backend/persistence/inmemory/SimpleChatHomeTest.java

diff --git a/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ChatHomeService.java b/src/main/java/de/juplo/kafka/chat/backend/persistence/inmemory/ChatHomeService.java
deleted file mode 100644 (file)
index f47e017..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-package de.juplo.kafka.chat.backend.persistence.inmemory;
-
-import de.juplo.kafka.chat.backend.domain.ChatRoom;
-import reactor.core.publisher.Flux;
-import reactor.core.publisher.Mono;
-
-import java.util.UUID;
-
-
-public interface ChatHomeService
-{
-  Mono<ChatRoom> getChatRoom(int shard, UUID id);
-  Flux<ChatRoom> getChatRooms(int shard);
-}
index 381f5db..1334124 100644 (file)
@@ -9,7 +9,7 @@ import java.util.*;
 
 
 @Slf4j
-public class InMemoryChatHomeService implements ChatHomeService
+public class InMemoryChatHomeService
 {
   private final Map<UUID, ChatRoom>[] chatrooms;
 
@@ -55,13 +55,11 @@ public class InMemoryChatHomeService implements ChatHomeService
     chatrooms[chatRoom.getShard()].put(chatRoom.getId(), chatRoom);
   }
 
-  @Override
   public Mono<ChatRoom> getChatRoom(int shard, UUID id)
   {
     return Mono.justOrEmpty(chatrooms[shard].get(id));
   }
 
-  @Override
   public Flux<ChatRoom> getChatRooms(int shard)
   {
     return Flux.fromStream(chatrooms[shard].values().stream());
index bdca9b7..e35a661 100644 (file)
@@ -13,18 +13,18 @@ import java.util.*;
 @Slf4j
 public class SimpleChatHome implements ChatHome
 {
-  private final ChatHomeService service;
+  private final InMemoryChatHomeService service;
   private final int shard;
 
 
-  public SimpleChatHome(ChatHomeService service, int shard)
+  public SimpleChatHome(InMemoryChatHomeService service, int shard)
   {
     log.info("Created SimpleChatHome for shard {}", shard);
     this.service = service;
     this.shard = shard;
   }
 
-  public SimpleChatHome(ChatHomeService service)
+  public SimpleChatHome(InMemoryChatHomeService service)
   {
     this(service, 0);
   }
index a4defeb..bff02a3 100644 (file)
@@ -1,9 +1,10 @@
 package de.juplo.kafka.chat.backend.persistence;
 
-import de.juplo.kafka.chat.backend.persistence.inmemory.ChatHomeService;
+import de.juplo.kafka.chat.backend.domain.ChatHome;
 import de.juplo.kafka.chat.backend.domain.ChatRoomFactory;
 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomFactory;
+import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 
@@ -21,21 +22,23 @@ public abstract class AbstractInMemoryStorageIT extends AbstractStorageStrategyI
   {
     return new StorageStrategyITConfig()
     {
-      InMemoryChatHomeService chatHomeService = new InMemoryChatHomeService(
+      InMemoryChatHomeService inMemoryChatHomeService = new InMemoryChatHomeService(
           1,
           new int[] { 0 },
           getStorageStrategy().read());
 
+      SimpleChatHome simpleChatHome = new SimpleChatHome(inMemoryChatHomeService);
+
       InMemoryChatRoomFactory chatRoomFactory = new InMemoryChatRoomFactory(
-          chatHomeService,
+          inMemoryChatHomeService,
           chatRoomId -> 0,
           clock,
           8);
 
       @Override
-      public ChatHomeService getChatHomeService()
+      public ChatHome getChatHome()
       {
-        return chatHomeService;
+        return simpleChatHome;
       }
 
       @Override
index 1373cf0..58acb19 100644 (file)
@@ -1,8 +1,6 @@
 package de.juplo.kafka.chat.backend.persistence;
 
 import de.juplo.kafka.chat.backend.domain.*;
-import de.juplo.kafka.chat.backend.persistence.inmemory.ChatHomeService;
-import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.jupiter.api.Test;
 
@@ -25,7 +23,7 @@ public abstract class AbstractStorageStrategyIT
   protected void start()
   {
     StorageStrategyITConfig config = getConfig();
-    chathome = new SimpleChatHome(config.getChatHomeService());
+    chathome = config.getChatHome();
     chatRoomFactory = config.getChatRoomFactory();
   }
 
@@ -118,7 +116,7 @@ public abstract class AbstractStorageStrategyIT
 
   interface StorageStrategyITConfig
   {
-    ChatHomeService getChatHomeService();
+    ChatHome getChatHome();
     ChatRoomFactory getChatRoomFactory();
   }
 }
index 418373a..e45f1a5 100644 (file)
@@ -2,8 +2,6 @@ package de.juplo.kafka.chat.backend.persistence.inmemory;
 
 import de.juplo.kafka.chat.backend.domain.ChatRoom;
 import de.juplo.kafka.chat.backend.domain.ChatRoomService;
-import de.juplo.kafka.chat.backend.persistence.inmemory.ChatHomeService;
-import de.juplo.kafka.chat.backend.persistence.inmemory.SimpleChatHome;
 import org.junit.jupiter.api.DisplayName;
 import org.junit.jupiter.api.Test;
 import reactor.core.publisher.Mono;
@@ -25,7 +23,7 @@ public class SimpleChatHomeTest
   void testGetExistingChatroom()
   {
     // Given
-    ChatHomeService chatHomeService = mock(ChatHomeService.class);
+    InMemoryChatHomeService chatHomeService = mock(InMemoryChatHomeService.class);
     ChatRoom chatRoom = new ChatRoom(
         UUID.randomUUID(),
         "Foo",
@@ -48,7 +46,7 @@ public class SimpleChatHomeTest
   void testGetNonExistentChatroom()
   {
     // Given
-    ChatHomeService chatHomeService = mock(ChatHomeService.class);
+    InMemoryChatHomeService chatHomeService = mock(InMemoryChatHomeService.class);
     when(chatHomeService.getChatRoom(anyInt(), any(UUID.class))).thenReturn(Mono.empty());
     SimpleChatHome chatHome = new SimpleChatHome(chatHomeService);