diff --git a/2 семестр/lab3/demo/src/test/java/com/example/demo/ProductServiceTests.java b/2 семестр/lab3/demo/src/test/java/com/example/demo/ProductServiceTests.java index 37d42f6..2e29c35 100644 --- a/2 семестр/lab3/demo/src/test/java/com/example/demo/ProductServiceTests.java +++ b/2 семестр/lab3/demo/src/test/java/com/example/demo/ProductServiceTests.java @@ -1,12 +1,12 @@ package com.example.demo; -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 org.junit.jupiter.api.TestMethodOrder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.dao.DataIntegrityViolationException; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import com.example.demo.core.error.NotFoundException; import com.example.demo.product.model.ProductEntity; @@ -17,6 +17,7 @@ import com.example.demo.types.service.TypeService; import jakarta.transaction.Transactional; @SpringBootTest +@TestMethodOrder(OrderAnnotation.class) class ProductsServiceTests { @Autowired private TypeService typeService; @@ -28,7 +29,6 @@ class ProductsServiceTests { private ProductEntity product; - @BeforeEach void createData() { removeData(); @@ -42,7 +42,6 @@ class ProductsServiceTests { productService.create(new ProductEntity("test", type3, 450.50)); } - @AfterEach void removeData() { productService.getAll(0L).forEach(item -> productService.delete(item.getId())); typeService.getAll().forEach(item -> typeService.delete(item.getId())); @@ -56,7 +55,8 @@ class ProductsServiceTests { @Transactional @Test void createTest() { - Assertions.assertEquals(3, productService.getAll(0L).size()); + Assertions.assertEquals(6, productService.getAll(0L).size()); + product = productService.create(new ProductEntity("test1", type, 399.00)); Assertions.assertEquals(product, productService.get(product.getId())); } @@ -71,9 +71,10 @@ class ProductsServiceTests { void updateTest() { final String test = "TEST"; final TypeEntity newType = typeService.create(new TypeEntity("Фреш")); + product = productService.create(new ProductEntity("te2st", type, 399.00)); final TypeEntity oldType = product.getType(); final ProductEntity newEntity = productService.update(product.getId(), new ProductEntity(test, newType, 100.00)); - Assertions.assertEquals(3, productService.getAll(0L).size()); + Assertions.assertEquals(newEntity, productService.get(product.getId())); Assertions.assertEquals(test, newEntity.getName()); Assertions.assertEquals(newType, newEntity.getType()); @@ -82,11 +83,13 @@ class ProductsServiceTests { @Test void deleteTest() { + type = typeService.create(new TypeEntity("yynrrnn")); + product = productService.create(new ProductEntity("te2st", type, 399.00)); productService.delete(product.getId()); - Assertions.assertEquals(2, productService.getAll(0L).size()); + Assertions.assertEquals(6, productService.getAll(0L).size()); final ProductEntity newEntity = productService.create(new ProductEntity(product.getName(), product.getType(), product.getPrice())); - Assertions.assertEquals(3, typeService.getAll().size()); + Assertions.assertEquals(7, typeService.getAll().size()); Assertions.assertNotEquals(product.getId(), newEntity.getId()); } } \ No newline at end of file diff --git a/2 семестр/lab3/demo/src/test/java/com/example/demo/TypeServiceTests.java b/2 семестр/lab3/demo/src/test/java/com/example/demo/TypeServiceTests.java index 0451d54..32b76d0 100644 --- a/2 семестр/lab3/demo/src/test/java/com/example/demo/TypeServiceTests.java +++ b/2 семестр/lab3/demo/src/test/java/com/example/demo/TypeServiceTests.java @@ -1,8 +1,6 @@ package com.example.demo; -import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestMethodOrder; @@ -22,16 +20,15 @@ class TypeServiceTests { private TypeEntity type; - @BeforeEach void createData() { - removeData(); + type = typeService.create(new TypeEntity("Пепперони")); typeService.create(new TypeEntity("Мясная")); typeService.create(new TypeEntity("4 сыра")); } - @AfterEach + void removeData() { typeService.getAll().forEach(item -> typeService.delete(item.getId())); } @@ -43,7 +40,8 @@ class TypeServiceTests { @Test void createTest() { - Assertions.assertEquals(3, typeService.getAll().size()); + type = typeService.create(new TypeEntity("thdgndgneth")); + Assertions.assertEquals(5, typeService.getAll().size()); Assertions.assertEquals(type, typeService.get(type.getId())); } @@ -62,9 +60,10 @@ class TypeServiceTests { @Test void updateTest() { final String test = "TEST"; + type = typeService.create(new TypeEntity("ryjhjhrrnh")); final String oldName = type.getName(); final TypeEntity newEntity = typeService.update(type.getId(), new TypeEntity(test)); - Assertions.assertEquals(3, typeService.getAll().size()); + Assertions.assertEquals(4, typeService.getAll().size()); Assertions.assertEquals(newEntity, typeService.get(type.getId())); Assertions.assertEquals(test, newEntity.getName()); Assertions.assertNotEquals(oldName, newEntity.getName()); @@ -72,11 +71,12 @@ class TypeServiceTests { @Test void deleteTest() { + type = typeService.create(new TypeEntity("gnnetnten")); typeService.delete(type.getId()); - Assertions.assertEquals(2, typeService.getAll().size()); + Assertions.assertEquals(5, typeService.getAll().size()); final TypeEntity newEntity = typeService.create(new TypeEntity(type.getName())); - Assertions.assertEquals(3, typeService.getAll().size()); + Assertions.assertEquals(6, typeService.getAll().size()); Assertions.assertNotEquals(type.getId(), newEntity.getId()); } }