2 * Copyright (c) 2016 Red Hat, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.odlguice.inject.guice.testutils;
11 * Convenience Guice module support class, which installs the
12 * {@link AnnotationsModule}, and handles exceptions as the
13 * {@link AbstractCheckedModule} does.
15 * @author Michael Vorburger.ch
17 public abstract class AbstractGuiceJsr250Module extends AbstractCheckedModule {
20 @SuppressWarnings("checkstyle:IllegalCatch")
21 protected final void checkedConfigure() throws Exception {
22 install(new AnnotationsModule());
26 protected abstract void configureBindings() throws Exception;
29 * Binds instance to both the interfaceClass as well as the implementationClass.
31 * @param interfaceClass class type of an interface
32 * @param implementationClass class type of implementing class
33 * @param instance an instance implementing both interfaceClass & implementationClass
34 * @param <T> type of interfaceClass
36 @SuppressWarnings("unchecked")
37 protected <T> void bindTypesToInstance(Class<T> interfaceClass, Class<? extends T> implementationClass,
39 if (implementationClass.equals(interfaceClass)) {
40 throw new IllegalArgumentException("interfaceClass should not be the same as implementationClass: "
41 + interfaceClass + "; " + implementationClass);
43 bind(interfaceClass).toInstance(instance);
44 bind((Class<T>) implementationClass).toInstance(instance);