ONOS-3321 Added ability for applications to register a deactivation hook.

Change-Id: I284321474dbf9e39e8b61f7b907f637ba6b80aaf
diff --git a/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java b/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java
index 1ce31ac..5461cf0 100644
--- a/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java
+++ b/core/net/src/test/java/org/onosproject/app/impl/ApplicationManagerTest.java
@@ -24,11 +24,11 @@
 import org.onosproject.app.ApplicationState;
 import org.onosproject.app.ApplicationStoreAdapter;
 import org.onosproject.common.app.ApplicationArchive;
+import org.onosproject.common.event.impl.TestEventDispatcher;
 import org.onosproject.core.Application;
 import org.onosproject.core.ApplicationId;
 import org.onosproject.core.DefaultApplication;
 import org.onosproject.core.DefaultApplicationId;
-import org.onosproject.common.event.impl.TestEventDispatcher;
 
 import java.io.InputStream;
 import java.net.URI;
@@ -36,7 +36,7 @@
 import java.util.Optional;
 import java.util.Set;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
 import static org.onosproject.app.ApplicationEvent.Type.*;
 import static org.onosproject.app.ApplicationState.ACTIVE;
 import static org.onosproject.app.ApplicationState.INSTALLED;
@@ -53,6 +53,8 @@
     private ApplicationManager mgr = new ApplicationManager();
     private ApplicationListener listener = new TestListener();
 
+    private boolean deactivated = false;
+
     @Before
     public void setUp() {
         injectEventDispatcher(mgr, new TestEventDispatcher());
@@ -88,6 +90,11 @@
         assertEquals("incorrect app count", 1, mgr.getApplications().size());
         assertEquals("incorrect app", app, mgr.getApplication(APP_ID));
         assertEquals("incorrect app state", INSTALLED, mgr.getState(APP_ID));
+        mgr.registerDeactivateHook(app.id(), this::deactivateHook);
+    }
+
+    private void deactivateHook() {
+        deactivated = true;
     }
 
     @Test
@@ -102,6 +109,7 @@
         install();
         mgr.activate(APP_ID);
         assertEquals("incorrect app state", ACTIVE, mgr.getState(APP_ID));
+        assertFalse("preDeactivate hook wrongly called", deactivated);
     }
 
     @Test
@@ -109,6 +117,7 @@
         activate();
         mgr.deactivate(APP_ID);
         assertEquals("incorrect app state", INSTALLED, mgr.getState(APP_ID));
+        assertTrue("preDeactivate hook not called", deactivated);
     }