projects
/
Sone.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
6d770b3
)
🐛 Fix sone-locked notification not showing all Sones
author
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Tue, 10 Dec 2019 18:56:22 +0000
(19:56 +0100)
committer
David ‘Bombe’ Roden
<bombe@pterodactylus.net>
Wed, 11 Dec 2019 15:59:18 +0000
(16:59 +0100)
src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt
patch
|
blob
|
history
src/test/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandlerTest.kt
patch
|
blob
|
history
diff --git
a/src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt
b/src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt
index
583601b
..
e8f2a79
100644
(file)
--- a/
src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt
+++ b/
src/main/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandler.kt
@@
-40,25
+40,25
@@
class SoneLockedHandler @Inject constructor(
@Subscribe
fun soneLocked(soneLockedEvent: SoneLockedEvent) {
synchronized(future) {
@Subscribe
fun soneLocked(soneLockedEvent: SoneLockedEvent) {
synchronized(future) {
- future.get()?.also { cancelPreviousFuture(it, soneLockedEvent.sone) }
- future.set(executor.schedule(showNotification(soneLockedEvent.sone), 5, TimeUnit.MINUTES))
+ notification.add(soneLockedEvent.sone)
+ future.get()?.also(this::cancelPreviousFuture)
+ future.set(executor.schedule(::showNotification, 5, TimeUnit.MINUTES))
}
}
@Subscribe
fun soneUnlocked(soneUnlockedEvent: SoneUnlockedEvent) {
synchronized(future) {
}
}
@Subscribe
fun soneUnlocked(soneUnlockedEvent: SoneUnlockedEvent) {
synchronized(future) {
- future.get()?.also { cancelPreviousFuture(it, soneUnlockedEvent.sone) }
+ notification.remove(soneUnlockedEvent.sone)
+ future.get()?.also(::cancelPreviousFuture)
}
}
}
}
- private fun cancelPreviousFuture(future: ScheduledFuture<*>, sone: Sone) {
- notification.remove(sone)
+ private fun cancelPreviousFuture(future: ScheduledFuture<*>) {
future.cancel(true)
}
future.cancel(true)
}
- private fun showNotification(sone: Sone): () -> Unit = {
- notification.add(sone)
+ private fun showNotification() {
notificationManager.addNotification(notification)
}
notificationManager.addNotification(notification)
}
diff --git
a/src/test/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandlerTest.kt
b/src/test/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandlerTest.kt
index
2daf5c9
..
191168e
100644
(file)
--- a/
src/test/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandlerTest.kt
+++ b/
src/test/kotlin/net/pterodactylus/sone/web/notification/SoneLockedHandlerTest.kt
@@
-44,16
+44,18
@@
class SoneLockedHandlerTest {
SoneLockedHandler(notificationManager, notification, executor).also(eventBus::register)
}
SoneLockedHandler(notificationManager, notification, executor).also(eventBus::register)
}
+ @AfterTest
+ fun shutdownExecutor() = executor.shutdown()
+
@Test
@Test
- fun `notification is not added
during the first five minutes
`() {
+ fun `notification is not added
before the command is run
`() {
eventBus.post(SoneLockedEvent(sone))
assertThat(notificationManager.notifications, emptyIterable())
}
@Test
eventBus.post(SoneLockedEvent(sone))
assertThat(notificationManager.notifications, emptyIterable())
}
@Test
- fun `sone is added to notification
from command
`() {
+ fun `sone is added to notification
immediately
`() {
eventBus.post(SoneLockedEvent(sone))
eventBus.post(SoneLockedEvent(sone))
- executor.scheduledDelay.single().command.run()
assertThat(notification.elements, contains(sone))
}
assertThat(notification.elements, contains(sone))
}