- elementLoader.loadElement(textKey)
- verify(freenetInterface).startFetch(eq(FreenetURI(textKey)), callback.capture())
- callback.value.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader2.html"))
- val linkedElement = elementLoader.loadElement(textKey)
- assertThat(linkedElement, equalTo(LinkedElement(textKey, properties = mapOf(
- "type" to "html",
- "size" to 185,
- "sizeHuman" to "185 B",
- "title" to "Some Nice Page Title",
- "description" to "This is the first paragraph of the very nice freesite."
- ))))
- }
-
- @Test
- fun `element loader can not extract description if html is more complicated`() {
- elementLoader.loadElement(textKey)
- verify(freenetInterface).startFetch(eq(FreenetURI(textKey)), callback.capture())
- callback.value.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader3.html"))
- val linkedElement = elementLoader.loadElement(textKey)
- assertThat(linkedElement, equalTo(LinkedElement(textKey, properties = mapOf(
- "type" to "html",
- "size" to 204,
- "sizeHuman" to "204 B",
- "title" to "Some Nice Page Title",
- "description" to null
- ))))
+ runWithCallback(textKey) { elementLoader, _, callback, _ ->
+ callback.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader2.html"))
+ val linkedElement = elementLoader.loadElement(textKey)
+ assertThat(linkedElement, isLinkedElement(equalTo(textKey), allOf(
+ hasEntry("type", "html"), hasEntry("size", 185), hasEntry("sizeHuman", "185 B"),
+ hasEntry("title", "Some Nice Page Title"),
+ hasEntry("description", "This is the first paragraph of the very nice freesite.")
+ )))
+ }
+ }
+
+ @Test
+ fun `element loader can extract description if html is more complicated`() {
+ runWithCallback(textKey) { elementLoader, _, callback, _ ->
+ callback.loaded(FreenetURI(textKey), "text/html; charset=UTF-8", read("element-loader3.html"))
+ val linkedElement = elementLoader.loadElement(textKey)
+ assertThat(linkedElement, isLinkedElement(equalTo(textKey), allOf(
+ hasEntry("type", "html"), hasEntry("size", 204), hasEntry("sizeHuman", "204 B"),
+ hasEntry("title", "Some Nice Page Title"),
+ hasEntry("description", "This is the first paragraph of the very nice freesite.")
+ )))
+ }