Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Created by .ignore support plugin (hsz.mobi)
### Example user template template
### Example user template

# IntelliJ project files
.idea
*.iml
out
gen
### Android template
# Built application files
*.apk
*.ap_
*.aab

# Files for the ART/Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/
out/
release/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/

# Log Files
*.log

# Android Studio Navigation editor temp files
.navigation/

# Android Studio captures folder
captures/

# IntelliJ
.idea/workspace.xml
.idea/tasks.xml
.idea/gradle.xml
.idea/assetWizardSettings.xml
.idea/dictionaries
.idea/libraries
# Android Studio 3 in .gitignore file.
.idea/caches
.idea/modules.xml
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
.idea/navEditor.xml

# Keystore files
# Uncomment the following lines if you do not want to check your keystore files in.
#*.jks
#*.keystore

# External native build folder generated in Android Studio 2.2 and later
.externalNativeBuild

# Google Services (e.g. APIs or Firebase)
# google-services.json

# Freeline
freeline.py
freeline/
freeline_project_description.json

# fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# Version control
vcs.xml

# lint
lint/intermediates/
lint/generated/
lint/outputs/
lint/tmp/
# lint/reports/

### AppEngine template
# Google App Engine generated folder
appengine-generated/

19 changes: 19 additions & 0 deletions pizza-order-training.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: org.junit.jupiter:junit-jupiter-api:5.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apiguardian:apiguardian-api:1.0.0" level="project" />
<orderEntry type="library" name="Maven: org.opentest4j:opentest4j:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.junit.platform:junit-platform-commons:1.3.2" level="project" />
</component>
</module>
33 changes: 31 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,43 @@
<groupId>com.simbirsoft</groupId>
<artifactId>pizza-order-training</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.2</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/PizzaOrdertests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import model.Ingredient;
import model.Pizza;
import model.PizzaException;
import org.junit.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.util.HashMap;

public class PizzaOrdertests {
Pizza pizza;
Ingredient ingredient;
@BeforeEach
public void prepare(){
pizza = new Pizza(50,new HashMap<Ingredient, Integer>());
ingredient = new Ingredient("cheeeeess");
}
@Test()
public void addIngredient_ShouldCreatePizzs_Sucksessfull() throws PizzaException {
pizza.addIngredient(ingredient,3);
int k = pizza.getIngredients().get(ingredient);
Assertions.assertEquals(3,k);
}

@Test()
public void addIngredient_ShouldGenerateException() throws PizzaException{
Assertions.assertThrows(PizzaException.class,()->pizza.addIngredient(ingredient, -5));
}
@Test()
public void removeIngredient_ShouldGenerateException() throws PizzaException{
Assertions.assertThrows(PizzaException.class,()->pizza.removeIngredient(ingredient, -5));
}
@AfterEach
public void after(){

}
/*@Test()
public void removeIngredient_ShouldSu throws PizzaException{
Pizza pizza = new Pizza(50,new HashMap<Ingredient, Integer>());
Ingredient ingredient = new Ingredient("cheeeeess");
Assertions.assertThrows(PizzaException.class,()->pizza.removeIngredient(ingredient, -5));
}*/
}
63 changes: 31 additions & 32 deletions src/main/java/model/Pizza.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,60 @@ public Pizza() {
}

public Pizza(
int size, HashMap<Ingredient, Integer> ingredients
int size, HashMap<Ingredient, Integer> ingredients
) {
this.size = size;
this.ingredients = ingredients;
}

public void addIngredient(
Ingredient ingredient,
int count
) throws PizzaException {
public void addIngredient(Ingredient ingredient, int count) throws PizzaException {
if (ingredient != null && count > 0) {
// Проверка на существование коллекции
if (!ingredientsCollectionNotNull())
initIngredientsCollection();
// Если элемент уже существует
if (ingredients.containsKey(ingredient)) {
int alreadyExistIngredientCount = ingredients.get(
ingredient);
ingredient);
ingredients.put(
ingredient, alreadyExistIngredientCount + count);
// Если не существует
ingredient, alreadyExistIngredientCount + count);
// Если не существует
} else {
ingredients.put(ingredient, count);
}
} else
throw new PizzaException(
"Указан некорректный ингредиент или его количество");
"Указан некорректный ингредиент или его количество");
}

public void removeIngredient(
Ingredient ingredient,
int count
) throws PizzaException {
public void removeIngredient(Ingredient ingredient, int count) throws PizzaException {
if (ingredient != null && count > 0) {
// Проверка на существование коллекции
if (!ingredientsCollectionNotNull())
initIngredientsCollection();
checkIngredientsCollection();
// Если элемент уже существует
if (ingredients.containsKey(ingredient)) {
int alreadyExistIngredientCount = ingredients.get(
ingredient);
// Если количество уже существующих элементов больше либо
// равно количеству удаляемых
if (Math.abs(count) >= alreadyExistIngredientCount)
ingredients.remove(ingredient);
else
ingredients.put(
} else
throw new PizzaException(
"Указан некорректный ингредиент или его количество");
if (ingredients.containsKey(ingredient)) {
int alreadyExistIngredientCount = ingredients.get(ingredient);
int countMinusExist = count - alreadyExistIngredientCount;
if (countMinusExist == 0) {
ingredients.remove(ingredient);
} else if (countMinusExist < 0) {
ingredients.put(
ingredient, alreadyExistIngredientCount - count);
// Если элемента не сущетсвует
} else
throw new PizzaException(
"Вы пытаетесь удалить ингредиент, который не существует в пицце");
} else {
throw new PizzaException(
"Вы пытаетесь удалить большее количество ингредиента, чем содержится в пицце");
}
// Если элемента не сущетсвует
} else
throw new PizzaException(
"Указан некорректный ингредиент или его количество");
"Вы пытаетесь удалить ингредиент, который не существует в пицце");
}

private void checkIngredientsCollection() {
if (!ingredientsCollectionNotNull())
initIngredientsCollection();
}

private boolean ingredientsCollectionNotNull() {
Expand All @@ -81,7 +80,7 @@ private void initIngredientsCollection() {
ingredients = new HashMap<Ingredient, Integer>();
}

// -- Getters & Setters --
// -- Getters & Setters --

public int getSize() {
return size;
Expand All @@ -96,7 +95,7 @@ public HashMap<Ingredient, Integer> getIngredients() {
}

public void setIngredients(
HashMap<Ingredient, Integer> ingredients
HashMap<Ingredient, Integer> ingredients
) {
this.ingredients = ingredients;
}
Expand Down