33 Commits

Author SHA1 Message Date
Maxim Volkov bfe9534bdd Added: javadoc for CustomersTest 3 years ago
Maxim Volkov a7e50b722a Added: javadoc for CustomersTest test_createRegisterAndCheckUserData 3 years ago
Maxim Volkov ec603c35f0 Added: javadoc for CustomersTest test_registerAndCountUsers() 3 years ago
Maxim Volkov 29329a7915 Added: javadoc for CustomersTest test_removeRegisteredUser() 3 years ago
Maxim Volkov 331a2b8407 Added: javadoc ItemTest test_buildCompleteItem() 3 years ago
Maxim Volkov 36d730a816 Added: javadoc ItemTest test_priceOfMultipleIdenticalItems() 3 years ago
Maxim Volkov 41247f5806 Added: javadoc ItemTest test_ItemInStock() 3 years ago
Maxim Volkov 8a996f5b24 Added: ItemTest minor refactoring 3 years ago
Maxim Volkov 04dd0a90b2 Added: Javadoc for UserTest test_initAndGetBirthdayOfUser() 3 years ago
Maxim Volkov 12e0edc42d Added: Javadoc for Birthday isValid() 3 years ago
Maxim Volkov cdfcc71399 Added: Javadoc for Customers nickNameAvailable() 3 years ago
Maxim Volkov dce6920ce7 Added: Javadoc for Customers getCountOfUsers() 3 years ago
Maxim Volkov bfb15c62be Added: Javadoc for Customers getByNickname() 3 years ago
Maxim Volkov a62245ae49 Added: Javadoc for Customers deleteUser() 3 years ago
Maxim Volkov 906bd9e4c9 Added: Javadoc for Customers registerUser() 3 years ago
Maxim Volkov b48c04fc39 Added: Javadoc for Item class 3 years ago
Maxim Volkov 70fa1700f5 Added: Javadoc for Item Methods + minor refactoring 3 years ago
Maxim Volkov 2b32772c85 Added: Javadoc for Item Methods 3 years ago
Maxim Volkov 28035c530f Added: Javadoc for Item constructors 3 years ago
Maxim Volkov 22f136449f Added: Javadoc for Warehouse 3 years ago
Maxim Volkov 2b8a628c60 Added: Javadoc for test_insertItemInWarehouse() 3 years ago
Maxim Volkov 5667effc02 Added: Javadoc for test_growingCountOfItemsInWarehouse 3 years ago
Maxim Volkov e1615c8adf Added: Javadoc for test_emptyWarehouse() 3 years ago
Maxim Volkov b6d9a7d449 Added: Empty Warehouse Test 3 years ago
Maxim Volkov 681a7a7f59 Added: Get Count Of Stock + Basic Test 3 years ago
Maxim Volkov 90025123e9 Added: Insert Item into Warehouse + Basic Test 3 years ago
Maxim Volkov 235e72665a Extended: test_buildCompleteItem() by validPrice Test 3 years ago
Maxim Volkov a7fdc436a9 Extended: test_buildCompleteItem() by validQuantity Test 3 years ago
Maxim Volkov de0afe0f23 Extended: test_buildCompleteItem() by validTitle Test 3 years ago
Maxim Volkov a3b1665875 Extended: test_buildCompleteItem() by validDescription Test 3 years ago
Maxim Volkov b9c6c11abf Minor Refactoring of test_buildCompleteItem() 3 years ago
Maxim Volkov 53b792fcc5 Added: Build Complete Item Basic Test 3 years ago
Maxim Volkov f6511309b1 Optimizing: Price of Item is float now 3 years ago
  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. 77
      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. 49
      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;
}
/**
*
* @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) {
if (DD < 1 || DD > 31) {
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 {
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) {
User u = pool.get(nickname);
if (null == u) {
@ -13,18 +19,37 @@ public class Customers {
return false;
}
/**
*
* @param user New User to register.
* @return
*/
public User registerUser(User 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) {
return pool.remove(userNickname);
}
/**
*
* @param nickname Find User by nickname
* @return
*/
public User getByNickname(String nickname) {
return pool.get(nickname);
}
/**
*
* @return Number of Users.
*/
public int getCountOfUsers() {
return pool.size();
}

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

@ -2,26 +2,87 @@ package de.hs_fulda.ciip.projjpn;
public class Item {
private int price;
// customerReview
// productTitle
// description
// tags
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;
}
public void updatePrice(int price) {
this.price = price;
/**
*
* @param newPrice of this item.
*/
public void updatePrice(float newPrice) {
this.price = newPrice;
}
public int getCurrentPrice() {
/**
*
* @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);
}
/**
* Register a user only when the given nickname is available.
*/
public void test_nicknameIsTaken() {
// Given
Customers customers = new Customers();
@ -32,6 +35,9 @@ public class CustomersTest extends TestCase {
assertFalse(nicknameIsTaken);
}
/**
* Register a single user and check whether it worked.
*/
public void test_registerSingleUser() {
// Given
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() {
// Given
Customers customers = new Customers();
@ -107,6 +116,9 @@ public class CustomersTest extends TestCase {
}
/**
* Register a given number of users.
*/
public void test_registerAndCountUsers() {
// Given
Customers customers = new Customers();
@ -123,6 +135,9 @@ public class CustomersTest extends TestCase {
assertEquals(expectedRegisteredUsers, actualRegisteredUsers);
}
/**
* Check if the Registration of a User works as intended.
*/
public void test_createRegisterAndCheckUserData() {
// Given
Customers customers = new Customers();

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

@ -3,6 +3,10 @@ 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();
@ -14,6 +18,10 @@ public class ItemTest extends TestCase {
assertFalse(notInStock);
}
/**
* Stock is not Empty.
* Check the inStock() Method.
*/
public void test_ItemInStock() {
// Given
Item item = new Item();
@ -25,24 +33,57 @@ public class ItemTest extends TestCase {
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;
int price = 5;
float price = 5;
item.updateAvailability(quantity);
item.updatePrice(price);
// When
int expectedPrice = quantity * price;
float expectedPrice = quantity * price;
// Then
int actualPrice = 0;
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;
public class UserTest extends TestCase {
/**
* Create User with a valid Birthday and check whether it worked as intended.
*/
public void test_initAndGetBirthdayOfUser() {
// Given
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