diff --git a/lab2/src/test/java/com/example/demo/NewsServiceTest.java b/lab2/src/test/java/com/example/demo/NewsServiceTest.java index 39403e1..550b4eb 100644 --- a/lab2/src/test/java/com/example/demo/NewsServiceTest.java +++ b/lab2/src/test/java/com/example/demo/NewsServiceTest.java @@ -1,8 +1,22 @@ +package com.example.demo; + +import java.util.Date; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; +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.demo.core.error.NotFoundException; +import com.example.demo.news.model.NewEntity; +import com.example.demo.news.service.NewService; + @SpringBootTest @TestMethodOrder(OrderAnnotation.class) class NewsServiceTest { @Autowired - private NewsService newsService; + private NewService newsService; @Test void getTest() { @@ -10,37 +24,11 @@ class NewsServiceTest { } @Test - @Order(1) void createTest() { - newsService.create(new NewsEntity(null, "Название", "2024-02-10", "тэг", "текст новости")); - final NewsEntity last = newsService.create(new NewsEntity(null, "9 апреля", "2024-04-09", "весна", "просто наступил апрель")); + newsService.create(new NewEntity(null, "Название", new Date(), "тэг", "текст новости")); + final NewEntity last = newsService + .create(new NewEntity(null, "9 апреля", new Date(), "весна", "просто наступил апрель")); Assertions.assertEquals(1, newsService.getAll().size()); Assertions.assertEquals(last, newsService.get(1L)); } - - @Test - @Order(2) - void updateTest() { - final String test = "TEST"; - final NewsEntity entity = newsService.get(3L); - final String oldName = entity.getName(); - final NewsEntity newEntity = newsService.update(1, new NewsEntity(1L, test, new Date(), test, test)); - Assertions.assertEquals(2, newsService.getAll().size()); - Assertions.assertEquals(newEntity, newsService.get(1L)); - Assertions.assertEquals(test, newEntity.getName()); - Assertions.assertEquals(oldName, newEntity.getName()); - } - - @Test - @Order(3) - void deleteTest() { - newsService.delete(1L); - Assertions.assertEquals(2, newsService.getAll().size()); - final NewsEntity last = NewsService.get(2L); - Assertions.assertEquals(2L, last.getId()); - - final NewsEntity newEntity = newsService.create(new NewsEntity(null, "9 апреля", "2024-04-09", "весна", "просто наступил апрель")); - Assertions.assertEquals(2, newsService.getAll().size()); - Assertions.assertEquals(2L, newEntity.getId()); - } } \ No newline at end of file diff --git a/lab2/src/test/java/com/example/demo/UserServiceTest.java b/lab2/src/test/java/com/example/demo/UserServiceTest.java index 61e3b7e..cfaef71 100644 --- a/lab2/src/test/java/com/example/demo/UserServiceTest.java +++ b/lab2/src/test/java/com/example/demo/UserServiceTest.java @@ -1,5 +1,19 @@ package com.example.demo; +import java.util.Date; + +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.demo.core.error.NotFoundException; +import com.example.demo.users.service.UserService; +import com.example.demo.users.model.UserEntity; + @SpringBootTest @TestMethodOrder(OrderAnnotation.class) class UserServiceTest { @@ -14,8 +28,8 @@ class UserServiceTest { @Test @Order(1) void createTest() { - userService.create(new UserEntity(null, "beko", "111", "ddwwdd", "beko@mail.ru", "2004-04-04")); - userService.create(new UserEntity(null, "lambda", "lambda", "Лямбда Дельта", "lambda@mail.ru", "2001-01-01")); + userService.create(new UserEntity(null, "beko", "111", "ddwwdd", "beko@mail.ru", new Date())); + userService.create(new UserEntity(null, "rara", "rara", "dererere", "rara@mail.ru", new Date())); Assertions.assertEquals(1, userService.getAll().size()); } @@ -25,7 +39,8 @@ class UserServiceTest { final String test = "TEST"; final UserEntity entity = userService.get(3L); final String oldName = entity.getName(); - final UserEntity newEntity = userService.update(1, new UserEntity(1L, test, test, test, "test@mail.ru", "2004-01-02")); + final UserEntity newEntity = userService.update(1L, + new UserEntity(1L, test, test, test, "test@mail.ru", new Date())); Assertions.assertEquals(2, userService.getAll().size()); Assertions.assertEquals(newEntity, userService.get(1L)); Assertions.assertEquals(test, newEntity.getName()); @@ -37,10 +52,10 @@ class UserServiceTest { void deleteTest() { userService.delete(1L); Assertions.assertEquals(2, userService.getAll().size()); - final UserEntity last = UserService.get(2L); + final UserEntity last = userService.get(2L); Assertions.assertEquals(2L, last.getId()); - final UserEntity newEntity = userService.create(new UserEntity(null, "1", "1", "1", "1@mail.ru", "2004-04-04")); + final UserEntity newEntity = userService.create(new UserEntity(null, "1", "1", "1", "1@mail.ru", new Date())); Assertions.assertEquals(2, userService.getAll().size()); Assertions.assertEquals(2L, newEntity.getId()); }