2 * Copyright (c) 2016 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.mdsal.binding.java.api.generator;
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;
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;
25 public class TypeUtilsTest {
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));
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));
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);
48 doReturn("test").when(property).getName();
49 doReturn(rootType).when(innerType).getSuperType();
50 doReturn(ImmutableList.of(property)).when(rootType).getProperties();
51 TypeUtils.getBaseYangType(innerType);
55 public void constructTest() throws ReflectiveOperationException {
56 final Constructor<TypeUtils> constructor = TypeUtils.class.getDeclaredConstructor();
57 constructor.setAccessible(true);
59 constructor.newInstance();
61 } catch (InvocationTargetException e) {
62 assertTrue(e.getCause() instanceof UnsupportedOperationException);