Merge "AbstractConfigTest - exposed BundleContext and ServiceRegistration mock."
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / AbstractMockedModule.java
index 89ac9a3828b076a8d2f3077006b49accfad1b83f..837ae2b3c86d7ee977648407b142f50dec17c76e 100644 (file)
@@ -14,15 +14,21 @@ import org.opendaylight.controller.config.spi.Module;
 public abstract class AbstractMockedModule implements Module {
 
     protected final AutoCloseable instance;
-
-    public AbstractMockedModule() throws Exception {
-        instance = prepareMockedInstance();
-    }
+    private final ModuleIdentifier id;
 
     protected abstract AutoCloseable prepareMockedInstance() throws Exception;
 
-    public AbstractMockedModule(DynamicMBeanWithInstance old) {
-        instance = old.getInstance();
+    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;
     }
 
     @Override
@@ -35,8 +41,8 @@ public abstract class AbstractMockedModule implements Module {
     }
 
     @Override
-    public ModuleIdentifier getName() {
-        return new ModuleIdentifier(getClass().getCanonicalName(), "mock");
+    public ModuleIdentifier getIdentifier() {
+        return id;
     }
 
 }