### Question:
DataModelerServiceHelper { public Package ensurePackageStructure(final Module module, final String packageName) { if (packageName == null || "".equals(packageName) || module == null) { return null; } final Package defaultPackage = moduleService.resolveDefaultPackage(module); final Path defaultPackagePath = Paths.convert(defaultPackage.getPackageMainSrcPath()); final String newPackageName = packageName.replace(".", "/"); final Path newPackagePath = defaultPackagePath.resolve(newPackageName); if (!ioService.exists(newPackagePath)) { return moduleService.newPackage(defaultPackage, packageName); } else { return moduleService.resolvePackage(Paths.convert(newPackagePath)); } } DataModelerServiceHelper(); @Inject  DataModelerServiceHelper(final KieModuleService moduleService,
                                    final @Named("ioStrategy") IOService ioService,
                                    final CommentedOptionFactory commentedOptionFactory); List<DataModelerError> toDataModelerError(List<DriverError> errors); List<DataModelerError> toDataModelerError(final List<SyntaxError> syntaxErrors,
                                                     final Path file); List<ValidationMessage> toValidationMessage(final List<DataModelerError> errors); CommentedOption makeCommentedOption(final String commitMessage); Package ensurePackageStructure(final Module module,
                                          final String packageName); Set<String> resolvePackages(final Module project); String calculateClassName(final Module module,
                                     final org.uberfire.backend.vfs.Path path); Path calculateFilePath(final String className,
                                  final Path javaPath);  }### Answer:
@Test public void testEnsurePackageStructureWhenNoValuesProvided() { prepareEnsurePackageTest(); assertNull(serviceHelper.ensurePackageStructure(module, null)); assertNull(serviceHelper.ensurePackageStructure(module, "")); }
@Test public void testEnsurePackageStructureWhenProvidedPackageAlreadyExists() { prepareEnsurePackageTest(); Package existingPackage = mock(Package.class); when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(true); when(moduleService.resolvePackage(any(Path.class))).thenReturn(existingPackage); Package result = serviceHelper.ensurePackageStructure(module, NEW_PACKAGE_NAME); assertEquals(existingPackage, result); verify(moduleService, never()).newPackage(any(Package.class), anyString()); }
@Test public void testEnsurePackageStructureWhenProvidedPackageDoNotExists() { prepareEnsurePackageTest(); Package createdPackage = mock(Package.class); when(ioService.exists(any(org.uberfire.java.nio.file.Path.class))).thenReturn(false); when(moduleService.newPackage(defaultPackage, NEW_PACKAGE_NAME)).thenReturn(createdPackage); Package result = serviceHelper.ensurePackageStructure(module, NEW_PACKAGE_NAME); assertEquals(createdPackage, result); verify(moduleService).newPackage(defaultPackage, NEW_PACKAGE_NAME); }