Merge branch 'master' of ../infrautils
[odlguice.git] / inject-guice-testutils / src / test / java / org / opendaylight / infrautils / inject / guice / testutils / tests / ExampleGuiceRuleTest.java
diff --git a/inject-guice-testutils/src/test/java/org/opendaylight/infrautils/inject/guice/testutils/tests/ExampleGuiceRuleTest.java b/inject-guice-testutils/src/test/java/org/opendaylight/infrautils/inject/guice/testutils/tests/ExampleGuiceRuleTest.java
new file mode 100644 (file)
index 0000000..1c7efa0
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * 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.infrautils.inject.guice.testutils.tests;
+
+import static org.junit.Assert.assertTrue;
+
+import javax.inject.Inject;
+import org.junit.Rule;
+import org.junit.Test;
+import org.opendaylight.infrautils.inject.guice.testutils.AbstractGuiceJsr250Module;
+import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
+
+/**
+ * Example Guice Test using the {@link GuiceRule} & {@link AbstractGuiceJsr250Module}.
+ *
+ * @author Michael Vorburger
+ */
+public class ExampleGuiceRuleTest {
+    @Rule public GuiceRule guice = new GuiceRule(TestModule.class);
+
+    @Inject SomeInterfaceWithPostConstruct someService;
+
+    @Test
+    public void testGuiceWithRule() {
+        assertTrue(someService.isInit());
+    }
+
+    public static class TestModule extends AbstractGuiceJsr250Module {
+        @Override
+        protected void configureBindings() {
+            bind(SomeInterfaceWithPostConstruct.class).to(SomeClassWithPostConstruct.class);
+        }
+    }
+}