7 Commits

  1. 45
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java
  2. 23
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java
  3. 29
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java
  4. 37
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java
  5. 41
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java

45
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 int getMonth() {
return month;
}
public int getYear() {
return year;
}
/**
* @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;
year = y;
}
}

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

@ -0,0 +1,23 @@
package de.hs_fulda.ciip.projjpn;
import java.util.HashMap;
public class Customers {
HashMap<String, User> pool = new HashMap<String, User>();
public boolean nickNameAvailable(String nickname) {
User u = pool.get(nickname);
if (null == u) {
return true;
}
return false;
}
public User registerUser(User user) {
return pool.putIfAbsent(user.nickName, user);
}
public User getByNickname(String nickname) {
return pool.get(nickname);
}
}

29
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/User.java

@ -0,0 +1,29 @@
package de.hs_fulda.ciip.projjpn;
public class User {
String firstName;
String lastName;
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;
}
}

37
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/BirthdateTest.java

@ -0,0 +1,37 @@
package de.hs_fulda.ciip.projjpn;
import junit.framework.TestCase;
public class BirthdateTest extends TestCase {
public void testToString() {
// Given
Birthdate b = new Birthdate(1, 1, 2000);
// When
String expectedDate = "1.1.2000";
// 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());
}
}

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

@ -0,0 +1,41 @@
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_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);
}
}
Loading…
Cancel
Save