DataBrokerTestModule: use AbstractDataBrokerTest without inheritance 61/90061/5
authorMichael Vorburger <vorburger@redhat.com>
Wed, 10 Aug 2016 15:22:30 +0000 (17:22 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 29 May 2020 08:34:16 +0000 (10:34 +0200)
commite94d340da0d1b19e506fe2ad7e4e19c79959e241
tree1dba8e31469072db220806d05dc11ee43110e079
parentfb0a271c02454f11cd3c64130513dfb7caf3f386
DataBrokerTestModule: use AbstractDataBrokerTest without inheritance

While starting to write JUnit tests (for functional components) with the
AbstractDataBrokerTest, I found myself not liking its design which
forces one to use a class SomeTest extends AbstractDataBrokerTest...

Modern JUnit tests should be written by composition, not enforced
inheritance.  Thus this new DataBrokerTestModule allows one to obtain a
DataBroker suitable for Tests from anywhere.

The *(Test)Module naming convention is obviously inspired by a DI point
of view (think Spring Framework's @Configuration classes, or Google
Guice or Dagger (yay!) *Module classes - which is exactly what this
really is - a particular way to obtain an instance of an
implementationof some service (here a DataBroker) in a certain
environment (here for tests).

The internal implementation of DataBrokerTestModule could be changed
later; I guess ideally what's in AbstractDataBrokerTest could go into
DataBrokerTestModule and AbstractDataBrokerTest could use it, but for
now I'm too lazy to change that, as this does the trick nicely.  Later
implementation changes would be transparent to users of
DataBrokerTestModule.

JIRA: MDSAL-556
Change-Id: I9641f527bbc0cb92732f2e513cdd64cc6a837200
Signed-off-by: Michael Vorburger <vorburger@redhat.com>
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/test/tests/AbstractDataBrokerTestTest.java [new file with mode: 0644]
binding/mdsal-binding-test-utils/src/main/java/org/opendaylight/mdsal/binding/testutils/DataBrokerTestModule.java [new file with mode: 0644]
binding/mdsal-binding-test-utils/src/test/java/org/opendaylight/mdsal/binding/testutils/DataBrokerTestModuleTest.java [new file with mode: 0644]