From edc3cd2c14280d045a764c169834dafdb94295f9 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 04:14:37 +0100 Subject: [PATCH] Added: Registering a User + Basic Test --- .../de/hs_fulda/ciip/projjpn/Customers.java | 8 +++++++ .../java/de/hs_fulda/ciip/projjpn/User.java | 20 ++++++++++++++++ .../hs_fulda/ciip/projjpn/CustomersTest.java | 23 ++++++++++++++++++- 3 files changed, 50 insertions(+), 1 deletion(-) 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 f495ca9..18059b9 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 @@ -12,4 +12,12 @@ public class Customers { } return false; } + + public User registerUser(User user) { + return pool.putIfAbsent(user.nickName, user); + } + + public User getByNickname(String nickname) { + return pool.get(nickname); + } } diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java index d8ce08a..dfac66c 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java @@ -6,4 +6,24 @@ public class User { String nickName; String eMail; Birthdate birthdate; + + public User(String nickName) { + this.nickName = nickName; + } + + public String getFirstName() { + return firstName; + } + public String getLastName() { + return lastName; + } + public String getNickName() { + return nickName; + } + public String geteMail() { + return eMail; + } + public Birthdate getBirthdate() { + return birthdate; + } } 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 5b6a59d..d4e24d4 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 @@ -14,7 +14,28 @@ public class CustomersTest extends TestCase { // Then assertTrue(nicknameIsAvailable); + } + + public void test_registerUser() { + // Given + Customers customers = new Customers(); + String expectedNickNameInput = "Mougli"; + User expectedNewUser = new User(expectedNickNameInput); + + // Add a user + customers.registerUser(expectedNewUser); + // Get the expected User + User expectedUser = customers.getByNickname(expectedNickNameInput); + assertTrue(null != expectedNewUser); + String expectedNickNameGotBack = expectedUser.nickName; + + System.out.println(expectedNickNameGotBack); + // When + boolean userRegistered = expectedNickNameGotBack.equals(expectedNickNameInput); + + // Then + assertTrue(userRegistered); } - + }