From deb3a451fb1d48a050f260806f0bc53a95ca5243 Mon Sep 17 00:00:00 2001 From: Artur Date: Fri, 12 May 2017 08:32:45 +0300 Subject: Properly remove service destroy listeners (#9304) Fixes #9291 --- .../main/java/com/vaadin/server/VaadinService.java | 2 +- .../java/com/vaadin/server/VaadinServiceTest.java | 30 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) 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); + } } -- cgit v1.2.3