✨ Allow activateDebugMode() to be called multiple times
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 28 Jul 2019 16:24:23 +0000 (18:24 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 28 Jul 2019 19:07:10 +0000 (21:07 +0200)
src/main/kotlin/net/pterodactylus/sone/web/PageToadletRegistry.kt
src/test/kotlin/net/pterodactylus/sone/web/PageToadletRegistryTest.kt

index 70105bc..651bffd 100644 (file)
@@ -21,6 +21,7 @@ class PageToadletRegistry @Inject constructor(
        private val debugPages = mutableListOf<Page<FreenetRequest>>()
        private val registeredToadlets = mutableListOf<PageToadlet>()
        private val registered = AtomicBoolean(false)
+       private val debugActivated = AtomicBoolean(false)
 
        fun addPage(page: Page<FreenetRequest>) {
                if (registered.get()) throw IllegalStateException()
@@ -61,7 +62,11 @@ class PageToadletRegistry @Inject constructor(
                registeredToadlets.forEach(toadletContainer::unregister)
        }
 
-       fun activateDebugMode() =
+       fun activateDebugMode() {
+               if (!debugActivated.get()) {
                        addPages(debugPages)
+                       debugActivated.set(true)
+               }
+       }
 
 }
index 5a19c7f..739a0dd 100644 (file)
@@ -101,6 +101,17 @@ class PageToadletRegistryTest {
        }
 
        @Test
+       fun `adding a debug page and activating debug mode twice will add it to the container once`() {
+               val toadlet = createPageToadlet()
+               whenever(pageToadletFactory.createPageToadlet(page)).thenReturn(toadlet)
+               pageToadletRegistry.addDebugPage(page)
+               pageToadletRegistry.registerToadlets()
+               pageToadletRegistry.activateDebugMode()
+               pageToadletRegistry.activateDebugMode()
+               verify(toadletContainer, times(1)).register(toadlet, null, "/Sone/", true, false)
+       }
+
+       @Test
        fun `debug pages are ungegistered from the container`() {
                val toadlet = createPageToadlet()
                whenever(pageToadletFactory.createPageToadlet(page)).thenReturn(toadlet)