✅ Add convenience function for runnables
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 11 Dec 2019 18:00:35 +0000 (19:00 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 11 Dec 2019 18:47:33 +0000 (19:47 +0100)
src/main/kotlin/net/pterodactylus/sone/utils/Functions.kt
src/test/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandlerTest.kt

index d7fb595..99f43b6 100644 (file)
@@ -4,3 +4,6 @@ import java.util.function.*
 
 /** Allows easy invocation of Java Consumers. */
 operator fun <T> Consumer<T>.invoke(t: T) = accept(t)
+
+/** Allows easy invocation of Java Runnables. */
+operator fun Runnable.invoke() = run()
index 86e456d..f7c185a 100644 (file)
@@ -22,6 +22,7 @@ import net.pterodactylus.sone.core.event.*
 import net.pterodactylus.sone.data.*
 import net.pterodactylus.sone.data.impl.*
 import net.pterodactylus.sone.notify.*
+import net.pterodactylus.sone.utils.*
 import net.pterodactylus.util.notify.*
 import net.pterodactylus.util.template.*
 import org.hamcrest.MatcherAssert.*
@@ -62,7 +63,7 @@ class SoneLockedHandlerTest {
        @Test
        fun `notification is added to notification manager from command`() {
                eventBus.post(SoneLockedEvent(sone))
-               executor.scheduleds.single().command.run()
+               executor.scheduleds.single().command()
                assertThat(notificationManager.notifications, contains<Any>(notification))
        }
 
@@ -91,7 +92,7 @@ class SoneLockedHandlerTest {
        @Test
        fun `unlocking sone after showing the notification will remove the sone from the notification`() {
                eventBus.post(SoneLockedEvent(sone))
-               executor.scheduleds.single().command.run()
+               executor.scheduleds.single().command()
                eventBus.post(SoneUnlockedEvent(sone))
                assertThat(notification.elements, emptyIterable())
        }