Cleaned up Java Binding code from YANG Tools
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / yangtools / sal / binding / yang / types / UnionDependencySortTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  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.sal.binding.yang.types;
9
10 import static org.junit.Assert.assertNotNull;
11
12 import com.google.common.base.Optional;
13 import java.util.HashSet;
14 import java.util.List;
15 import java.util.Set;
16 import org.junit.Rule;
17 import org.junit.Test;
18 import org.junit.rules.ExpectedException;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
21 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
22 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
23 import org.opendaylight.yangtools.yang.model.util.StringType;
24
25 public class UnionDependencySortTest {
26
27     @Rule
28     public ExpectedException expException = ExpectedException.none();
29
30     @Test
31     public void testSortMethod() {
32
33         final UnionDependencySort unionDependencySort = new UnionDependencySort();
34         final Set<TypeDefinition<?>> typeDefs = new HashSet<>();
35
36         final StringType stringType = StringType.getInstance();
37         final ExtendedType extendedType = ExtendedType.builder(QName.create("ExtendedType1"), stringType, Optional.<String> absent(), Optional.<String> absent(), SchemaPath.create(false, QName.create("Cont1"), QName.create("List1"))).build();
38
39         typeDefs.add(stringType);
40         typeDefs.add(extendedType);
41
42         final List<ExtendedType> sortedExtendedTypes = unionDependencySort.sort(typeDefs);
43         assertNotNull(sortedExtendedTypes);
44
45         expException.expect(IllegalArgumentException.class);
46         expException.expectMessage("Set of Type Definitions cannot be NULL!");
47         unionDependencySort.sort(null);
48     }
49 }