2 * Copyright (c) 2013 Cisco Systems, 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.yangtools.util;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertThrows;
13 import java.util.HashSet;
14 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.util.TopologicalSort.Node;
18 import org.opendaylight.yangtools.util.TopologicalSort.NodeImpl;
20 public class TopologicalSortTest {
24 Set<Node> nodes = new HashSet<>();
26 NodeImpl node1 = new NodeImpl();
28 NodeImpl node2 = new NodeImpl();
30 NodeImpl node3 = new NodeImpl();
37 assertThrows(IllegalStateException.class, () -> TopologicalSort.sort(nodes));
41 public void testValidSimple() throws Exception {
42 Set<Node> nodes = new HashSet<>();
44 NodeImpl node1 = new NodeImpl();
46 NodeImpl node2 = new NodeImpl();
48 NodeImpl node3 = new NodeImpl();
50 Node node4 = new NodeImpl();
58 List<Node> sorted = TopologicalSort.sort(nodes);
60 assertEquals(node4, sorted.get(0));
61 assertEquals(node2, sorted.get(1));
62 assertEquals(node3, sorted.get(2));
63 assertEquals(node1, sorted.get(3));