3 Commits

  1. 8
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java
  2. 51
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java

8
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java

@ -17,7 +17,15 @@ public class Customers {
return pool.putIfAbsent(user.nickName, user); return pool.putIfAbsent(user.nickName, user);
} }
public User deleteUser(String userNickname) {
return pool.remove(userNickname);
}
public User getByNickname(String nickname) { public User getByNickname(String nickname) {
return pool.get(nickname); return pool.get(nickname);
} }
public int getCountOfUsers() {
return pool.size();
}
} }

51
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java

@ -16,6 +16,22 @@ public class CustomersTest extends TestCase {
assertTrue(nicknameIsAvailable); 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() { public void test_registerSingleUser() {
// Given // Given
Customers customers = new Customers(); Customers customers = new Customers();
@ -72,4 +88,39 @@ public class CustomersTest extends TestCase {
assertTrue(userRegistered); 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);
}
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);
}
} }
Loading…
Cancel
Save