aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-05-12 08:32:45 +0300
committerTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2017-07-11 10:01:02 +0300
commitdeb3a451fb1d48a050f260806f0bc53a95ca5243 (patch)
tree4b457918360a3ee2978cf1e33de44a40794d145f
parent78c96ee27e64f9be35ad8922915486e832472762 (diff)
downloadvaadin-framework-deb3a451fb1d48a050f260806f0bc53a95ca5243.tar.gz
vaadin-framework-deb3a451fb1d48a050f260806f0bc53a95ca5243.zip
Properly remove service destroy listeners (#9304)
Fixes #9291
-rw-r--r--server/src/main/java/com/vaadin/server/VaadinService.java2
-rw-r--r--server/src/test/java/com/vaadin/server/VaadinServiceTest.java30
2 files changed, 31 insertions, 1 deletions
diff --git a/server/src/main/java/com/vaadin/server/VaadinService.java b/server/src/main/java/com/vaadin/server/VaadinService.java
index 80ae39cb35..f9c44f87ba 100644
--- a/server/src/main/java/com/vaadin/server/VaadinService.java
+++ b/server/src/main/java/com/vaadin/server/VaadinService.java
@@ -1935,7 +1935,7 @@ public abstract class VaadinService implements Serializable {
*/
@Deprecated
public void removeServiceDestroyListener(ServiceDestroyListener listener) {
- serviceDestroyListeners.remove(serviceDestroyListeners);
+ serviceDestroyListeners.remove(listener);
}
/**
diff --git a/server/src/test/java/com/vaadin/server/VaadinServiceTest.java b/server/src/test/java/com/vaadin/server/VaadinServiceTest.java
index 59ddaf3e67..7d6cc70146 100644
--- a/server/src/test/java/com/vaadin/server/VaadinServiceTest.java
+++ b/server/src/test/java/com/vaadin/server/VaadinServiceTest.java
@@ -26,6 +26,7 @@ import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
+import com.vaadin.shared.Registration;
import com.vaadin.util.CurrentInstance;
/**
@@ -44,6 +45,17 @@ public class VaadinServiceTest {
}
}
+ private class TestServiceDestroyListener implements ServiceDestroyListener {
+
+ int callCount = 0;
+
+ @Override
+ public void serviceDestroy(ServiceDestroyEvent event) {
+ callCount++;
+ }
+
+ }
+
private String createCriticalNotification(String caption, String message,
String details, String url) {
return VaadinService.createCriticalNotificationJSON(caption, message,
@@ -169,4 +181,22 @@ public class VaadinServiceTest {
return service;
}
+ @Test
+ public void fireServiceDestroy() {
+ VaadinService service = createService();
+ TestServiceDestroyListener listener = new TestServiceDestroyListener();
+ TestServiceDestroyListener listener2 = new TestServiceDestroyListener();
+ service.addServiceDestroyListener(listener);
+ Registration remover2 = service.addServiceDestroyListener(listener2);
+
+ service.destroy();
+ Assert.assertEquals(1, listener.callCount);
+ Assert.assertEquals(1, listener2.callCount);
+ service.removeServiceDestroyListener(listener);
+ remover2.remove();
+
+ service.destroy();
+ Assert.assertEquals(1, listener.callCount);
+ Assert.assertEquals(1, listener2.callCount);
+ }
}