тесты для категорий
This commit is contained in:
parent
980a89897f
commit
8fed6a12ef
@ -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'
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user