GeneratorUtil { static Map<String, JavaTypeName> createImports(final GeneratedType genType) { if (genType == null) { throw new IllegalArgumentException("Generated Type cannot be NULL!"); } final Map<String, JavaTypeName> imports = new LinkedHashMap<>(); List<GeneratedType> childGeneratedTypes = genType.getEnclosedTypes(); if (!childGeneratedTypes.isEmpty()) { for (GeneratedType genTypeChild : childGeneratedTypes) { imports.putAll(createImports(genTypeChild)); } } if (genType instanceof GeneratedTransferObject && isConstantInTO(TypeConstants.PATTERN_CONSTANT_NAME, (GeneratedTransferObject) genType)) { putTypeIntoImports(genType, Types.typeForClass(java.util.regex.Pattern.class), imports); } final List<MethodSignature> methods = genType.getMethodDefinitions(); if (methods != null) { for (final MethodSignature method : methods) { final Type methodReturnType = method.getReturnType(); putTypeIntoImports(genType, methodReturnType, imports); for (final MethodSignature.Parameter methodParam : method.getParameters()) { putTypeIntoImports(genType, methodParam.getType(), imports); } for (final AnnotationType at : method.getAnnotations()) { putTypeIntoImports(genType, at, imports); } } } if (genType instanceof GeneratedTransferObject) { final GeneratedTransferObject genTO = (GeneratedTransferObject) genType; final List<GeneratedProperty> properties = genTO.getProperties(); if (properties != null) { for (GeneratedProperty property : properties) { final Type propertyType = property.getReturnType(); putTypeIntoImports(genType, propertyType, imports); } } } return imports; } private  GeneratorUtil();   }
@Test(expected = IllegalArgumentException.class) public void createImportsWithExceptionTest() throws Exception { GeneratorUtil.createImports(null); }
@Test public void createImportsTest() throws Exception { final Map<String, JavaTypeName> generated = createImports(generatedType); assertNotNull(generated); assertEquals(JavaTypeName.create("tst.package", "tstAnnotationName"), generated.get("tstAnnotationName")); }