Merge "Remove unnecessary declaration of <prerequisites> in features"
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / AbstractMockedModule.java
index 87d6e8b698e6d44795e0850380a15f4924bbf72e..a6e24e9a495fe0df079952144ee440e02732cea0 100644 (file)
@@ -14,15 +14,27 @@ import org.opendaylight.controller.config.spi.Module;
 public abstract class AbstractMockedModule implements Module {
 
     protected final AutoCloseable instance;
+    private final ModuleIdentifier id;
 
-    public AbstractMockedModule() throws Exception {
-        instance = prepareMockedInstance();
+    protected abstract AutoCloseable prepareMockedInstance() throws Exception;
+
+    public AbstractMockedModule(DynamicMBeanWithInstance old, ModuleIdentifier id) {
+        if(old!=null)
+            instance = old.getInstance();
+        else
+            try {
+                instance = prepareMockedInstance();
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+
+        this.id = id==null ? new ModuleIdentifier(getClass().getCanonicalName(), "mock") : id;
     }
 
-    protected abstract AutoCloseable prepareMockedInstance() throws Exception;
 
-    public AbstractMockedModule(DynamicMBeanWithInstance old) {
-        instance = old.getInstance();
+    @Override
+    public boolean canReuse(Module oldModule) {
+        return instance!=null;
     }
 
     @Override
@@ -34,5 +46,9 @@ public abstract class AbstractMockedModule implements Module {
         return instance;
     }
 
+    @Override
+    public ModuleIdentifier getIdentifier() {
+        return id;
+    }
 
 }