From fa83071186ad48b41819bc2a2ed1033e4f803cdd Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 05:04:22 +0100 Subject: [PATCH] Added: Remove a registered user + Basic Test --- .../de/hs_fulda/ciip/projjpn/Customers.java | 4 ++++ .../hs_fulda/ciip/projjpn/CustomersTest.java | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java index 18059b9..c56cde6 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java @@ -17,6 +17,10 @@ public class Customers { return pool.putIfAbsent(user.nickName, user); } + public User deleteUser(String userNickname) { + return pool.remove(userNickname); + } + public User getByNickname(String nickname) { return pool.get(nickname); } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java index 2816fc5..2df7fd8 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java @@ -88,4 +88,22 @@ public class CustomersTest extends TestCase { assertTrue(userRegistered); } } + + public void test_removeRegisteredUser() { + // Given + Customers customers = new Customers(); + String userToRemove = "beastMaster64"; + User userToRegister = new User("beastMaster64"); + customers.registerUser(userToRegister); + + // When + boolean userExists = !customers.nickNameAvailable(userToRemove); + assertTrue(userExists); + + // Then + User removedUser = customers.deleteUser(userToRemove); + assertEquals(userToRemove, removedUser.nickName); + + } + }