Browse Source

Merge commit 'bfe9534bdd0932cf6c15919ffd2a5ed1ab75b638' into HEAD

dev
Jenkins 3 years ago
parent
commit
8e75a74775
  1. 8
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Birthdate.java
  2. 25
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Customers.java
  3. 88
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java
  4. 28
      projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Warehouse.java
  5. 15
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/CustomersTest.java
  6. 89
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java
  7. 3
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java
  8. 63
      projjpn/src/test/java/de/hs_fulda/ciip/projjpn/WarehouseTest.java

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

@ -42,6 +42,14 @@ public class Birthdate {
year = y; year = y;
} }
/**
*
* @param DD
* @param MM
* @param YYYY
* @return true if date is valid.
* @return false if date is invalid.
*/
public boolean isValid(int DD, int MM, int YYYY) { public boolean isValid(int DD, int MM, int YYYY) {
if (DD < 1 || DD > 31) { if (DD < 1 || DD > 31) {
return false; return false;

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

@ -5,6 +5,12 @@ import java.util.HashMap;
public class Customers { public class Customers {
HashMap<String, User> pool = new HashMap<String, User>(); HashMap<String, User> pool = new HashMap<String, User>();
/**
*
* @param nickname Is the particular Nickname free to use?
* @return true if nickname is Available.
* @return false if nickname is Available.
*/
public boolean nickNameAvailable(String nickname) { public boolean nickNameAvailable(String nickname) {
User u = pool.get(nickname); User u = pool.get(nickname);
if (null == u) { if (null == u) {
@ -13,18 +19,37 @@ public class Customers {
return false; return false;
} }
/**
*
* @param user New User to register.
* @return
*/
public User registerUser(User user) { public User registerUser(User user) {
return pool.putIfAbsent(user.nickName, user); return pool.putIfAbsent(user.nickName, user);
} }
/**
*
* @param userNickname Delete a particular User with the given nickname
* @return null or the deleted user.
*/
public User deleteUser(String userNickname) { public User deleteUser(String userNickname) {
return pool.remove(userNickname); return pool.remove(userNickname);
} }
/**
*
* @param nickname Find User by nickname
* @return
*/
public User getByNickname(String nickname) { public User getByNickname(String nickname) {
return pool.get(nickname); return pool.get(nickname);
} }
/**
*
* @return Number of Users.
*/
public int getCountOfUsers() { public int getCountOfUsers() {
return pool.size(); return pool.size();
} }

88
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Item.java

@ -0,0 +1,88 @@
package de.hs_fulda.ciip.projjpn;
public class Item {
private String productTitle;
private String description;
private int availability = 0;
private float price;
/**
* Creation of blank Item.
*/
public Item() {
}
/**
* Creation of Item.
* @param titel
* @param description
* @param quantity
* @param price
*/
public Item(String titel,
String description,
int quantity,
float price) {
this.productTitle = titel;
this.description = description;
this.availability = quantity;
this.price = price;
}
/**
*
* @return true if at least one item is in stock.
*/
public boolean inStock() {
return availability > 0;
}
/**
*
* @return current number of this items
*/
public float getCurrentStock() {
return availability;
}
/**
*
* @param newAmount of items
*/
public void updateAvailability(int newAmount) {
availability = newAmount;
}
/**
*
* @param newPrice of this item.
*/
public void updatePrice(float newPrice) {
this.price = newPrice;
}
/**
*
* @return Current Price of the Item.
*/
public float getCurrentPrice() {
return price;
}
/**
*
* @return Current public Title of this Item.
*/
public String getTitel() {
return this.productTitle;
}
/**
*
* @return Current public Description of this Item.
*/
public String getDescription() {
return this.description;
}
}

28
projjpn/src/main/java/de/hs_fulda/ciip/projjpn/Warehouse.java

@ -0,0 +1,28 @@
package de.hs_fulda.ciip.projjpn;
import java.util.HashMap;
public class Warehouse {
protected HashMap<String, Item> pool = new HashMap<String, Item>();
/**
*
* @param item Item to insert.
* @return the inserted Item or null.
*/
public Item insertItem(Item item) {
return pool.putIfAbsent(item.getTitel(), item);
}
/**
*
* @return The total amount of all Items.
*/
public int getCountOfStock() {
int sumItems = 0;
for (HashMap.Entry<String, Item> set : pool.entrySet()) {
sumItems += set.getValue().getCurrentStock();
}
return sumItems;
}
}

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

@ -16,6 +16,9 @@ public class CustomersTest extends TestCase {
assertTrue(nicknameIsAvailable); assertTrue(nicknameIsAvailable);
} }
/**
* Register a user only when the given nickname is available.
*/
public void test_nicknameIsTaken() { public void test_nicknameIsTaken() {
// Given // Given
Customers customers = new Customers(); Customers customers = new Customers();
@ -32,6 +35,9 @@ public class CustomersTest extends TestCase {
assertFalse(nicknameIsTaken); assertFalse(nicknameIsTaken);
} }
/**
* Register a single user and check whether it worked.
*/
public void test_registerSingleUser() { public void test_registerSingleUser() {
// Given // Given
Customers customers = new Customers(); Customers customers = new Customers();
@ -90,6 +96,9 @@ public class CustomersTest extends TestCase {
} }
} }
/**
* Test if deletion of an allready registered customer works.
*/
public void test_removeRegisteredUser() { public void test_removeRegisteredUser() {
// Given // Given
Customers customers = new Customers(); Customers customers = new Customers();
@ -107,6 +116,9 @@ public class CustomersTest extends TestCase {
} }
/**
* Register a given number of users.
*/
public void test_registerAndCountUsers() { public void test_registerAndCountUsers() {
// Given // Given
Customers customers = new Customers(); Customers customers = new Customers();
@ -123,6 +135,9 @@ public class CustomersTest extends TestCase {
assertEquals(expectedRegisteredUsers, actualRegisteredUsers); assertEquals(expectedRegisteredUsers, actualRegisteredUsers);
} }
/**
* Check if the Registration of a User works as intended.
*/
public void test_createRegisterAndCheckUserData() { public void test_createRegisterAndCheckUserData() {
// Given // Given
Customers customers = new Customers(); Customers customers = new Customers();

89
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/ItemTest.java

@ -0,0 +1,89 @@
package de.hs_fulda.ciip.projjpn;
import junit.framework.TestCase;
public class ItemTest extends TestCase {
/**
* No Items are in Stock.
* Check the inStock() Method.
*/
public void test_ItemNotInStock() {
// Given
Item item = new Item();
// When
boolean notInStock = item.inStock();
// Then
assertFalse(notInStock);
}
/**
* Stock is not Empty.
* Check the inStock() Method.
*/
public void test_ItemInStock() {
// Given
Item item = new Item();
item.updateAvailability(1);
// When
boolean inStock = item.inStock();
// Then
assertTrue(inStock);
}
/**
* One and the same type of an item costs the same.
* check getCurrentPrice()
*/
public void test_priceOfMultipleIdenticalItems() {
// Given
Item item = new Item();
int quantity = 3;
float price = 5;
item.updateAvailability(quantity);
item.updatePrice(price);
// When
float expectedPrice = quantity * price;
// Then
float actualPrice = 0;
for(int i = 0; i < quantity; i++) {
actualPrice += item.getCurrentPrice();
}
assertEquals(expectedPrice, actualPrice);
}
/**
* Check if creating a complete item with all attributes works as intended.
*/
public void test_buildCompleteItem() {
// Given
String expectedTitel = "Logitec Maus";
String expectedDescription = "Gaming Maus fuer Fortgeschrittene.";
int expectedQuantity = 10;
float expectedPrice = 69.99f;
// When
Item itemNotNull = new Item(expectedTitel, expectedDescription, expectedQuantity, expectedPrice);
// Then
assertNotNull(itemNotNull);
// When
boolean validDescription = itemNotNull.getDescription().equals(expectedDescription);
assertTrue(validDescription);
boolean validTitle = itemNotNull.getTitel().equals(expectedTitel);
assertTrue(validTitle);
boolean validQuantity = itemNotNull.getCurrentStock() == expectedQuantity;
assertTrue(validQuantity);
boolean validPrice = itemNotNull.getCurrentPrice() == expectedPrice;
assertTrue(validPrice);
}
}

3
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/UserTest.java

@ -3,6 +3,9 @@ package de.hs_fulda.ciip.projjpn;
import junit.framework.TestCase; import junit.framework.TestCase;
public class UserTest extends TestCase { public class UserTest extends TestCase {
/**
* Create User with a valid Birthday and check whether it worked as intended.
*/
public void test_initAndGetBirthdayOfUser() { public void test_initAndGetBirthdayOfUser() {
// Given // Given
Customers customers = new Customers(); Customers customers = new Customers();

63
projjpn/src/test/java/de/hs_fulda/ciip/projjpn/WarehouseTest.java

@ -0,0 +1,63 @@
package de.hs_fulda.ciip.projjpn;
import junit.framework.TestCase;
public class WarehouseTest extends TestCase {
/**
* Check if the insertion of an Item works properly.
*/
public void test_insertItemInWarehouse() {
// Given
Warehouse warehouse = new Warehouse();
String expectedTitel = "Logitec Maus";
String expectedDescription = "Gaming Maus fuer Fortgeschrittene.";
int expectedQuantity = 10;
float expectedPrice = 69.69f;
// When
Item expectedItem = new Item(expectedTitel, expectedDescription, expectedQuantity, expectedPrice);
assertNotNull(expectedItem);
warehouse.insertItem(expectedItem);
Item gotItem = warehouse.pool.get(expectedTitel);
// Then
assertEquals(expectedTitel, gotItem.getTitel());
}
/**
* Test the total Sum of Items in the whole Warehouse.
*/
public void test_growingCountOfItemsInWarehouse() {
// Given
Warehouse warehouse = new Warehouse();
int unitsPerItemType = 3;
int expectedSize = 13;
for (int i = 0; i < expectedSize; i++) {
Item item = new Item("ItemDummy" + i, "DescriptionDummy" + i, unitsPerItemType, 12.0f);
warehouse.insertItem(item);
}
int expectedSum = expectedSize * unitsPerItemType;
int actualSumOfAllItems = warehouse.getCountOfStock();
// Then
assertEquals(expectedSum, actualSumOfAllItems);
}
/**
* Empty Warehouse means there are a total of zero Items.
*/
public void test_emptyWarehouse() {
// Given
Warehouse warehouse = new Warehouse();
// When
int expectedSum = 0;
// Then
int actualSumOfAllItems = warehouse.getCountOfStock();
assertEquals(expectedSum, actualSumOfAllItems);
}
}
Loading…
Cancel
Save