package net.pterodactylus.sone.web.page import freenet.clients.http.* import freenet.l10n.* import freenet.support.api.* import net.pterodactylus.sone.core.* import net.pterodactylus.sone.test.* import net.pterodactylus.sone.web.* import net.pterodactylus.util.web.* import org.hamcrest.MatcherAssert.* import org.hamcrest.Matchers.* import org.junit.* import org.mockito.* import java.net.* class SoneRequestTest { private val uri = URI(".") private val method = Method.GET private val httpRequest = Mockito.mock(HTTPRequest::class.java) private val toadletContext = Mockito.mock(ToadletContext::class.java) private val l10n = mock() private val sessionManager = mock() private val core = mock() private val webInterface = mock() private val soneRequest = SoneRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager, core, webInterface) @Test fun `freenet request properties are retained correctly`() { assertThat(soneRequest.uri, equalTo(uri)) assertThat(soneRequest.method, equalTo(method)) assertThat(soneRequest.httpRequest, equalTo(httpRequest)) assertThat(soneRequest.toadletContext, equalTo(toadletContext)) assertThat(soneRequest.l10n, equalTo(l10n)) assertThat(soneRequest.sessionManager, equalTo(sessionManager)) } @Test fun `core is retained correctly`() { assertThat(soneRequest.core, sameInstance(core)) } @Test fun `web interface is retained correctly`() { assertThat(soneRequest.webInterface, sameInstance(webInterface)) } @Test fun `freenet request is wrapped correctly`() { val freenetRequest = FreenetRequest(uri, method, httpRequest, toadletContext, l10n, sessionManager) val wrappedSoneRequest = freenetRequest.toSoneRequest(core, webInterface) assertThat(wrappedSoneRequest.uri, equalTo(uri)) assertThat(wrappedSoneRequest.method, equalTo(method)) assertThat(wrappedSoneRequest.httpRequest, equalTo(httpRequest)) assertThat(wrappedSoneRequest.toadletContext, equalTo(toadletContext)) assertThat(wrappedSoneRequest.l10n, equalTo(l10n)) assertThat(wrappedSoneRequest.sessionManager, equalTo(sessionManager)) assertThat(wrappedSoneRequest.core, sameInstance(core)) assertThat(wrappedSoneRequest.webInterface, sameInstance(webInterface)) } }