Bug 1131 - yang-parser-impl cleanup
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / util / ModuleDependencySortTest.java
index 203e9e06107d451c454176f0d95a67603f2aca4d..edacfc55727f3d48d42eb0790d21a6c4f39374c0 100644 (file)
@@ -14,15 +14,16 @@ import static org.junit.matchers.JUnitMatchers.containsString;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 
+import com.google.common.collect.Sets;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-
 import org.hamcrest.Matcher;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -31,14 +32,12 @@ import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
 import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort.ModuleNodeImpl;
 import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Edge;
 
-import com.google.common.collect.Sets;
-
 public class ModuleDependencySortTest {
     private final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
-    private ModuleBuilder a = mockModuleBuilder("a", null);
-    private ModuleBuilder b = mockModuleBuilder("b", null);
-    private ModuleBuilder c = mockModuleBuilder("c", null);
-    private ModuleBuilder d = mockModuleBuilder("d", null);
+    private final ModuleBuilder a = mockModuleBuilder("a", null);
+    private final ModuleBuilder b = mockModuleBuilder("b", null);
+    private final ModuleBuilder c = mockModuleBuilder("c", null);
+    private final ModuleBuilder d = mockModuleBuilder("d", null);
 
     @Test
     public void testValid() throws Exception {
@@ -51,7 +50,8 @@ public class ModuleDependencySortTest {
 
         List<ModuleBuilder> l = ModuleDependencySort.sort(builders);
 
-        assertDependencyGraph(ModuleDependencySort.createModuleGraph(Arrays.asList(builders)));
+        assertDependencyGraph(ModuleDependencySort.createModuleGraph(ModuleOrModuleBuilder.fromAll(
+                Collections.<Module>emptySet(), Arrays.asList(builders))));
 
         @SuppressWarnings("unchecked")
         Matcher<String> cOrD = anyOf(is(c.getName()), is(d.getName()));
@@ -118,26 +118,6 @@ public class ModuleDependencySortTest {
         ModuleDependencySort.sort(builders);
     }
 
-    @Test(expected = YangValidationException.class)
-    public void testImportTwiceDifferentRevision() throws Exception {
-        Date date1 = new Date(463846463486L);
-        Date date2 = new Date(364896446683L);
-        b = mockModuleBuilder("b", date1);
-        ModuleBuilder b2 = mockModuleBuilder("b", date2);
-
-        mockDependency(a, b);
-        mockDependency(c, b2);
-
-        ModuleBuilder[] builders = new ModuleBuilder[] { a, c, b, b2 };
-        try {
-            ModuleDependencySort.sort(builders);
-        } catch (YangValidationException e) {
-            assertThat(e.getMessage(), containsString("Module:b imported twice with different revisions:"
-                    + SIMPLE_DATE_FORMAT.format(date1) + ", " + SIMPLE_DATE_FORMAT.format(date2)));
-            throw e;
-        }
-    }
-
     @Test
     public void testModuleTwiceWithDifferentRevs() throws Exception {
         ModuleBuilder a2 = mockModuleBuilder("a", new Date());
@@ -162,7 +142,7 @@ public class ModuleDependencySortTest {
         }
     }
 
-    private void assertDependencyGraph(Map<String, Map<Date, ModuleNodeImpl>> moduleGraph) {
+    private void assertDependencyGraph(final Map<String, Map<Date, ModuleNodeImpl>> moduleGraph) {
         for (Entry<String, Map<Date, ModuleNodeImpl>> node : moduleGraph.entrySet()) {
             String name = node.getKey();
 
@@ -181,26 +161,26 @@ public class ModuleDependencySortTest {
         }
     }
 
-    private void assertEdgeCount(Set<Edge> inEdges, int i, Set<Edge> outEdges, int j) {
+    private void assertEdgeCount(final Set<Edge> inEdges, final int i, final Set<Edge> outEdges, final int j) {
         assertThat(inEdges.size(), is(i));
         assertThat(outEdges.size(), is(j));
     }
 
-    private void mockDependency(ModuleBuilder a, ModuleBuilder b) {
+    private void mockDependency(final ModuleBuilder a, final ModuleBuilder b) {
         ModuleImport imprt = mock(ModuleImport.class);
         doReturn(b.getName()).when(imprt).getModuleName();
         doReturn(b.getRevision()).when(imprt).getRevision();
         a.getModuleImports().add(imprt);
     }
 
-    private void mockDependency(Module a, Module b) {
+    private void mockDependency(final Module a, final Module b) {
         ModuleImport imprt = mock(ModuleImport.class);
         doReturn(b.getName()).when(imprt).getModuleName();
         doReturn(b.getRevision()).when(imprt).getRevision();
         a.getImports().add(imprt);
     }
 
-    private ModuleBuilder mockModuleBuilder(String name, Date rev) {
+    private ModuleBuilder mockModuleBuilder(final String name, final Date rev) {
         ModuleBuilder a = mock(ModuleBuilder.class);
         doReturn(name).when(a).getName();
         Set<ModuleImport> set = Sets.newHashSet();
@@ -211,7 +191,7 @@ public class ModuleDependencySortTest {
         return a;
     }
 
-    private Module mockModule(String name, Date rev) {
+    private Module mockModule(final String name, final Date rev) {
         Module a = mock(Module.class);
         doReturn(name).when(a).getName();
         Set<ModuleImport> set = Sets.newHashSet();