summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArtur <artur@vaadin.com>2017-05-12 08:32:45 +0300
committerHenri Sara <henri.sara@gmail.com>2017-05-12 08:32:45 +0300
commit22848f3420b5aded4d35c84f368dd9c44041200f (patch)
tree5f6fdeeab53b33fb19278457f220c68591fb68be
parent494b90a81cdd7dfc2fb337676e51ffa4bdd6ea43 (diff)
downloadvaadin-framework-22848f3420b5aded4d35c84f368dd9c44041200f.tar.gz
vaadin-framework-22848f3420b5aded4d35c84f368dd9c44041200f.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 1f687e91b0..3b56457c92 100644
--- a/server/src/main/java/com/vaadin/server/VaadinService.java
+++ b/server/src/main/java/com/vaadin/server/VaadinService.java
@@ -1986,7 +1986,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);
+ }
}