*
* @author Michael Vorburger
*/
-public abstract class GuiceModule extends AbstractModule {
+public abstract class AbstractGuiceJsr250Module extends AbstractModule {
@Override
protected final void configure() {
install(new CloseableModule());
install(new Jsr250Module());
+ configureBindings();
}
protected abstract void configureBindings();
import javax.inject.Inject;
import org.junit.Rule;
import org.junit.Test;
-import org.opendaylight.infrautils.inject.guice.testutils.GuiceModule;
+import org.opendaylight.infrautils.inject.guice.testutils.AbstractGuiceJsr250Module;
import org.opendaylight.infrautils.inject.guice.testutils.GuiceRule;
/**
- * Example Guice Test using the {@link GuiceRule} & {@link GuiceModule}.
+ * Example Guice Test using the {@link GuiceRule} & {@link AbstractGuiceJsr250Module}.
*
* @author Michael Vorburger
*/
public @Rule GuiceRule guice = new GuiceRule(TestModule.class);
- @Inject SomeClassWithPostConstruct someClass;
+ @Inject SomeInterfaceWithPostConstruct someService;
@Test public void testGuiceWithRule() {
- assertThat(someClass.isInit).named("isInit").isTrue();
+ assertThat(someService.isInit()).named("isInit()").isTrue();
}
- public static class TestModule extends GuiceModule {
+ public static class TestModule extends AbstractGuiceJsr250Module {
@Override
protected void configureBindings() {
- bind(SomeClassWithPostConstruct.class);
+ bind(SomeInterfaceWithPostConstruct.class).to(SomeClassWithPostConstruct.class);
}
}
}
--- /dev/null
+/*
+ * 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;
+
+interface SomeInterfaceWithPostConstruct {
+
+ void init();
+
+ boolean isInit();
+
+}