Починил тесты для постов
This commit is contained in:
parent
2c033cd280
commit
39f8b460d1
@ -36,54 +36,54 @@ public class PostServiceTests {
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
|
||||
SimpleDateFormat dateTimeFormatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.ENGLISH);
|
||||
|
||||
final UserEntity firstUser = new UserEntity(
|
||||
null,
|
||||
"nspotapov",
|
||||
"pass123456",
|
||||
true,
|
||||
"Никита",
|
||||
"Потапов",
|
||||
dateFormatter.parse("17.02.2003"),
|
||||
"Ульяновск",
|
||||
null,
|
||||
"Я здесь админ");
|
||||
final UserEntity secondUser = new UserEntity(
|
||||
null,
|
||||
"ekallin",
|
||||
"pass87654321",
|
||||
false,
|
||||
"Елена",
|
||||
"Каллин",
|
||||
dateFormatter.parse("14.06.2005"),
|
||||
"Новоульяновск",
|
||||
null,
|
||||
null);
|
||||
final UserEntity firstUser = new UserEntity();
|
||||
firstUser.setUsername("nspotapov");
|
||||
firstUser.setPassword("pass123456");
|
||||
firstUser.setIsAdmin(true);
|
||||
firstUser.setName("Никита");
|
||||
firstUser.setSurname("Потапов");
|
||||
firstUser.setCity("Ульяновск");
|
||||
firstUser.setStatus("Я здесь админ");
|
||||
firstUser.setBirthday(dateFormatter.parse("17.02.2003"));
|
||||
|
||||
final PostEntity firstPost = postService
|
||||
.create(new PostEntity(
|
||||
null,
|
||||
firstUser,
|
||||
dateTimeFormatter.parse("01.04.2024, 17:02:34"),
|
||||
null, "Первый тестовый пост"));
|
||||
final UserEntity secondUser = new UserEntity();
|
||||
secondUser.setUsername("ekallin");
|
||||
secondUser.setPassword("pass87654321");
|
||||
secondUser.setIsAdmin(false);
|
||||
secondUser.setName("Елена");
|
||||
secondUser.setSurname("Каллин");
|
||||
secondUser.setCity("Новоульяновск");
|
||||
secondUser.setBirthday(dateFormatter.parse("14.06.2005"));
|
||||
|
||||
postService.create(new PostEntity(
|
||||
null,
|
||||
firstUser,
|
||||
dateTimeFormatter.parse("22.03.2024, 09:34:01"),
|
||||
"myimage.jpg", "Второй тестовый пост"));
|
||||
PostEntity firstPost = new PostEntity();
|
||||
firstPost.setUser(firstUser);
|
||||
firstPost.setPubDate(dateTimeFormatter.parse("01.04.2024, 17:02:34"));
|
||||
firstPost.setHtml("Первый тестовый пост");
|
||||
|
||||
postService.create(new PostEntity(
|
||||
null,
|
||||
secondUser,
|
||||
dateTimeFormatter.parse("13.02.2024, 18:01:01"),
|
||||
"ohmypost.jpg", "Первый постовый пост"));
|
||||
firstPost = postService.create(firstPost);
|
||||
|
||||
Assertions.assertThrows(BadRequestException.class, () -> postService
|
||||
.create(new PostEntity(
|
||||
null,
|
||||
secondUser,
|
||||
dateTimeFormatter.parse("13.02.2024, 18:01:01"),
|
||||
null, null)));
|
||||
PostEntity secondPost = new PostEntity();
|
||||
secondPost.setUser(firstUser);
|
||||
secondPost.setPubDate(dateTimeFormatter.parse("22.03.2024, 09:34:01"));
|
||||
secondPost.setImage("myimage.jpg");
|
||||
secondPost.setHtml("Второй тестовый пост");
|
||||
|
||||
postService.create(secondPost);
|
||||
|
||||
PostEntity thirdPost = new PostEntity();
|
||||
thirdPost.setUser(secondUser);
|
||||
thirdPost.setPubDate(dateTimeFormatter.parse("13.02.2024, 18:01:01"));
|
||||
thirdPost.setImage("ohmypost.jpg");
|
||||
thirdPost.setHtml("Третий постовый пост");
|
||||
|
||||
postService.create(thirdPost);
|
||||
|
||||
PostEntity fourthPost = new PostEntity();
|
||||
fourthPost.setUser(secondUser);
|
||||
fourthPost.setPubDate(dateTimeFormatter.parse("13.02.2024, 18:01:01"));
|
||||
|
||||
Assertions.assertThrows(BadRequestException.class,
|
||||
() -> postService.create(fourthPost));
|
||||
|
||||
Assertions.assertEquals(firstPost, postService.get(1));
|
||||
Assertions.assertEquals(firstUser, postService.get(1).getUser());
|
||||
@ -98,36 +98,36 @@ public class PostServiceTests {
|
||||
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd.MM.yyyy", Locale.ENGLISH);
|
||||
SimpleDateFormat dateTimeFormatter = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.ENGLISH);
|
||||
|
||||
final UserEntity firstUser = new UserEntity(
|
||||
null,
|
||||
"nspotapov",
|
||||
"pass123456",
|
||||
true,
|
||||
"Никита",
|
||||
"Потапов",
|
||||
dateFormatter.parse("17.02.2003"),
|
||||
"Ульяновск",
|
||||
null,
|
||||
"Я здесь админ");
|
||||
final UserEntity firstUser = new UserEntity();
|
||||
firstUser.setUsername("nspotapov");
|
||||
firstUser.setPassword("pass123456");
|
||||
firstUser.setIsAdmin(true);
|
||||
firstUser.setName("Никита");
|
||||
firstUser.setSurname("Потапов");
|
||||
firstUser.setCity("Ульяновск");
|
||||
firstUser.setStatus("Я здесь админ");
|
||||
firstUser.setBirthday(dateFormatter.parse("17.02.2003"));
|
||||
|
||||
postService.create(new PostEntity(
|
||||
null,
|
||||
firstUser,
|
||||
dateTimeFormatter.parse("01.04.2024, 17:02:34"),
|
||||
null, "Первый тестовый пост"));
|
||||
PostEntity firstPost = new PostEntity();
|
||||
firstPost.setUser(firstUser);
|
||||
firstPost.setPubDate(dateTimeFormatter.parse("01.04.2024, 17:02:34"));
|
||||
firstPost.setHtml("Первый тестовый пост");
|
||||
|
||||
firstPost = postService.create(firstPost);
|
||||
|
||||
Integer postId = 1;
|
||||
PostEntity oldPost = postService.get(postId);
|
||||
String oldImage = oldPost.getImage();
|
||||
PostEntity newPost = new PostEntity(
|
||||
oldPost.getId(),
|
||||
oldPost.getUser(),
|
||||
oldPost.getPubDate(),
|
||||
"new image",
|
||||
oldPost.getHtml());
|
||||
|
||||
PostEntity newPost = new PostEntity();
|
||||
newPost.setId(oldPost.getId());
|
||||
newPost.setUser(oldPost.getUser());
|
||||
newPost.setPubDate(oldPost.getPubDate());
|
||||
newPost.setImage("new image");
|
||||
newPost.setHtml(oldPost.getHtml());
|
||||
|
||||
postService.update(postId, newPost);
|
||||
Assertions.assertNotEquals(
|
||||
postService.get(postId).getImage(), oldImage);
|
||||
Assertions.assertNotEquals(postService.get(postId).getImage(), oldImage);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user