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