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
36 changes: 36 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
target/*
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
!target/site/

### IntelliJ IDEA ###
.idea/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
130 changes: 129 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,134 @@
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<allure.version>2.29.1</allure.version>
</properties>

</project>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>5.5.6</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.15.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit4</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<version>0.8.13</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.20.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.16</version>
<scope>test</scope>
</dependency>
<!-- Добавляем AssertJ для SoftAssertions -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.26.3</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<systemPropertyVariables>
<allure.results.directory>target/allure-results</allure.results.directory>
</systemPropertyVariables>
<argLine>@{argLine}</argLine>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.13</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-maven</artifactId>
<version>2.12.0</version>
<configuration>
<reportVersion>${allure.version}</reportVersion>
<resultsDirectory>target/allure-results</resultsDirectory>
</configuration>
<executions>
<execution>
<id>allure-report</id>
<phase>site</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
10 changes: 6 additions & 4 deletions src/main/java/praktikum/Burger.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.util.ArrayList;
import java.util.List;

import java.util.Locale;

/**
* Модель бургера.
* Бургер состоит из булочек и ингредиентов (начинка или соус).
Expand Down Expand Up @@ -41,15 +43,15 @@ public float getPrice() {
}

public String getReceipt() {
StringBuilder receipt = new StringBuilder(String.format("(==== %s ====)%n", bun.getName()));
StringBuilder receipt = new StringBuilder(String.format(Locale.US, "(==== %s ====)%n", bun.getName()));

for (Ingredient ingredient : ingredients) {
receipt.append(String.format("= %s %s =%n", ingredient.getType().toString().toLowerCase(),
receipt.append(String.format(Locale.US, "= %s %s =%n", ingredient.getType().toString().toLowerCase(),
ingredient.getName()));
}

receipt.append(String.format("(==== %s ====)%n", bun.getName()));
receipt.append(String.format("%nPrice: %f%n", getPrice()));
receipt.append(String.format(Locale.US, "(==== %s ====)%n", bun.getName()));
receipt.append(String.format(Locale.US, "%nPrice: %f%n", getPrice()));

return receipt.toString();
}
Expand Down
104 changes: 104 additions & 0 deletions src/test/java/praktikum/tests/BurgerSimpleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package praktikum.tests;

import org.assertj.core.api.SoftAssertions;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import praktikum.Burger;
import praktikum.Bun;
import praktikum.Ingredient;
import praktikum.IngredientType;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

public class BurgerSimpleTest {

private Burger burger;

@Mock
private Bun bun;

@Mock
private Ingredient firstIngredient;

@Mock
private Ingredient secondIngredient;

@Before
public void setUp() {
MockitoAnnotations.openMocks(this);
burger = new Burger();
}

@Test
public void testSetBuns() {
when(bun.getName()).thenReturn("black bun");
when(bun.getPrice()).thenReturn(100.0f);

burger.setBuns(bun);

assertEquals("Bun should be set correctly", bun, burger.bun);
}

@Test
public void testAddIngredient() {
SoftAssertions softly = new SoftAssertions();
when(firstIngredient.getName()).thenReturn("hot sauce");
when(firstIngredient.getPrice()).thenReturn(50.0f);
when(firstIngredient.getType()).thenReturn(IngredientType.SAUCE);

burger.addIngredient(firstIngredient);

softly.assertThat(burger.ingredients).hasSize(1);
softly.assertThat(burger.ingredients.get(0)).isEqualTo(firstIngredient);
softly.assertAll();
}

@Test
public void testRemoveIngredient() {
burger.ingredients.add(firstIngredient);
burger.removeIngredient(0);
assertTrue("Ingredients list should be empty after removal", burger.ingredients.isEmpty());
}

@Test(expected = IndexOutOfBoundsException.class)
public void testRemoveIngredientInvalidIndex() {
burger.removeIngredient(0); // Should throw IndexOutOfBoundsException
}

@Test
public void testMoveIngredient() {
SoftAssertions softly = new SoftAssertions();
when(firstIngredient.getName()).thenReturn("sauce");
when(secondIngredient.getName()).thenReturn("filling");

burger.ingredients.add(firstIngredient);
burger.ingredients.add(secondIngredient);

burger.moveIngredient(0, 1);

softly.assertThat(burger.ingredients.get(0)).isEqualTo(secondIngredient);
softly.assertThat(burger.ingredients.get(1)).isEqualTo(firstIngredient);
softly.assertAll();
}

@Test(expected = IndexOutOfBoundsException.class)
public void testMoveIngredientInvalidIndex() {
burger.moveIngredient(0, 0); // Should throw IndexOutOfBoundsException
}

@Test(expected = NullPointerException.class)
public void testGetPriceWithNullBun() {
burger.setBuns(null);
burger.getPrice(); // Should throw NullPointerException
}

@Test(expected = NullPointerException.class)
public void testGetReceiptWithNullBun() {
burger.setBuns(null);
burger.getReceipt(); // Should throw NullPointerException
}
}
Loading