-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1336 from scireum/feature/smo/migrate-page-test
JUNIT: Migrating PageTest to Kotlin
- Loading branch information
Showing
2 changed files
with
88 additions
and
99 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Made with all the love in the world | ||
* by scireum in Remshalden, Germany | ||
* | ||
* Copyright by scireum GmbH | ||
* http://www.scireum.de - info@scireum.de | ||
*/ | ||
|
||
|
||
package sirius.web.controller | ||
|
||
import spock.lang.Specification | ||
import java.awt.Stroke | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertFalse | ||
|
||
class PageTest { | ||
|
||
@Test | ||
fun `linkToPageWithConfigurableStart() returns 'start=' if no filters are set`() { | ||
val page: Page<String> = Page() | ||
val result = page.linkToPageWithConfigurableStart("/test") | ||
assertEquals("/test?start=", result) | ||
} | ||
|
||
@Test | ||
fun `linkToCurrentPage() works with an URI that already contains a query string`() { | ||
val page: Page<String> = Page() | ||
page.withQuery("QUERY").withFacets( | ||
listOf( | ||
Facet("", "field1", "value1", null), | ||
Facet("", "field2", "value2", null) | ||
) | ||
) | ||
val result = page.linkToCurrentPage("/test?hallo=welt") | ||
assertEquals("/test?hallo=welt&query=QUERY&field1=value1&field2=value2", result) | ||
} | ||
|
||
@Test | ||
fun `linkToPageWithConfigurableStart() returns a valid query string ending with start=`() { | ||
val page: Page<String> = Page() | ||
page.withQuery("QUERY").withFacets( | ||
listOf( | ||
Facet("", "field1", "value1", null), | ||
Facet("", "field2", "value2", null) | ||
) | ||
) | ||
val result = page.linkToPageWithConfigurableStart("/test") | ||
result.contains("field1=value1&") | ||
result.contains("field2=value2&") | ||
result.contains("query=QUERY&") | ||
result.endsWith("&start=") | ||
} | ||
|
||
@Test | ||
fun `withLimitedItemsSupplier() removes elements which exceed the page size`() { | ||
val limitPage = Page<String>().withPageSize(5) | ||
val elementsList = ArrayList<String>() | ||
elementsList.add("1") | ||
elementsList.add("2") | ||
elementsList.add("3") | ||
elementsList.add("4") | ||
elementsList.add("5") | ||
elementsList.add("6") | ||
elementsList.add("7") | ||
limitPage.withLimitedItemsSupplier { limit -> elementsList } | ||
assertEquals(5, limitPage.getItems().size) | ||
assertEquals(true, limitPage.hasMore()) | ||
assertEquals("5", limitPage.getItems().get(4)) | ||
assertEquals("1", limitPage.getItems().get(0)) | ||
} | ||
|
||
@Test | ||
fun `withLimitedItemsSupplier() with a list smaller than the page size does not crash`() { | ||
val limitPage = Page<String>().withPageSize(5) | ||
val elementsList = ArrayList<String>() | ||
elementsList.add("1") | ||
elementsList.add("2") | ||
elementsList.add("3") | ||
limitPage.withLimitedItemsSupplier { limit -> elementsList } | ||
assertEquals(3, limitPage.getItems().size) | ||
assertFalse(limitPage.hasMore()) | ||
assertEquals("3", limitPage.getItems().get(2)) | ||
assertEquals("1", limitPage.getItems().get(0)) | ||
} | ||
|
||
} |