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()
registeredToadlets.forEach(toadletContainer::unregister)
}
- fun activateDebugMode() =
+ fun activateDebugMode() {
+ if (!debugActivated.get()) {
addPages(debugPages)
+ debugActivated.set(true)
+ }
+ }
}
}
@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)