Merge "Add Mycilla code to odlguice"
[odlguice.git] / inject / inject-guice / src / test / java / org / opendaylight / infrautils / inject / guice / test / ClassPathScannerTest.java
1 /*
2  * Copyright © 2018 Red Hat, Inc. and others.
3  *
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
7  */
8 package org.opendaylight.infrautils.inject.guice.test;
9
10 import static com.google.common.truth.Truth.assertThat;
11
12 import java.util.HashMap;
13 import java.util.HashSet;
14 import java.util.Map;
15 import java.util.Set;
16 import org.junit.Test;
17 import org.opendaylight.infrautils.inject.ClassPathScanner;
18
19 public class ClassPathScannerTest {
20
21     private static final String PREFIX = "org.opendaylight.infrautils.inject.guice.test";
22
23     @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);
32     }
33
34     @Test
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();
41     }
42 }