generator.server.pagination.domain.test.AppPageTest.mustache Maven / Gradle / Ivy
package {{packageName}}.shared.pagination.domain;
import static org.assertj.core.api.Assertions.*;
import static {{packageName}}.shared.pagination.domain.{{baseName}}PagesFixture.*;
import java.util.List;
import org.junit.jupiter.api.Test;
import {{packageName}}.UnitTest;
import {{packageName}}.shared.error.domain.MissingMandatoryValueException;
@UnitTest
class {{baseName}}PageTest {
@Test
void shouldGetEmptySinglePageWithoutContent() {
{{baseName}}Page page = {{baseName}}Page.singlePage(null);
assertEmptyPage(page);
}
@Test
void shouldGetEmptySinglePageFromBuilderWithoutContent() {
{{baseName}}Page> page = {{baseName}}Page.builder(null).build();
assertEmptyPage(page);
}
private void assertEmptyPage({{baseName}}Page> page) {
assertThat(page.content()).isEmpty();
assertThat(page.currentPage()).isZero();
assertThat(page.pageSize()).isZero();
assertThat(page.totalElementsCount()).isZero();
}
@Test
void shouldGetSinglePage() {
{{baseName}}Page page = {{baseName}}Page.singlePage(List.of("test", "dummy"));
assertSinglePage(page);
}
@Test
void shouldGetSinglePageFromBuilderWithContentOnly() {
{{baseName}}Page page = {{baseName}}Page.builder(List.of("test", "dummy")).build();
assertSinglePage(page);
}
private void assertSinglePage({{baseName}}Page page) {
assertThat(page.content()).containsExactly("test", "dummy");
assertThat(page.currentPage()).isZero();
assertThat(page.pageSize()).isEqualTo(2);
assertThat(page.totalElementsCount()).isEqualTo(2);
assertThat(page.pageCount()).isEqualTo(1);
}
@Test
void shouldGetFullPage() {
{{baseName}}Page page = pageBuilder().build();
assertThat(page.content()).containsExactly("test");
assertThat(page.currentPage()).isEqualTo(2);
assertThat(page.pageSize()).isEqualTo(10);
assertThat(page.totalElementsCount()).isEqualTo(21);
assertThat(page.pageCount()).isEqualTo(3);
}
@Test
void shouldNotMapWithoutMapper() {
assertThatThrownBy(() -> pageBuilder().build().map(null))
.isExactlyInstanceOf(MissingMandatoryValueException.class)
.hasMessageContaining("mapper");
}
@Test
void shouldMapPage() {
{{baseName}}Page page = pageBuilder().build().map(entry -> "hey");
assertThat(page.content()).containsExactly("hey");
assertThat(page.currentPage()).isEqualTo(2);
assertThat(page.pageSize()).isEqualTo(10);
assertThat(page.totalElementsCount()).isEqualTo(21);
assertThat(page.pageCount()).isEqualTo(3);
}
@Test
void shouldNotBeLastForFirstPage() {
assertThat(pageBuilder().currentPage(0).build().isNotLast()).isTrue();
}
@Test
void shouldBeLastWithOnePage() {
assertThat({{baseName}}Page.singlePage(List.of("d")).isNotLast()).isFalse();
}
@Test
void shouldBeLastPageWithoutContent() {
{{baseName}}Page