Add ModuleDependencyInfoTest
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / util / ModuleDependencySortTest.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o.  All rights reserved.
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.yangtools.yang.parser.util;
9
10 import static com.google.common.collect.ImmutableList.of;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.Mockito.doReturn;
13
14 import com.google.common.collect.ImmutableSet;
15 import java.net.URI;
16 import java.util.List;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.mockito.Mock;
21 import org.mockito.runners.MockitoJUnitRunner;
22 import org.opendaylight.yangtools.yang.common.QNameModule;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24
25 @RunWith(MockitoJUnitRunner.class)
26 public class ModuleDependencySortTest {
27     private static final QNameModule TEST = QNameModule.create(URI.create("foo"), null);
28
29     @Mock
30     private Module fooNoRev;
31
32     @Before
33     public void before() {
34         doReturn(ImmutableSet.of()).when(fooNoRev).getImports();
35         doReturn("foo").when(fooNoRev).getName();
36         doReturn(TEST).when(fooNoRev).getQNameModule();
37         doReturn(TEST.getNamespace()).when(fooNoRev).getNamespace();
38         doReturn(TEST.getRevision()).when(fooNoRev).getRevision();
39     }
40
41     @Test
42     public void testSimpleModules() {
43         assertSortedTo(of(fooNoRev), fooNoRev);
44     }
45
46     private static void assertSortedTo(final List<Module> expected, final Module... modules) {
47         assertEquals(expected, ModuleDependencySort.sort(modules));
48     }
49 }