|
|
@ -0,0 +1,162 @@ |
|
|
|
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); |
|
|
|
} |
|
|
|
|
|
|
|
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 |
|
|
|
assertFalse(nicknameIsTaken); |
|
|
|
} |
|
|
|
|
|
|
|
public void test_registerSingleUser() { |
|
|
|
// 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); |
|
|
|
// |
|
|
|
assertNotNull(expectedNewUser); |
|
|
|
String expectedNickNameGotBack = expectedUser.nickName; |
|
|
|
|
|
|
|
// When |
|
|
|
boolean userRegistered = expectedNickNameGotBack.equals(expectedNickNameInput); |
|
|
|
|
|
|
|
// Then |
|
|
|
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]); |
|
|
|
assertNotNull(foundUser); |
|
|
|
|
|
|
|
// When |
|
|
|
expectedNickNameGotBack = foundUser.nickName; |
|
|
|
userRegistered = expectedNickNameGotBack.equals(expectedNickNamesInput[i]); |
|
|
|
|
|
|
|
// Then |
|
|
|
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); |
|
|
|
assertFalse(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); |
|
|
|
} |
|
|
|
|
|
|
|
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); |
|
|
|
|
|
|
|
assertNotNull(gotUser); |
|
|
|
|
|
|
|
// 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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |