From: David ‘Bombe’ Roden Date: Sun, 28 Jul 2019 16:24:23 +0000 (+0200) Subject: ✨ Allow activateDebugMode() to be called multiple times X-Git-Tag: v81^2~165 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=32f850f85a051c2924e6323f03613c476d4fa2de;p=Sone.git ✨ Allow activateDebugMode() to be called multiple times --- diff --git a/src/main/kotlin/net/pterodactylus/sone/web/PageToadletRegistry.kt b/src/main/kotlin/net/pterodactylus/sone/web/PageToadletRegistry.kt index 70105bc..651bffd 100644 --- a/src/main/kotlin/net/pterodactylus/sone/web/PageToadletRegistry.kt +++ b/src/main/kotlin/net/pterodactylus/sone/web/PageToadletRegistry.kt @@ -21,6 +21,7 @@ class PageToadletRegistry @Inject constructor( private val debugPages = mutableListOf>() private val registeredToadlets = mutableListOf() private val registered = AtomicBoolean(false) + private val debugActivated = AtomicBoolean(false) fun addPage(page: Page) { 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) + } + } } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/PageToadletRegistryTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/PageToadletRegistryTest.kt index 5a19c7f..739a0dd 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/PageToadletRegistryTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/PageToadletRegistryTest.kt @@ -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)