@Test public void getBaseYangTypeTest() throws Exception { final GeneratedTransferObject rootType = mock(GeneratedTransferObject.class); final GeneratedTransferObject innerType = mock(GeneratedTransferObject.class); final GeneratedProperty property = mock(GeneratedProperty.class); final Type type = mock(ConcreteType.class); assertEquals(type, TypeUtils.getBaseYangType(type)); doReturn("value").when(property).getName(); doReturn(type).when(property).getReturnType(); doReturn(rootType).when(innerType).getSuperType(); doReturn(ImmutableList.of(property)).when(rootType).getProperties(); assertEquals(type, TypeUtils.getBaseYangType(innerType)); }
static ConcreteType getBaseYangType(final @NonNull Type type) { if (type instanceof ConcreteType) { return (ConcreteType) type; } checkArgument(type instanceof GeneratedTransferObject, "Unsupported type %s", type); GeneratedTransferObject rootGto = (GeneratedTransferObject) type; while (rootGto.getSuperType() != null) { rootGto = rootGto.getSuperType(); } for (GeneratedProperty s : rootGto.getProperties()) { if (TypeConstants.VALUE_PROP.equals(s.getName())) { return (ConcreteType) s.getReturnType(); } } throw new IllegalArgumentException(String.format("Type %s root %s properties %s do not include \"%s\"", type, rootGto, rootGto.getProperties(), TypeConstants.VALUE_PROP)); }
TypeUtils { static ConcreteType getBaseYangType(final @NonNull Type type) { if (type instanceof ConcreteType) { return (ConcreteType) type; } checkArgument(type instanceof GeneratedTransferObject, "Unsupported type %s", type); GeneratedTransferObject rootGto = (GeneratedTransferObject) type; while (rootGto.getSuperType() != null) { rootGto = rootGto.getSuperType(); } for (GeneratedProperty s : rootGto.getProperties()) { if (TypeConstants.VALUE_PROP.equals(s.getName())) { return (ConcreteType) s.getReturnType(); } } throw new IllegalArgumentException(String.format("Type %s root %s properties %s do not include \"%s\"", type, rootGto, rootGto.getProperties(), TypeConstants.VALUE_PROP)); } }
TypeUtils { static ConcreteType getBaseYangType(final @NonNull Type type) { if (type instanceof ConcreteType) { return (ConcreteType) type; } checkArgument(type instanceof GeneratedTransferObject, "Unsupported type %s", type); GeneratedTransferObject rootGto = (GeneratedTransferObject) type; while (rootGto.getSuperType() != null) { rootGto = rootGto.getSuperType(); } for (GeneratedProperty s : rootGto.getProperties()) { if (TypeConstants.VALUE_PROP.equals(s.getName())) { return (ConcreteType) s.getReturnType(); } } throw new IllegalArgumentException(String.format("Type %s root %s properties %s do not include \"%s\"", type, rootGto, rootGto.getProperties(), TypeConstants.VALUE_PROP)); } private  TypeUtils(); }
TypeUtils { static ConcreteType getBaseYangType(final @NonNull Type type) { if (type instanceof ConcreteType) { return (ConcreteType) type; } checkArgument(type instanceof GeneratedTransferObject, "Unsupported type %s", type); GeneratedTransferObject rootGto = (GeneratedTransferObject) type; while (rootGto.getSuperType() != null) { rootGto = rootGto.getSuperType(); } for (GeneratedProperty s : rootGto.getProperties()) { if (TypeConstants.VALUE_PROP.equals(s.getName())) { return (ConcreteType) s.getReturnType(); } } throw new IllegalArgumentException(String.format("Type %s root %s properties %s do not include \"%s\"", type, rootGto, rootGto.getProperties(), TypeConstants.VALUE_PROP)); } private  TypeUtils();  }
TypeUtils { static ConcreteType getBaseYangType(final @NonNull Type type) { if (type instanceof ConcreteType) { return (ConcreteType) type; } checkArgument(type instanceof GeneratedTransferObject, "Unsupported type %s", type); GeneratedTransferObject rootGto = (GeneratedTransferObject) type; while (rootGto.getSuperType() != null) { rootGto = rootGto.getSuperType(); } for (GeneratedProperty s : rootGto.getProperties()) { if (TypeConstants.VALUE_PROP.equals(s.getName())) { return (ConcreteType) s.getReturnType(); } } throw new IllegalArgumentException(String.format("Type %s root %s properties %s do not include \"%s\"", type, rootGto, rootGto.getProperties(), TypeConstants.VALUE_PROP)); } private  TypeUtils();   }