DataBrokerTestModule: use AbstractDataBrokerTest without inheritance
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / test / DataBrokerTestModule.java
diff --git a/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestModule.java b/opendaylight/md-sal/sal-binding-broker/src/test/java/org/opendaylight/controller/md/sal/binding/test/DataBrokerTestModule.java
new file mode 100644 (file)
index 0000000..96facbe
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2016 Red Hat, 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,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.md.sal.binding.test;
+
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+
+// @Module
+public class DataBrokerTestModule {
+
+    // Suppress IllegalCatch because of AbstractDataBrokerTest (change later)
+    @SuppressWarnings({ "checkstyle:IllegalCatch", "checkstyle:IllegalThrows" })
+    public static /* @Provides @Singleton */ DataBroker dataBroker() throws RuntimeException {
+        try {
+            // This is a little bit "upside down" - in the future,
+            // we should probably put what is in AbstractDataBrokerTest
+            // into this DataBrokerTestModule, and make AbstractDataBrokerTest
+            // use it, instead of the way around it currently is (the opposite);
+            // this is just for historical reasons... and works for now.
+            AbstractDataBrokerTest dataBrokerTest = new AbstractDataBrokerTest();
+            dataBrokerTest.setup();
+            return dataBrokerTest.getDataBroker();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+}