From 46bed7c28a5df7add8f52730d87712bde13e29c5 Mon Sep 17 00:00:00 2001 From: Alessandro Iezzi Date: Wed, 30 Nov 2022 16:10:25 +0100 Subject: Add whole directory --- .../commons/page/ExampleUnitTest.java | 36 +++++++++++++ .../commons/page/PageAdapterUnitTest.java | 61 ++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 src/test/java/it/alessandroiezzi/commons/page/ExampleUnitTest.java create mode 100644 src/test/java/it/alessandroiezzi/commons/page/PageAdapterUnitTest.java (limited to 'src/test') diff --git a/src/test/java/it/alessandroiezzi/commons/page/ExampleUnitTest.java b/src/test/java/it/alessandroiezzi/commons/page/ExampleUnitTest.java new file mode 100644 index 0000000..ae6692d --- /dev/null +++ b/src/test/java/it/alessandroiezzi/commons/page/ExampleUnitTest.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 Alessandro Iezzi + * + * This file is part of commons-page. + * + * commons-page is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * commons-page is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with commons-page. If not, see . + */ + +package it.alessandroiezzi.commons.page; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/src/test/java/it/alessandroiezzi/commons/page/PageAdapterUnitTest.java b/src/test/java/it/alessandroiezzi/commons/page/PageAdapterUnitTest.java new file mode 100644 index 0000000..65b880d --- /dev/null +++ b/src/test/java/it/alessandroiezzi/commons/page/PageAdapterUnitTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2022 Alessandro Iezzi + * + * This file is part of commons-page. + * + * commons-page is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * commons-page is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with commons-page. If not, see . + */ + +package it.alessandroiezzi.commons.page; + +import org.junit.*; + +import java.util.*; + +import static org.junit.Assert.*; + +public class PageAdapterUnitTest { + @Test + public void test() { + int max = 48; + List integers = new ArrayList<>(); + for (int i = 1; i < max; i++) { + integers.add(i); + } + Pages pages = new PageAdapter<>(integers); + assertEquals(4, pages.getTotalPages()); + + int i = 0; + for (Integer integer : pages.firstPage().getContent()) { + assertEquals(++i, (int) integer); + } + assertEquals(i, 15); + + for (Integer integer : pages.lastPage().getContent()) { +// System.out.println(integer); + } + + for (int j = max; j < max + 13; j++) { + pages.addElement(j); + } + pages.removeElementIf((e) -> e > 0 && e < 58); + for (Integer integer : pages.lastPage().getContent()) { + System.out.println(integer); + } + System.out.println(); + for (Integer integer : pages.firstPage().getContent()) { + System.out.println(integer); + } + } +} \ No newline at end of file -- cgit v1.2.3