From e0f80b9ae742b4cc2d29e37dcc40e3fd67560092 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 02:33:08 +0100 Subject: [PATCH 01/18] Added: Birthdate class, basic Birthdate Test --- .../de/hs_fulda/ciip/projjpn/Birthdate.java | 45 +++++++++++++++++++ .../hs_fulda/ciip/projjpn/BirthdateTest.java | 21 +++++++++ 2 files changed, 66 insertions(+) create mode 100644 projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java create mode 100644 projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java new file mode 100644 index 0000000..ad05fb7 --- /dev/null +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java @@ -0,0 +1,45 @@ +package de.hs_fulda.ciip.projjpn; + +public class Birthdate { + private int day; + private int month; + private int year; + + public Birthdate(int d, int m, int y) { + day = d; + month = m; + year = y; + } + + public int getDay() { + return day; + } + + public void setDay(int day) { + this.day = day; + } + + public int getMonth() { + return month; + } + + public void setMonth(int month) { + this.month = month; + } + + public int getYear() { + return year; + } + + public void setYear(int year) { + this.year = year; + } + + /** + * @return Date Format TT.DD.YYYY + */ + public String toString() { + return day + "." + month + "." + year; + } + +} diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java new file mode 100644 index 0000000..6461784 --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java @@ -0,0 +1,21 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class BirthdateTest extends TestCase { + + /** + * Test method for {@link de.hs_fulda.ciip.projjpn.Birthdate#toString()}. + */ + public final void testToString() { + + // Given + Birthdate b = new Birthdate(1, 1, 2000); + + // When + String expectedDate = "1.1.2000"; + + // Then + assertEquals(expectedDate, b.toString()); + } +} From 7ae7650c2d4755f5f399b90dfbe09a70cbacc5c1 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 02:39:46 +0100 Subject: [PATCH 02/18] Cleanup: Birthday class --- .../de/hs_fulda/ciip/projjpn/Birthdate.java | 30 ++++--------------- .../hs_fulda/ciip/projjpn/BirthdateTest.java | 4 +-- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java index ad05fb7..14062d7 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java @@ -11,35 +11,17 @@ public class Birthdate { year = y; } - public int getDay() { - return day; - } - - public void setDay(int day) { - this.day = day; - } - - public int getMonth() { - return month; - } - - public void setMonth(int month) { - this.month = month; - } - - public int getYear() { - return year; - } - - public void setYear(int year) { - this.year = year; - } - /** * @return Date Format TT.DD.YYYY */ public String toString() { return day + "." + month + "." + year; } + + public void changeBirthdate(int d, int m, int y) { + day = d; + month = m; + year = y; + } } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java index 6461784..312a870 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java @@ -7,7 +7,7 @@ public class BirthdateTest extends TestCase { /** * Test method for {@link de.hs_fulda.ciip.projjpn.Birthdate#toString()}. */ - public final void testToString() { + public void testToString() { // Given Birthdate b = new Birthdate(1, 1, 2000); @@ -17,5 +17,5 @@ public class BirthdateTest extends TestCase { // Then assertEquals(expectedDate, b.toString()); - } + } } From b1cda58c660f94a4b27cdec7ab55ce3f5289c905 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 02:49:52 +0100 Subject: [PATCH 03/18] Added: Change Date of Birthday --- .../de/hs_fulda/ciip/projjpn/Birthdate.java | 12 ++++++++++ .../hs_fulda/ciip/projjpn/BirthdateTest.java | 22 ++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java index 14062d7..f000456 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java @@ -10,6 +10,18 @@ public class Birthdate { month = m; year = y; } + + public int getDay() { + return day; + } + + public int getMonth() { + return month; + } + + public int getYear() { + return year; + } /** * @return Date Format TT.DD.YYYY diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java index 312a870..23de888 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java @@ -4,9 +4,6 @@ import junit.framework.TestCase; public class BirthdateTest extends TestCase { - /** - * Test method for {@link de.hs_fulda.ciip.projjpn.Birthdate#toString()}. - */ public void testToString() { // Given @@ -18,4 +15,23 @@ public class BirthdateTest extends TestCase { // Then assertEquals(expectedDate, b.toString()); } + + public void test_changeBirthdate() { + // Given + Birthdate b = new Birthdate(1, 1, 2000); + + // Change Birthdate + b.changeBirthdate(2, 3, 2001); + + // When + int expectedDay = 2; + int expectedMonth = 3; + int expectedYear = 2001; + + // Then + assertEquals(2, b.getDay()); + assertEquals(3, b.getMonth()); + assertEquals(2001, b.getYear()); + } + } From 64fbd340311bae982493ee3efd428803829f87b4 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 02:53:32 +0100 Subject: [PATCH 04/18] Refactoring: Fixing Comments in Birthdate --- .../src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java index f000456..f3d5b81 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java @@ -24,12 +24,18 @@ public class Birthdate { } /** - * @return Date Format TT.DD.YYYY + * @return Date Format DD.MM.YYYY */ public String toString() { return day + "." + month + "." + year; } + /** + * + * @param d Day + * @param m Month + * @param y Year + */ public void changeBirthdate(int d, int m, int y) { day = d; month = m; From e7fe6b37ff44a0acc959dba023c8de4146e6a10e Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 03:06:27 +0100 Subject: [PATCH 05/18] Added: User class, basic attributes --- projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java 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 new file mode 100644 index 0000000..d8ce08a --- /dev/null +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java @@ -0,0 +1,9 @@ +package de.hs_fulda.ciip.projjpn; + +public class User { + String firstName; + String lastName; + String nickName; + String eMail; + Birthdate birthdate; +} From 9061e3df654657ae41965dbcd4143ff3c5c9121d Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 03:24:08 +0100 Subject: [PATCH 06/18] Added: Customers class for managing Users, Test if a nickname is available --- .../de/hs_fulda/ciip/projjpn/Customers.java | 15 ++++++++++++++ .../hs_fulda/ciip/projjpn/CustomersTest.java | 20 +++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java create mode 100644 projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java 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 new file mode 100644 index 0000000..f495ca9 --- /dev/null +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java @@ -0,0 +1,15 @@ +package de.hs_fulda.ciip.projjpn; + +import java.util.HashMap; + +public class Customers { + HashMap pool = new HashMap(); + + public boolean nickNameAvailable(String nickname) { + User u = pool.get(nickname); + if (null == u) { + return true; + } + return false; + } +} 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 new file mode 100644 index 0000000..5b6a59d --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java @@ -0,0 +1,20 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class CustomersTest extends TestCase { + + public void test_nicknameIsFree() { + // Given + Customers customers = new Customers(); + String availableNickname = "beastMaster64"; + + // When + boolean nicknameIsAvailable = customers.nickNameAvailable(availableNickname); + + // Then + assertTrue(nicknameIsAvailable); + + } + +} From edc3cd2c14280d045a764c169834dafdb94295f9 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 04:14:37 +0100 Subject: [PATCH 07/18] 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); } - + } From 08664de5b52d87b550414b0b674ec17b76fb590d Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 04:24:36 +0100 Subject: [PATCH 08/18] Refactoring: Rename Test for registering a user --- .../src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d4e24d4..833dfd0 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 @@ -16,7 +16,7 @@ public class CustomersTest extends TestCase { assertTrue(nicknameIsAvailable); } - public void test_registerUser() { + public void test_registerSingleUser() { // Given Customers customers = new Customers(); String expectedNickNameInput = "Mougli"; From 8bc8925dfb1a95470df967275b1d1129e763482a Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 04:26:29 +0100 Subject: [PATCH 09/18] Remove: Deprecated System Out Print --- .../src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java | 1 - 1 file changed, 1 deletion(-) 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 833dfd0..33b6cba 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 @@ -30,7 +30,6 @@ public class CustomersTest extends TestCase { assertTrue(null != expectedNewUser); String expectedNickNameGotBack = expectedUser.nickName; - System.out.println(expectedNickNameGotBack); // When boolean userRegistered = expectedNickNameGotBack.equals(expectedNickNameInput); From a5d54b0ea60673b511c23c830bd4f2c84efe60ee Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 04:38:33 +0100 Subject: [PATCH 10/18] Added: Register Multiple Users Test --- .../hs_fulda/ciip/projjpn/CustomersTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) 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 33b6cba..e89d5e2 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 @@ -37,4 +37,39 @@ public class CustomersTest extends TestCase { assertTrue(userRegistered); } + /** + * Register multiple Users and then search for them in the same order. + */ + public void test_registerMultipleUsers() { + // Given + Customers customers = new Customers(); + String[] expectedNickNamesInput = {"Mougli", "Tarkan", "beastMaster64", "BlaBlaPew", "MuchDoge_321"}; + User[] expectedNewUsers = new User[expectedNickNamesInput.length]; + + for (int i = 0; i < expectedNickNamesInput.length; i++) { + // Create user + expectedNewUsers[i] = new User(expectedNickNamesInput[i]); + + // Add user + customers.registerUser(expectedNewUsers[i]); + } + + // Get the expected Users + User foundUser; + String expectedNickNameGotBack; + boolean userRegistered; + + for (int i = 0; i < expectedNickNamesInput.length; i++) { + // Get user + foundUser = customers.getByNickname(expectedNickNamesInput[i]); + assertTrue(null != foundUser); + + // When + expectedNickNameGotBack = foundUser.nickName; + userRegistered = expectedNickNameGotBack.equals(expectedNickNamesInput[i]); + + // Then + assertTrue(userRegistered); + } + } } From 59ba7db3a512154716b96d05cc98ae704fa16de3 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 04:46:15 +0100 Subject: [PATCH 11/18] Added: Nickname allready taken test --- .../de/hs_fulda/ciip/projjpn/CustomersTest.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 e89d5e2..2816fc5 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 @@ -16,6 +16,22 @@ public class CustomersTest extends TestCase { assertTrue(nicknameIsAvailable); } + public void test_nicknameIsTaken() { + // Given + Customers customers = new Customers(); + String availableNickname = "beastMaster64"; + String takenNickname = "beastMaster64"; + User userToRegister = new User(availableNickname); + + customers.registerUser(userToRegister); + + // When + boolean nicknameIsTaken = !customers.nickNameAvailable(availableNickname); + + // Then + assertTrue(nicknameIsTaken); + } + public void test_registerSingleUser() { // Given Customers customers = new Customers(); From fa83071186ad48b41819bc2a2ed1033e4f803cdd Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 05:04:22 +0100 Subject: [PATCH 12/18] 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); + + } + } From 012ad38d16eb2724ee39375f77aa98eea1a3e2d3 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 05:20:10 +0100 Subject: [PATCH 13/18] Added: Count Registered Users and Test --- .../de/hs_fulda/ciip/projjpn/Customers.java | 4 ++++ .../de/hs_fulda/ciip/projjpn/CustomersTest.java | 17 +++++++++++++++++ 2 files changed, 21 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 c56cde6..174016e 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 @@ -24,4 +24,8 @@ public class Customers { public User getByNickname(String nickname) { return pool.get(nickname); } + + public int getCountOfUsers() { + return pool.size(); + } } 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 2df7fd8..1a2bf5f 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 @@ -105,5 +105,22 @@ public class CustomersTest extends TestCase { assertEquals(userToRemove, removedUser.nickName); } + + public void test_registerAndCountUsers() { + // Given + Customers customers = new Customers(); + int expectedRegisteredUsers = 20; + int actualRegisteredUsers = -1; + String nickname; + + // Prepare + for(int i = 0, j = 1; i < expectedRegisteredUsers; i++, j++) { + nickname = "beastMaster_" + j; + customers.registerUser(new User(nickname)); + } + actualRegisteredUsers = customers.getCountOfUsers(); + assertEquals(expectedRegisteredUsers, actualRegisteredUsers); + + } } From 66dc3dea9ce7b67e7e83b283a788cacaa8583aea Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 05:37:26 +0100 Subject: [PATCH 14/18] Added: Create register and check user data - Test --- .../java/de/hs_fulda/ciip/projjpn/User.java | 12 ++++++ .../hs_fulda/ciip/projjpn/CustomersTest.java | 39 +++++++++++++++++++ 2 files changed, 51 insertions(+) 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 dfac66c..3c1fc87 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 @@ -7,6 +7,18 @@ public class User { String eMail; Birthdate birthdate; + public User(String firstName, + String lastName, + String nickName, + String eMail, + Birthdate birthdate) { + this.firstName = firstName; + this.lastName = lastName; + this.nickName = nickName; + this.eMail = eMail; + this.birthdate = birthdate; + } + public User(String nickName) { this.nickName = 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 1a2bf5f..f9228c1 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 @@ -120,7 +120,46 @@ public class CustomersTest extends TestCase { } actualRegisteredUsers = customers.getCountOfUsers(); assertEquals(expectedRegisteredUsers, actualRegisteredUsers); + } + + public void test_createRegisterAndCheckUserData() { + // Given + Customers customers = new Customers(); + + String firstName = "Mia"; + String lastName = "Muster"; + String nickName = "harley"; + String eMail = "mia@muster.de"; + Birthdate birthdate = new Birthdate(30, 12, 1997); + User userToCheck = new User(firstName, lastName, nickName, eMail, birthdate); + + // Register User + customers.registerUser(userToCheck); + + User gotUser = customers.getByNickname(nickName); + + // When + boolean foundUser = null != gotUser; + + // Then + assertTrue(foundUser); + + // When + boolean correctFirstName = "Mia".equals(gotUser.getFirstName()); + boolean correctLastName = "Muster".equals(gotUser.getLastName()); + boolean correctNickName = "harley".equals(gotUser.getNickName()); + boolean correctEMail = "mia@muster.de".equals(gotUser.geteMail()); + boolean correctBirthdate = birthdate.toString().equals(gotUser.birthdate.toString()); + + // Then + assertTrue(correctFirstName); + assertTrue(correctLastName); + assertTrue(correctNickName); + assertTrue(correctEMail); + assertTrue(correctBirthdate); + } + } From 866807f244b3f07e13e4ece43941d62bbb6ede27 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 05:59:07 +0100 Subject: [PATCH 15/18] Refactoring: Optimized Structure of Tests --- .../hs_fulda/ciip/projjpn/CustomersTest.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) 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 f9228c1..92669c7 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 @@ -26,10 +26,10 @@ public class CustomersTest extends TestCase { customers.registerUser(userToRegister); // When - boolean nicknameIsTaken = !customers.nickNameAvailable(availableNickname); + boolean nicknameIsTaken = customers.nickNameAvailable(availableNickname); // Then - assertTrue(nicknameIsTaken); + assertFalse(nicknameIsTaken); } public void test_registerSingleUser() { @@ -43,7 +43,8 @@ public class CustomersTest extends TestCase { // Get the expected User User expectedUser = customers.getByNickname(expectedNickNameInput); - assertTrue(null != expectedNewUser); + // + assertNotNull(expectedNewUser); String expectedNickNameGotBack = expectedUser.nickName; // When @@ -78,7 +79,7 @@ public class CustomersTest extends TestCase { for (int i = 0; i < expectedNickNamesInput.length; i++) { // Get user foundUser = customers.getByNickname(expectedNickNamesInput[i]); - assertTrue(null != foundUser); + assertNotNull(foundUser); // When expectedNickNameGotBack = foundUser.nickName; @@ -97,8 +98,8 @@ public class CustomersTest extends TestCase { customers.registerUser(userToRegister); // When - boolean userExists = !customers.nickNameAvailable(userToRemove); - assertTrue(userExists); + boolean userExists = customers.nickNameAvailable(userToRemove); + assertFalse(userExists); // Then User removedUser = customers.deleteUser(userToRemove); @@ -139,11 +140,7 @@ public class CustomersTest extends TestCase { User gotUser = customers.getByNickname(nickName); - // When - boolean foundUser = null != gotUser; - - // Then - assertTrue(foundUser); + assertNotNull(gotUser); // When boolean correctFirstName = "Mia".equals(gotUser.getFirstName()); From 8b877b06216f354bfe296274eb4a0a55601ef11a Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 06:01:29 +0100 Subject: [PATCH 16/18] Refactoring: Minor Renaming in User class --- projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java | 2 +- .../src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 3c1fc87..710e097 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 @@ -32,7 +32,7 @@ public class User { public String getNickName() { return nickName; } - public String geteMail() { + public String getEMail() { return eMail; } public Birthdate getBirthdate() { 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 92669c7..110d7ad 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 @@ -146,7 +146,7 @@ public class CustomersTest extends TestCase { boolean correctFirstName = "Mia".equals(gotUser.getFirstName()); boolean correctLastName = "Muster".equals(gotUser.getLastName()); boolean correctNickName = "harley".equals(gotUser.getNickName()); - boolean correctEMail = "mia@muster.de".equals(gotUser.geteMail()); + boolean correctEMail = "mia@muster.de".equals(gotUser.getEMail()); boolean correctBirthdate = birthdate.toString().equals(gotUser.birthdate.toString()); // Then From b3833f62b84c698cae8a7cf11b003fc12c9cc985 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 06:22:48 +0100 Subject: [PATCH 17/18] Added: Birthday Validation + Test --- .../de/hs_fulda/ciip/projjpn/Birthdate.java | 14 +++++++++++++ .../hs_fulda/ciip/projjpn/BirthdateTest.java | 7 +++++++ .../de/hs_fulda/ciip/projjpn/UserTest.java | 20 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java index f3d5b81..ab9af4c 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java @@ -41,5 +41,19 @@ public class Birthdate { month = m; year = y; } + + public boolean isValid(int DD, int MM, int YYYY) { + if (DD < 1) { + return false; + } + if (MM < 1) { + return false; + } + if (YYYY < 1) { + return false; + } + + return true; + } } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java index 23de888..8b3ea01 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java @@ -34,4 +34,11 @@ public class BirthdateTest extends TestCase { assertEquals(2001, b.getYear()); } + public void test_rejectInvalidBirthday() { + Birthdate birthdate = new Birthdate(0, 0, 0); + boolean expectedResult = false; + boolean gotResult = birthdate.isValid(0, 0, 0); + assertEquals(expectedResult, gotResult); + } + } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java new file mode 100644 index 0000000..419153e --- /dev/null +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java @@ -0,0 +1,20 @@ +package de.hs_fulda.ciip.projjpn; + +import junit.framework.TestCase; + +public class UserTest extends TestCase { + public void test_initAndGetBirthdayOfUser() { + // Given + Customers customers = new Customers(); + String firstName = "Mia"; + String lastName = "Muster"; + String nickName = "harley"; + String eMail = "mia@muster.de"; + int DD = 30, MM = 12, YYYY = 1997; + String expectedBirthdate = new Birthdate(DD, MM, YYYY).toString(); + + User userToCheck = new User(firstName, lastName, nickName, eMail, new Birthdate(DD, MM, YYYY)); + String gotBirthdate = userToCheck.getBirthdate().toString(); + boolean gotExpectedBirthdayBack = gotBirthdate.equals(expectedBirthdate); + } +} From 66a8e380b06f8dff28e5871ab298598fb916b7f2 Mon Sep 17 00:00:00 2001 From: Maxim Volkov Date: Thu, 17 Feb 2022 06:41:45 +0100 Subject: [PATCH 18/18] Added: Better Test Coverage for the Birthday class --- .../de/hs_fulda/ciip/projjpn/Birthdate.java | 6 +++--- .../hs_fulda/ciip/projjpn/BirthdateTest.java | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java index ab9af4c..32ed901 100644 --- a/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java +++ b/projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java @@ -43,13 +43,13 @@ public class Birthdate { } public boolean isValid(int DD, int MM, int YYYY) { - if (DD < 1) { + if (DD < 1 || DD > 31) { return false; } - if (MM < 1) { + if (MM < 1 || MM > 12) { return false; } - if (YYYY < 1) { + if (YYYY < 1990 || YYYY > 2022) { return false; } diff --git a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java index 8b3ea01..b584b58 100644 --- a/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java +++ b/projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java @@ -39,6 +39,25 @@ public class BirthdateTest extends TestCase { boolean expectedResult = false; boolean gotResult = birthdate.isValid(0, 0, 0); assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(32, 13, 1990); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(31, 0, 1980); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(31, 13, 1980); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(1, 1, 3000); + assertEquals(expectedResult, gotResult); + + gotResult = birthdate.isValid(1, 1, 1900); + assertEquals(expectedResult, gotResult); + + expectedResult = true; + gotResult = birthdate.isValid(1, 5, 2020); + assertEquals(expectedResult, gotResult); } }