2 * Copyright © 2018 Red Hat, Inc. and others.
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.test;
10 import static com.google.common.truth.Truth.assertThat;
12 import java.util.HashMap;
13 import java.util.HashSet;
16 import org.junit.Test;
17 import org.opendaylight.odlguice.inject.ClassPathScanner;
19 public class ClassPathScannerTest {
21 private static final String PREFIX = "org.opendaylight.odlguice.inject.guice.test";
24 public void testClasspathScanning() {
25 Set<Class<?>> singletons = new HashSet<>();
26 Map<Class<?>, Class<?>> bindings = new HashMap<>();
27 new ClassPathScanner(PREFIX).bindAllSingletons(PREFIX, bindings::put, singletons::add);
28 assertThat(bindings).containsExactly(
29 ClassPathScannerTestTopInterface.class, ClassPathScannerTestImplementation.class,
30 ClassPathScannerTestAnotherInterface.class, ClassPathScannerTestImplementation.class);
31 assertThat(singletons).containsExactly(ClassPathScannerTestNoInterfacesImplementation.class);
35 public void testClasspathExclusion() {
36 Set<Class<?>> singletons = new HashSet<>();
37 Map<Class<?>, Class<?>> bindings = new HashMap<>();
38 new ClassPathScanner(PREFIX).bindAllSingletons("nope", bindings::put, singletons::add);
39 assertThat(bindings).isEmpty();
40 assertThat(singletons).isEmpty();