diff --git a/backend/build.gradle b/backend/build.gradle index 6bde929..b7867b9 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -16,10 +16,9 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.3.0' implementation 'org.modelmapper:modelmapper:3.2.0' - // implementation 'com.fasterxml.jackson.core:jackson-databind:2.12.5' testImplementation 'org.springframework.boot:spring-boot-starter-test' } diff --git a/backend/src/test/java/com/example/backend/CategorieServiceTests.java b/backend/src/test/java/com/example/backend/CategorieServiceTests.java new file mode 100644 index 0000000..2be7e6d --- /dev/null +++ b/backend/src/test/java/com/example/backend/CategorieServiceTests.java @@ -0,0 +1,54 @@ +package com.example.backend; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +import org.junit.jupiter.api.Order; +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 com.example.backend.categories.model.CategorieEntity; +import com.example.backend.categories.service.CategorieService; +import com.example.backend.core.errors.NotFoundException; + +@SpringBootTest +@TestMethodOrder(OrderAnnotation.class) +public class CategorieServiceTests { + + @Autowired + private CategorieService categorieService; + + @Test + void getTest() { + Assertions.assertThrows(NotFoundException.class, () -> categorieService.get(0)); + } + + @Test + @Order(1) + void createTest() { + categorieService.create(new CategorieEntity(1, "Драма", "")); + final CategorieEntity lastCategorie = categorieService.create(new CategorieEntity(2, "Хоррор", "")); + Assertions.assertEquals(lastCategorie, categorieService.get(2)); + } + + @Test + @Order(2) + void update() { + final String newName = "Комедия"; + final CategorieEntity entity = categorieService.get(2); + final String oldName = entity.getName(); + final CategorieEntity newEntity = categorieService.update(2, new CategorieEntity(2, newName, "")); + Assertions.assertEquals(newName, newEntity.getName()); + Assertions.assertNotEquals(oldName, "Аниме"); + + } + + @Test + @Order(3) + void delete() { + categorieService.delete(2); + + Assertions.assertNotEquals(2, categorieService.getAll().size()); + } +}