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.controller.yang.parser.util;
10 import static org.hamcrest.core.Is.is;
11 import static org.junit.Assert.assertThat;
13 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.controller.yang.parser.util.TopologicalSort.Node;
18 import org.opendaylight.controller.yang.parser.util.TopologicalSort.NodeImpl;
20 import com.google.common.collect.Sets;
22 public class TopologicalSortTest {
24 @Test(expected = IllegalStateException.class)
25 public void test() throws Exception {
26 Set<Node> nodes = Sets.newHashSet();
28 NodeImpl node1 = new NodeImpl();
30 NodeImpl node2 = new NodeImpl();
32 NodeImpl node3 = new NodeImpl();
40 TopologicalSort.sort(nodes);
41 } catch (IllegalStateException e) {
47 public void testValidSimple() throws Exception {
48 Set<Node> nodes = Sets.newHashSet();
50 Node node1 = new NodeImpl();
52 Node node2 = new NodeImpl();
54 Node node3 = new NodeImpl();
56 Node node4 = new NodeImpl();
59 ((NodeImpl) node1).addEdge(node2);
60 ((NodeImpl) node1).addEdge(node3);
61 ((NodeImpl) node2).addEdge(node4);
62 ((NodeImpl) node3).addEdge(node2);
64 List<Node> sorted = TopologicalSort.sort(nodes);
66 assertThat(sorted.get(0), is(node4));
67 assertThat(sorted.get(1), is(node2));
68 assertThat(sorted.get(2), is(node3));
69 assertThat(sorted.get(3), is(node1));