🚚 Move Kotlin tests to kotlin directory
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Jun 2019 08:26:45 +0000 (10:26 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 26 Jun 2019 08:26:45 +0000 (10:26 +0200)
src/test/java/net/pterodactylus/sone/test/Matchers.kt [deleted file]
src/test/java/net/pterodactylus/sone/test/TestUtils.kt [deleted file]
src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt [deleted file]
src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt [new file with mode: 0644]
src/test/kotlin/net/pterodactylus/sone/web/AllPagesTest.kt [new file with mode: 0644]

diff --git a/src/test/java/net/pterodactylus/sone/test/Matchers.kt b/src/test/java/net/pterodactylus/sone/test/Matchers.kt
deleted file mode 100644 (file)
index c084d35..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-package net.pterodactylus.sone.test
-
-import net.pterodactylus.util.web.*
-import org.hamcrest.*
-
-fun hasHeader(name: String, value: String) = object : TypeSafeDiagnosingMatcher<Header>() {
-       override fun matchesSafely(item: Header, mismatchDescription: Description) =
-                       compare(item.name, { it.equals(name, ignoreCase = true) }) { mismatchDescription.appendText("name is ").appendValue(it) }
-                                       ?: compare(item.hasValue(value), { it }) { mismatchDescription.appendText("does not have value ").appendValue(value) }
-                                       ?: true
-
-       override fun describeTo(description: Description) {
-               description.appendText("name is ").appendValue(name)
-                               .appendText(", value is ").appendValue(value)
-       }
-}
-
-fun <T : Any> compare(value: T, comparison: (T) -> Boolean, onError: (T) -> Unit) =
-               false.takeUnless { comparison(value) }
-                               ?.also { onError(value) }
-
diff --git a/src/test/java/net/pterodactylus/sone/test/TestUtils.kt b/src/test/java/net/pterodactylus/sone/test/TestUtils.kt
deleted file mode 100644 (file)
index 9996925..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-package net.pterodactylus.sone.test
-
-import java.lang.reflect.*
-
-private val modifiers = Field::class.java.getDeclaredField("modifiers").apply {
-       isAccessible = true
-}
-
-fun setField(instance: Any, name: String, value: Any?) {
-       generateSequence<Class<*>>(instance.javaClass) { it.superclass }
-                       .flatMap { it.declaredFields.asSequence() }
-                       .filter { it.name == name }
-                       .toList()
-                       .forEach { field ->
-                               field.isAccessible = true
-                               modifiers.setInt(field, field.modifiers and Modifier.FINAL.inv())
-                               field.set(instance, value)
-                       }
-}
diff --git a/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt b/src/test/java/net/pterodactylus/sone/web/AllPagesTest.kt
deleted file mode 100644 (file)
index cf6ab15..0000000
+++ /dev/null
@@ -1,253 +0,0 @@
-package net.pterodactylus.sone.web
-
-import com.google.inject.Guice.createInjector
-import net.pterodactylus.sone.core.Core
-import net.pterodactylus.sone.core.FreenetInterface
-import net.pterodactylus.sone.main.PluginHomepage
-import net.pterodactylus.sone.main.PluginVersion
-import net.pterodactylus.sone.main.PluginYear
-import net.pterodactylus.sone.test.*
-import net.pterodactylus.sone.web.page.*
-import net.pterodactylus.sone.web.pages.*
-import net.pterodactylus.util.template.Template
-import org.hamcrest.Matcher
-import org.hamcrest.MatcherAssert.assertThat
-import org.hamcrest.Matchers
-import org.junit.Test
-
-/**
- * Test for [AllPages].
- */
-class AllPagesTest {
-
-       private val injector by lazy {
-               baseInjector.createChildInjector(
-                               PluginVersion::class.isProvidedByMock(),
-                               PluginYear::class.isProvidedByMock(),
-                               PluginHomepage::class.isProvidedByMock()
-               )!!
-       }
-       private val allPages by lazy { injector.getInstance<AllPages>() }
-
-       private inline fun <reified T> instanceOf(): Matcher<T> = Matchers.instanceOf<T>(T::class.java)
-
-       @Test
-       fun `about page can be injected`() {
-               assertThat(allPages.aboutPage, instanceOf<AboutPage>())
-       }
-
-       @Test
-       fun `bookmark page can be injected`() {
-               assertThat(allPages.bookmarkPage, instanceOf<BookmarkPage>())
-       }
-
-       @Test
-       fun `bookmarks page can be injected`() {
-               assertThat(allPages.bookmarksPage, instanceOf<BookmarksPage>())
-       }
-
-       @Test
-       fun `create album page can be injected`() {
-               assertThat(allPages.createAlbumPage, instanceOf<CreateAlbumPage>())
-       }
-
-       @Test
-       fun `create post page can be injected`() {
-               assertThat(allPages.createPostPage, instanceOf<CreatePostPage>())
-       }
-
-       @Test
-       fun `create reply page can be injected`() {
-               assertThat(allPages.createReplyPage, instanceOf<CreateReplyPage>())
-       }
-
-       @Test
-       fun `create sone page can be injected`() {
-               assertThat(allPages.createSonePage, instanceOf<CreateSonePage>())
-       }
-
-       @Test
-       fun `delete album page can be injected`() {
-               assertThat(allPages.deleteAlbumPage, instanceOf<DeleteAlbumPage>())
-       }
-
-       @Test
-       fun `delete image page can be injected`() {
-               assertThat(allPages.deleteImagePage, instanceOf<DeleteImagePage>())
-       }
-
-       @Test
-       fun `delete post page can be injected`() {
-               assertThat(allPages.deletePostPage, instanceOf<DeletePostPage>())
-       }
-
-       @Test
-       fun `delete profile field page can be injected`() {
-               assertThat(allPages.deleteProfileFieldPage, instanceOf<DeleteProfileFieldPage>())
-       }
-
-       @Test
-       fun `delete reply page can be injected`() {
-               assertThat(allPages.deleteReplyPage, instanceOf<DeleteReplyPage>())
-       }
-
-       @Test
-       fun `delete sone page can be injected`() {
-               assertThat(allPages.deleteSonePage, instanceOf<DeleteSonePage>())
-       }
-
-       @Test
-       fun `dismiss notification page can be injected`() {
-               assertThat(allPages.dismissNotificationPage, instanceOf<DismissNotificationPage>())
-       }
-
-       @Test
-       fun `distrust page can be injected`() {
-               assertThat(allPages.distrustPage, instanceOf<DistrustPage>())
-       }
-
-       @Test
-       fun `edit album page can be injected`() {
-               assertThat(allPages.editAlbumPage, instanceOf<EditAlbumPage>())
-       }
-
-       @Test
-       fun `edit image page can be injected`() {
-               assertThat(allPages.editImagePage, instanceOf<EditImagePage>())
-       }
-
-       @Test
-       fun `edit profile field page can be injected`() {
-               assertThat(allPages.editProfileFieldPage, instanceOf<EditProfileFieldPage>())
-       }
-
-       @Test
-       fun `edit profile page can be injected`() {
-               assertThat(allPages.editProfilePage, instanceOf<EditProfilePage>())
-       }
-
-       @Test
-       fun `follow sone page can be injected`() {
-               assertThat(allPages.followSonePage, instanceOf<FollowSonePage>())
-       }
-
-       @Test
-       fun `get image page can be injected`() {
-               assertThat(allPages.getImagePage, instanceOf<GetImagePage>())
-       }
-
-       @Test
-       fun `image browser page can be injected`() {
-               assertThat(allPages.imageBrowserPage, instanceOf<ImageBrowserPage>())
-       }
-
-       @Test
-       fun `index page can be injected`() {
-               assertThat(allPages.indexPage, instanceOf<IndexPage>())
-       }
-
-       @Test
-       fun `known sones page can be injected`() {
-               assertThat(allPages.knownSonesPage, instanceOf<KnownSonesPage>())
-       }
-
-       @Test
-       fun `like page can be injected`() {
-               assertThat(allPages.likePage, instanceOf<LikePage>())
-       }
-
-       @Test
-       fun `lock sone page can be injected`() {
-               assertThat(allPages.lockSonePage, instanceOf<LockSonePage>())
-       }
-
-       @Test
-       fun `login page can be injected`() {
-               assertThat(allPages.loginPage, instanceOf<LoginPage>())
-       }
-
-       @Test
-       fun `logout page can be injected`() {
-               assertThat(allPages.logoutPage, instanceOf<LogoutPage>())
-       }
-
-       @Test
-       fun `mark as known page can be injected`() {
-               assertThat(allPages.markAsKnownPage, instanceOf<MarkAsKnownPage>())
-       }
-
-       @Test
-       fun `new page can be injected`() {
-               assertThat(allPages.newPage, instanceOf<NewPage>())
-       }
-
-       @Test
-       fun `options page can be injected`() {
-               assertThat(allPages.optionsPage, instanceOf<OptionsPage>())
-       }
-
-       @Test
-       fun `rescue page can be injected`() {
-               assertThat(allPages.rescuePage, instanceOf<RescuePage>())
-       }
-
-       @Test
-       fun `search page can be injected`() {
-               assertThat(allPages.searchPage, instanceOf<SearchPage>())
-       }
-
-       @Test
-       fun `trust page can be injected`() {
-               assertThat(allPages.trustPage, instanceOf<TrustPage>())
-       }
-
-       @Test
-       fun `unbookmark page can be injected`() {
-               assertThat(allPages.unbookmarkPage, instanceOf<UnbookmarkPage>())
-       }
-
-       @Test
-       fun `unfollow sone page can be injected`() {
-               assertThat(allPages.unfollowSonePage, instanceOf<UnfollowSonePage>())
-       }
-
-       @Test
-       fun `unlike page can be injected`() {
-               assertThat(allPages.unlikePage, instanceOf<UnlikePage>())
-       }
-
-       @Test
-       fun `unlock sone page can be injected`() {
-               assertThat(allPages.unlockSonePage, instanceOf<UnlockSonePage>())
-       }
-
-       @Test
-       fun `untrust page can be injected`() {
-               assertThat(allPages.untrustPage, instanceOf<UntrustPage>())
-       }
-
-       @Test
-       fun `upload image page can be injected`() {
-               assertThat(allPages.uploadImagePage, instanceOf<UploadImagePage>())
-       }
-
-       @Test
-       fun `view post page can be injected`() {
-               assertThat(allPages.viewPostPage, instanceOf<ViewPostPage>())
-       }
-
-       @Test
-       fun `view sone page can be injected`() {
-               assertThat(allPages.viewSonePage, instanceOf<ViewSonePage>())
-       }
-}
-
-val baseInjector by lazy {
-       createInjector(
-                       Core::class.isProvidedByMock(),
-                       FreenetInterface::class.isProvidedByMock(),
-                       Template::class.isProvidedByMock(),
-                       WebInterface::class.isProvidedByDeepMock(),
-                       TemplateRenderer::class.isProvidedByMock()
-       )!!
-}
diff --git a/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt b/src/test/kotlin/net/pterodactylus/sone/test/Matchers.kt
new file mode 100644 (file)
index 0000000..c084d35
--- /dev/null
@@ -0,0 +1,21 @@
+package net.pterodactylus.sone.test
+
+import net.pterodactylus.util.web.*
+import org.hamcrest.*
+
+fun hasHeader(name: String, value: String) = object : TypeSafeDiagnosingMatcher<Header>() {
+       override fun matchesSafely(item: Header, mismatchDescription: Description) =
+                       compare(item.name, { it.equals(name, ignoreCase = true) }) { mismatchDescription.appendText("name is ").appendValue(it) }
+                                       ?: compare(item.hasValue(value), { it }) { mismatchDescription.appendText("does not have value ").appendValue(value) }
+                                       ?: true
+
+       override fun describeTo(description: Description) {
+               description.appendText("name is ").appendValue(name)
+                               .appendText(", value is ").appendValue(value)
+       }
+}
+
+fun <T : Any> compare(value: T, comparison: (T) -> Boolean, onError: (T) -> Unit) =
+               false.takeUnless { comparison(value) }
+                               ?.also { onError(value) }
+
diff --git a/src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt b/src/test/kotlin/net/pterodactylus/sone/test/TestUtils.kt
new file mode 100644 (file)
index 0000000..9996925
--- /dev/null
@@ -0,0 +1,19 @@
+package net.pterodactylus.sone.test
+
+import java.lang.reflect.*
+
+private val modifiers = Field::class.java.getDeclaredField("modifiers").apply {
+       isAccessible = true
+}
+
+fun setField(instance: Any, name: String, value: Any?) {
+       generateSequence<Class<*>>(instance.javaClass) { it.superclass }
+                       .flatMap { it.declaredFields.asSequence() }
+                       .filter { it.name == name }
+                       .toList()
+                       .forEach { field ->
+                               field.isAccessible = true
+                               modifiers.setInt(field, field.modifiers and Modifier.FINAL.inv())
+                               field.set(instance, value)
+                       }
+}
diff --git a/src/test/kotlin/net/pterodactylus/sone/web/AllPagesTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/AllPagesTest.kt
new file mode 100644 (file)
index 0000000..cf6ab15
--- /dev/null
@@ -0,0 +1,253 @@
+package net.pterodactylus.sone.web
+
+import com.google.inject.Guice.createInjector
+import net.pterodactylus.sone.core.Core
+import net.pterodactylus.sone.core.FreenetInterface
+import net.pterodactylus.sone.main.PluginHomepage
+import net.pterodactylus.sone.main.PluginVersion
+import net.pterodactylus.sone.main.PluginYear
+import net.pterodactylus.sone.test.*
+import net.pterodactylus.sone.web.page.*
+import net.pterodactylus.sone.web.pages.*
+import net.pterodactylus.util.template.Template
+import org.hamcrest.Matcher
+import org.hamcrest.MatcherAssert.assertThat
+import org.hamcrest.Matchers
+import org.junit.Test
+
+/**
+ * Test for [AllPages].
+ */
+class AllPagesTest {
+
+       private val injector by lazy {
+               baseInjector.createChildInjector(
+                               PluginVersion::class.isProvidedByMock(),
+                               PluginYear::class.isProvidedByMock(),
+                               PluginHomepage::class.isProvidedByMock()
+               )!!
+       }
+       private val allPages by lazy { injector.getInstance<AllPages>() }
+
+       private inline fun <reified T> instanceOf(): Matcher<T> = Matchers.instanceOf<T>(T::class.java)
+
+       @Test
+       fun `about page can be injected`() {
+               assertThat(allPages.aboutPage, instanceOf<AboutPage>())
+       }
+
+       @Test
+       fun `bookmark page can be injected`() {
+               assertThat(allPages.bookmarkPage, instanceOf<BookmarkPage>())
+       }
+
+       @Test
+       fun `bookmarks page can be injected`() {
+               assertThat(allPages.bookmarksPage, instanceOf<BookmarksPage>())
+       }
+
+       @Test
+       fun `create album page can be injected`() {
+               assertThat(allPages.createAlbumPage, instanceOf<CreateAlbumPage>())
+       }
+
+       @Test
+       fun `create post page can be injected`() {
+               assertThat(allPages.createPostPage, instanceOf<CreatePostPage>())
+       }
+
+       @Test
+       fun `create reply page can be injected`() {
+               assertThat(allPages.createReplyPage, instanceOf<CreateReplyPage>())
+       }
+
+       @Test
+       fun `create sone page can be injected`() {
+               assertThat(allPages.createSonePage, instanceOf<CreateSonePage>())
+       }
+
+       @Test
+       fun `delete album page can be injected`() {
+               assertThat(allPages.deleteAlbumPage, instanceOf<DeleteAlbumPage>())
+       }
+
+       @Test
+       fun `delete image page can be injected`() {
+               assertThat(allPages.deleteImagePage, instanceOf<DeleteImagePage>())
+       }
+
+       @Test
+       fun `delete post page can be injected`() {
+               assertThat(allPages.deletePostPage, instanceOf<DeletePostPage>())
+       }
+
+       @Test
+       fun `delete profile field page can be injected`() {
+               assertThat(allPages.deleteProfileFieldPage, instanceOf<DeleteProfileFieldPage>())
+       }
+
+       @Test
+       fun `delete reply page can be injected`() {
+               assertThat(allPages.deleteReplyPage, instanceOf<DeleteReplyPage>())
+       }
+
+       @Test
+       fun `delete sone page can be injected`() {
+               assertThat(allPages.deleteSonePage, instanceOf<DeleteSonePage>())
+       }
+
+       @Test
+       fun `dismiss notification page can be injected`() {
+               assertThat(allPages.dismissNotificationPage, instanceOf<DismissNotificationPage>())
+       }
+
+       @Test
+       fun `distrust page can be injected`() {
+               assertThat(allPages.distrustPage, instanceOf<DistrustPage>())
+       }
+
+       @Test
+       fun `edit album page can be injected`() {
+               assertThat(allPages.editAlbumPage, instanceOf<EditAlbumPage>())
+       }
+
+       @Test
+       fun `edit image page can be injected`() {
+               assertThat(allPages.editImagePage, instanceOf<EditImagePage>())
+       }
+
+       @Test
+       fun `edit profile field page can be injected`() {
+               assertThat(allPages.editProfileFieldPage, instanceOf<EditProfileFieldPage>())
+       }
+
+       @Test
+       fun `edit profile page can be injected`() {
+               assertThat(allPages.editProfilePage, instanceOf<EditProfilePage>())
+       }
+
+       @Test
+       fun `follow sone page can be injected`() {
+               assertThat(allPages.followSonePage, instanceOf<FollowSonePage>())
+       }
+
+       @Test
+       fun `get image page can be injected`() {
+               assertThat(allPages.getImagePage, instanceOf<GetImagePage>())
+       }
+
+       @Test
+       fun `image browser page can be injected`() {
+               assertThat(allPages.imageBrowserPage, instanceOf<ImageBrowserPage>())
+       }
+
+       @Test
+       fun `index page can be injected`() {
+               assertThat(allPages.indexPage, instanceOf<IndexPage>())
+       }
+
+       @Test
+       fun `known sones page can be injected`() {
+               assertThat(allPages.knownSonesPage, instanceOf<KnownSonesPage>())
+       }
+
+       @Test
+       fun `like page can be injected`() {
+               assertThat(allPages.likePage, instanceOf<LikePage>())
+       }
+
+       @Test
+       fun `lock sone page can be injected`() {
+               assertThat(allPages.lockSonePage, instanceOf<LockSonePage>())
+       }
+
+       @Test
+       fun `login page can be injected`() {
+               assertThat(allPages.loginPage, instanceOf<LoginPage>())
+       }
+
+       @Test
+       fun `logout page can be injected`() {
+               assertThat(allPages.logoutPage, instanceOf<LogoutPage>())
+       }
+
+       @Test
+       fun `mark as known page can be injected`() {
+               assertThat(allPages.markAsKnownPage, instanceOf<MarkAsKnownPage>())
+       }
+
+       @Test
+       fun `new page can be injected`() {
+               assertThat(allPages.newPage, instanceOf<NewPage>())
+       }
+
+       @Test
+       fun `options page can be injected`() {
+               assertThat(allPages.optionsPage, instanceOf<OptionsPage>())
+       }
+
+       @Test
+       fun `rescue page can be injected`() {
+               assertThat(allPages.rescuePage, instanceOf<RescuePage>())
+       }
+
+       @Test
+       fun `search page can be injected`() {
+               assertThat(allPages.searchPage, instanceOf<SearchPage>())
+       }
+
+       @Test
+       fun `trust page can be injected`() {
+               assertThat(allPages.trustPage, instanceOf<TrustPage>())
+       }
+
+       @Test
+       fun `unbookmark page can be injected`() {
+               assertThat(allPages.unbookmarkPage, instanceOf<UnbookmarkPage>())
+       }
+
+       @Test
+       fun `unfollow sone page can be injected`() {
+               assertThat(allPages.unfollowSonePage, instanceOf<UnfollowSonePage>())
+       }
+
+       @Test
+       fun `unlike page can be injected`() {
+               assertThat(allPages.unlikePage, instanceOf<UnlikePage>())
+       }
+
+       @Test
+       fun `unlock sone page can be injected`() {
+               assertThat(allPages.unlockSonePage, instanceOf<UnlockSonePage>())
+       }
+
+       @Test
+       fun `untrust page can be injected`() {
+               assertThat(allPages.untrustPage, instanceOf<UntrustPage>())
+       }
+
+       @Test
+       fun `upload image page can be injected`() {
+               assertThat(allPages.uploadImagePage, instanceOf<UploadImagePage>())
+       }
+
+       @Test
+       fun `view post page can be injected`() {
+               assertThat(allPages.viewPostPage, instanceOf<ViewPostPage>())
+       }
+
+       @Test
+       fun `view sone page can be injected`() {
+               assertThat(allPages.viewSonePage, instanceOf<ViewSonePage>())
+       }
+}
+
+val baseInjector by lazy {
+       createInjector(
+                       Core::class.isProvidedByMock(),
+                       FreenetInterface::class.isProvidedByMock(),
+                       Template::class.isProvidedByMock(),
+                       WebInterface::class.isProvidedByDeepMock(),
+                       TemplateRenderer::class.isProvidedByMock()
+       )!!
+}