Remove deprecated Types methods
[mdsal.git] / binding / mdsal-binding-java-api-generator / src / test / java / org / opendaylight / mdsal / binding / java / api / generator / TypeUtilsTest.java
1 /*
2  * Copyright (c) 2016 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.mdsal.binding.java.api.generator;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.junit.Assert.fail;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15
16 import com.google.common.collect.ImmutableList;
17 import java.lang.reflect.Constructor;
18 import java.lang.reflect.InvocationTargetException;
19 import org.junit.Test;
20 import org.opendaylight.mdsal.binding.model.api.ConcreteType;
21 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
22 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
23 import org.opendaylight.mdsal.binding.model.api.Type;
24
25 public class TypeUtilsTest {
26
27     @Test
28     public void getBaseYangTypeTest() throws Exception {
29         final GeneratedTransferObject rootType = mock(GeneratedTransferObject.class);
30         final GeneratedTransferObject innerType = mock(GeneratedTransferObject.class);
31         final GeneratedProperty property = mock(GeneratedProperty.class);
32         final Type type = mock(ConcreteType.class);
33         assertEquals(type, TypeUtils.getBaseYangType(type));
34
35         doReturn("value").when(property).getName();
36         doReturn(type).when(property).getReturnType();
37         doReturn(rootType).when(innerType).getSuperType();
38         doReturn(ImmutableList.of(property)).when(rootType).getProperties();
39         assertEquals(type, TypeUtils.getBaseYangType(innerType));
40     }
41
42     @Test(expected = IllegalArgumentException.class)
43     public void getBaseYangTypeWithExceptionTest() throws Exception {
44         final GeneratedTransferObject rootType = mock(GeneratedTransferObject.class);
45         final GeneratedTransferObject innerType = mock(GeneratedTransferObject.class);
46         final GeneratedProperty property = mock(GeneratedProperty.class);
47
48         doReturn("test").when(property).getName();
49         doReturn(rootType).when(innerType).getSuperType();
50         doReturn(ImmutableList.of(property)).when(rootType).getProperties();
51         TypeUtils.getBaseYangType(innerType);
52     }
53
54     @Test
55     public void constructTest() throws ReflectiveOperationException {
56         final Constructor<TypeUtils> constructor = TypeUtils.class.getDeclaredConstructor();
57         constructor.setAccessible(true);
58         try {
59             constructor.newInstance();
60             fail();
61         } catch (InvocationTargetException e) {
62             assertTrue(e.getCause() instanceof UnsupportedOperationException);
63         }
64     }
65 }