Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / test / java / org / opendaylight / controller / config / manager / impl / AbstractMockedModule.java
index 87d6e8b698e6d44795e0850380a15f4924bbf72e..1acf6b2fee0ab2b01f855fdbcca322d67c13647c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2013, 2017 Cisco Systems, Inc. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -14,15 +14,28 @@ 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();
+    @SuppressWarnings("IllegalCatch")
+    public AbstractMockedModule(final DynamicMBeanWithInstance old, final ModuleIdentifier id) {
+        if (old != null) {
+            instance = old.getInstance();
+        } else {
+            try {
+                instance = prepareMockedInstance();
+            } catch (final Exception e) {
+                throw new RuntimeException(e);
+            }
+        }
+
+        this.id = id == null ? new ModuleIdentifier(getClass().getCanonicalName(), "mock") : id;
+    }
+
+    @Override
+    public boolean canReuse(final Module oldModule) {
+        return instance != null;
     }
 
     @Override
@@ -34,5 +47,8 @@ public abstract class AbstractMockedModule implements Module {
         return instance;
     }
 
-
+    @Override
+    public ModuleIdentifier getIdentifier() {
+        return id;
+    }
 }