Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop1 #889

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,64 @@
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-surefire-plugin -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<!--Mockito-->
<!-- <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.2.0</version>
<scope>test</scope>
</dependency>-->

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.12.4</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<!--id выбираешь самостоятельно-->
<id>prepare-agent</id>
<!--в какой фазе maven будет выполняться цель-->
<phase>initialize</phase>
<!--цель jacoco, которую нужно выполнить-->
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
9 changes: 9 additions & 0 deletions praktikum.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="AdditionalModuleElements">
<content url="file://$MODULE_DIR$" dumb="true">
<sourceFolder url="file://$MODULE_DIR$/src/main/test" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/test/resources" type="java-resource" />
</content>
</component>
</module>
24 changes: 24 additions & 0 deletions src/main/test/java/praktikum/BunTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package praktikum;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;


@RunWith(MockitoJUnitRunner.class)
public class BunTest {
static float delta = 0.0f;

@Test
public void getNameTest() {
Bun bun = new Bun("test", 2.5f);
Assert.assertEquals("test", bun.getName());
}

@Test
public void getPriceTest() {
Bun bun = new Bun("test", 0.23f);
Assert.assertEquals(0.23f, bun.getPrice(), delta);
}
}
84 changes: 84 additions & 0 deletions src/main/test/java/praktikum/BurgerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package praktikum;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
public class BurgerTest {
Burger burger = new Burger();
String expected = null;

@Mock
Bun bunMock;
@Mock
Ingredient ingredientMock;
@Mock
Ingredient sauceMock;
//Burger burger = new Burger();

@Test
public void setBunsTest() {
burger.setBuns(bunMock);
burger.bun.getName();
Mockito.verify(bunMock).getName();
Assert.assertEquals(expected,burger.bun.getName());
}

@Test
public void addIngredientTest() {
burger.addIngredient(ingredientMock);
burger.ingredients.get(0).getName();
Mockito.verify(ingredientMock).getName();
Assert.assertEquals(expected, burger.ingredients.get(0).getName());
}

@Test
public void removeIngredientTest() {
burger.addIngredient(ingredientMock);
burger.addIngredient(sauceMock);
burger.removeIngredient(0);
burger.ingredients.get(0).getName();
Mockito.verify(sauceMock).getName();
Assert.assertEquals(expected, burger.ingredients.get(0).getName());
}

@Test
public void moveIngredientTest() {
burger.addIngredient(ingredientMock);
burger.addIngredient(sauceMock);
burger.moveIngredient(0,1);
burger.ingredients.get(0).getName();
Mockito.verify(sauceMock).getName();
Assert.assertEquals(expected, burger.ingredients.get(0).getName());
}

@Test
public void getReceipt() {
burger.setBuns(bunMock);
burger.addIngredient(ingredientMock);
burger.addIngredient(sauceMock);
Mockito.when(bunMock.getName()).thenReturn("test");
Mockito.when(bunMock.getPrice()).thenReturn(0.23F);
Mockito.when(ingredientMock.getName()).thenReturn("test");
Mockito.when(ingredientMock.getPrice()).thenReturn(0.1F);
Mockito.when(ingredientMock.getType()).thenReturn(IngredientType.FILLING);
Mockito.when(sauceMock.getName()).thenReturn("chili");
Mockito.when(sauceMock.getPrice()).thenReturn(0.02F);
Mockito.when(sauceMock.getType()).thenReturn(IngredientType.SAUCE);

burger.getReceipt();
Mockito.verify(bunMock, Mockito.times(2)).getName();
Mockito.verify(ingredientMock).getName();
Mockito.verify(ingredientMock).getType();
Mockito.verify(sauceMock).getName();
Mockito.verify(sauceMock).getType();
Assert.assertEquals("test", ingredientMock.getName());
Assert.assertEquals(IngredientType.FILLING, ingredientMock.getType());
Assert.assertEquals("chili", sauceMock.getName());
Assert.assertEquals(IngredientType.SAUCE, sauceMock.getType());
}
}
Loading