diff --git a/.idea/.name b/.idea/.name
new file mode 100644
index 0000000..ecd3ab2
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+pizza-order-training
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..b9c722a
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml
new file mode 100644
index 0000000..a82457d
--- /dev/null
+++ b/.idea/libraries/Maven__org_apiguardian_apiguardian_api_1_0_0.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_2.xml b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_2.xml
new file mode 100644
index 0000000..75b2f5e
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_jupiter_junit_jupiter_api_5_3_2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_2.xml b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_2.xml
new file mode 100644
index 0000000..26372d3
--- /dev/null
+++ b/.idea/libraries/Maven__org_junit_platform_junit_platform_commons_1_3_2.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml
new file mode 100644
index 0000000..70277df
--- /dev/null
+++ b/.idea/libraries/Maven__org_opentest4j_opentest4j_1_1_1.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..d30d09e
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..b9db595
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..e96534f
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..59d5b64
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,453 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1561131495367
+
+
+ 1561131495367
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pizza-order-training.iml b/pizza-order-training.iml
new file mode 100644
index 0000000..488e86a
--- /dev/null
+++ b/pizza-order-training.iml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 3e9851b..7a21c61 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,14 +7,29 @@
com.simbirsoft
pizza-order-training
1.0-SNAPSHOT
+
+
+ 5.3.2
+
+
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junit.version}
+ test
+
+
+
+
org.apache.maven.plugins
maven-compiler-plugin
- 1.7
- 1.7
+ 1.8
+ 1.8
diff --git a/src/main/java/model/Pizza.java b/src/main/java/model/Pizza.java
index 8096217..238735c 100644
--- a/src/main/java/model/Pizza.java
+++ b/src/main/java/model/Pizza.java
@@ -12,65 +12,51 @@ public class Pizza {
private HashMap ingredients;
public Pizza() {
-
+ this.ingredients = new HashMap<>();
}
- public Pizza(
- int size, HashMap ingredients
- ) {
+ public Pizza(int size, HashMap ingredients) {
this.size = size;
this.ingredients = ingredients;
+
+ }
+
+ public boolean isNotNull(Ingredient ingredient, int count) {
+ if (ingredient != null && count > 0 && ingredientsCollectionNotNull()) {
+ return true;
+ }
+ return false;
}
- public void addIngredient(
- Ingredient ingredient,
- int count
- ) throws PizzaException {
- if (ingredient != null && count > 0) {
- // Проверка на существование коллекции
- if (!ingredientsCollectionNotNull())
- initIngredientsCollection();
- // Если элемент уже существует
+ public void addIngredient(Ingredient ingredient, int count) throws PizzaException {
+ if(isNotNull(ingredient, count)) {
if (ingredients.containsKey(ingredient)) {
int alreadyExistIngredientCount = ingredients.get(
ingredient);
ingredients.put(
ingredient, alreadyExistIngredientCount + count);
- // Если не существует
} else {
ingredients.put(ingredient, count);
}
} else
- throw new PizzaException(
- "Указан некорректный ингредиент или его количество");
+ throw new PizzaException("Указан некорректный ингредиент или его количество");
}
- public void removeIngredient(
- Ingredient ingredient,
- int count
- ) throws PizzaException {
- if (ingredient != null && count > 0) {
- // Проверка на существование коллекции
- if (!ingredientsCollectionNotNull())
- initIngredientsCollection();
- // Если элемент уже существует
- if (ingredients.containsKey(ingredient)) {
- int alreadyExistIngredientCount = ingredients.get(
- ingredient);
- // Если количество уже существующих элементов больше либо
- // равно количеству удаляемых
- if (Math.abs(count) >= alreadyExistIngredientCount)
+ public void removeIngredient(Ingredient ingredient, int count) throws PizzaException {
+ if (isNotNull(ingredient, count)){
+ if (ingredients.containsKey(ingredient)) {
+ System.out.println("salam");
+ int alreadyExistIngredientCount = ingredients.get(ingredient);
+ if (Math.abs(count) >= alreadyExistIngredientCount) {
+ System.out.println("privet");
ingredients.remove(ingredient);
- else
+ } else {
ingredients.put(
- ingredient, alreadyExistIngredientCount - count);
- // Если элемента не сущетсвует
- } else
- throw new PizzaException(
- "Вы пытаетесь удалить ингредиент, который не существует в пицце");
- } else
- throw new PizzaException(
- "Указан некорректный ингредиент или его количество");
+ ingredient, alreadyExistIngredientCount - count);
+ }
+ } else
+ throw new PizzaException("Вы пытаетесь удалить ингредиент, который не существует в пицце");
+ }
}
private boolean ingredientsCollectionNotNull() {
@@ -78,10 +64,9 @@ private boolean ingredientsCollectionNotNull() {
}
private void initIngredientsCollection() {
- ingredients = new HashMap();
+ ingredients = new HashMap<>();
}
- // -- Getters & Setters --
public int getSize() {
return size;
diff --git a/src/main/tests/model/PizzaTests.java b/src/main/tests/model/PizzaTests.java
new file mode 100644
index 0000000..3de5fac
--- /dev/null
+++ b/src/main/tests/model/PizzaTests.java
@@ -0,0 +1,40 @@
+package model;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+/**
+ * ToDo Описание
+ *
+ * @author Ilshat Rizvanov
+ **/
+public class PizzaTests {
+ private Pizza pizza;
+
+ @BeforeEach
+ void init() {
+ pizza = new Pizza();
+ }
+
+ @Test
+ void addIngredient_ifIngredientAdded() throws PizzaException {
+ Ingredient ingredient = new Ingredient("Pelmen");
+ pizza.addIngredient(ingredient, 1);
+ assertTrue(pizza.getIngredients().containsKey(ingredient));
+ }
+
+ @Test
+ void removeIngredient_ifIngredientRemoved() throws PizzaException {
+ Ingredient ingredient = new Ingredient("Pelmen");
+ pizza.addIngredient(ingredient, 1);
+ pizza.removeIngredient(ingredient, 1);
+ assertFalse(pizza.getIngredients().containsKey(ingredient));
+ }
+
+ @Test
+ void addIngredient_exceptionThrown_ifIngredientIllegal() {
+ assertThrows(Exception.class, () -> pizza.addIngredient(null, 1));
+ }
+}
diff --git a/target/classes/PizzaOrder.class b/target/classes/PizzaOrder.class
new file mode 100644
index 0000000..2afd9c8
Binary files /dev/null and b/target/classes/PizzaOrder.class differ
diff --git a/target/classes/controller/CliController.class b/target/classes/controller/CliController.class
new file mode 100644
index 0000000..28f175a
Binary files /dev/null and b/target/classes/controller/CliController.class differ
diff --git a/target/classes/model/DefaultStorage.class b/target/classes/model/DefaultStorage.class
new file mode 100644
index 0000000..e1e9218
Binary files /dev/null and b/target/classes/model/DefaultStorage.class differ
diff --git a/target/classes/model/Ingredient.class b/target/classes/model/Ingredient.class
new file mode 100644
index 0000000..e6fc03b
Binary files /dev/null and b/target/classes/model/Ingredient.class differ
diff --git a/target/classes/model/Pizza.class b/target/classes/model/Pizza.class
new file mode 100644
index 0000000..975f191
Binary files /dev/null and b/target/classes/model/Pizza.class differ
diff --git a/target/classes/model/PizzaException.class b/target/classes/model/PizzaException.class
new file mode 100644
index 0000000..165c865
Binary files /dev/null and b/target/classes/model/PizzaException.class differ
diff --git a/target/classes/model/Storage.class b/target/classes/model/Storage.class
new file mode 100644
index 0000000..1f0bf5d
Binary files /dev/null and b/target/classes/model/Storage.class differ
diff --git a/target/classes/model/StorageException.class b/target/classes/model/StorageException.class
new file mode 100644
index 0000000..a51a6d6
Binary files /dev/null and b/target/classes/model/StorageException.class differ
diff --git a/target/test-classes/model/PizzaTests.class b/target/test-classes/model/PizzaTests.class
new file mode 100644
index 0000000..6cc9f6b
Binary files /dev/null and b/target/test-classes/model/PizzaTests.class differ