/
skonoplich
/
domainmodelling-java
Обзор
Документация
Войти
/
skonoplich
/
domainmodelling-java
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
domainintegrationtests/src/test/java/o/e/domainmodelling/cases/RegistriesLinkedWithDomainStateTest.java
78 строк
3 KB
sk
skeleton
07 сен 2025, 15:48
07 сен 2025, 15:48
de79d2a
Код
Авторство
О чём код?
package o.e.domainmodelling.cases; import o.e.domainmodelling.library.Library; import o.e.domainmodelling.library.LibraryProperties; import o.e.domainmodelling.library.bootstrap.LibraryFactory; import o.e.domainmodelling.library.dto.CreateBookInstanceParams; import o.e.domainmodelling.library.dto.CreateBookParams; import o.e.domainmodelling.library.entity.Author; import o.e.domainmodelling.library.entity.Book; import o.e.domainmodelling.library.entity.BookInstance; import o.e.domainmodelling.util.EntitiesUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class RegistriesLinkedWithDomainStateTest { private final LibraryProperties libraryProperties = new LibraryProperties(); private final Library library = new LibraryFactory().createLibrary(libraryProperties); @Test void registryBookCreationsAffectsAuthorCheckSameness() { Author author = EntitiesUtils.createAuthor(library, "author"); CreateBookParams params = CreateBookParams.builder(author, "book").build(); Book book = library.books().create(params); Assertions.assertSame(book, author.getBooks().get(0)); } @Test void registryBookCreationsAffectsAuthorCheckCount() { Author author = EntitiesUtils.createAuthor(library, "author"); CreateBookParams firstBookParams = CreateBookParams.builder(author, "book1").build(); CreateBookParams secondBookParams = CreateBookParams.builder(author, "book2").build(); CreateBookParams thirdBookParams = CreateBookParams.builder(author, "book3").build(); library.books().create(firstBookParams); library.books().create(secondBookParams); library.books().create(thirdBookParams); Assertions.assertSame(3, author.getBooks().size()); } @Test void registryInstanceCreationAffectsBookCheckSameness() { Author author = EntitiesUtils.createAuthor(library, "author"); CreateBookParams bookParams = CreateBookParams.builder(author, "book").build(); Book book = library.books().create(bookParams); CreateBookInstanceParams bookInstanceParams = CreateBookInstanceParams.builder(book).build(); BookInstance bookInstance = library.bookInstances().create(bookInstanceParams); Assertions.assertSame(bookInstance, book.getInstances().get(0)); } @Test void registryInstanceCreationAffectsBookCheckCount() { Author author = EntitiesUtils.createAuthor(library, "author"); CreateBookParams bookParams = CreateBookParams.builder(author, "book").build(); Book book = library.books().create(bookParams); CreateBookInstanceParams firstInstanceParams = CreateBookInstanceParams.builder(book).build(); CreateBookInstanceParams secondInstanceParams = CreateBookInstanceParams.builder(book).build(); CreateBookInstanceParams thirdInstanceParams = CreateBookInstanceParams.builder(book).build(); library.bookInstances().create(firstInstanceParams); library.bookInstances().create(secondInstanceParams); library.bookInstances().create(thirdInstanceParams); Assertions.assertSame(3, book.getInstances().size()); } }