From 7406e766e71ddef5d538f08919112c449e26ccd3 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Fri, 7 Jun 2024 18:20:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BE=D0=BD=D0=BE=20=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=D0=B5=D1=82!!!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DemoApplicationTests/CustomerTests.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 demo/src/test/java/com/example/demo/DemoApplicationTests/CustomerTests.java diff --git a/demo/src/test/java/com/example/demo/DemoApplicationTests/CustomerTests.java b/demo/src/test/java/com/example/demo/DemoApplicationTests/CustomerTests.java new file mode 100644 index 0000000..01c9493 --- /dev/null +++ b/demo/src/test/java/com/example/demo/DemoApplicationTests/CustomerTests.java @@ -0,0 +1,63 @@ +package com.example.demo.DemoApplicationTests; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.ArrayList; + + @SpringBootTest + class PostsServiceTest { + @Autowired + private PostService newsService; + + @Autowired + private TageService tageService; + + List tages = new ArrayList<>(); + + @AfterEach + void removeData() { + newsService.getAll().forEach(item -> newsService.delete(item.getId())); + tageService.getAll().forEach(i -> tageService.delete(i.getId())); + } + + @Test + void getTest() { + Assertions.assertThrows(NotFoundException.class, () -> newsService.get(0L)); + } + + @Test + void CreateUpdateDelete() { + //create + removeData(); + + var tage1 = tageService.create(new TageEntity("праздник")); + var tage2 = tageService.create(new TageEntity("сессия")); + tages.add(tage1); + tages.add(tage2); + + // create + var post1 = newsService.create(new PostEntity( + "Название", new Date(), "текст новости", tages)); + var post2 = newsService.create(new PostEntity( + "9 апреля", new Date(), "просто наступил апрель", tages)); + + Assertions.assertEquals(2L, newsService.getAll().size()); + + //update + var post2new = newsService.update(post2.getId(), new PostEntity( + "2 июня", new Date(), "просто наступил ИЮНЬ" + )); + Assertions.assertEquals(2L, newsService.getAll().size()); + + // delete + newsService.delete(post2new.getId()); + Assertions.assertEquals(1L, newsService.getAll().size()); + final var lastNew = newsService.get(post1.getId()); + Assertions.assertEquals(lastNew.getText(), post1.getText()); + } + } +}