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;
12 import java.util.HashSet;
13 import java.util.List;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.util.TopologicalSort.Node;
17 import org.opendaylight.yangtools.util.TopologicalSort.NodeImpl;
19 public class TopologicalSortTest {
21 @Test(expected = IllegalStateException.class)
23 Set<Node> nodes = new HashSet<>();
25 NodeImpl node1 = new NodeImpl();
27 NodeImpl node2 = new NodeImpl();
29 NodeImpl node3 = new NodeImpl();
36 // We expect an IllegalStateException here
37 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));