@Test public void testCalculateClassName() { Module module = mock(Module.class); Package defaultPackage = mock(Package.class); Path javaFile1Main = Paths.convert(testRootPath.resolve(JAVA_FILE_1_MAIN_PATH)); Path javaFile1Test = Paths.convert(testRootPath.resolve(JAVA_FILE_1_TEST_PATH)); Path javaFile2Main = Paths.convert(testRootPath.resolve(JAVA_FILE_2_MAIN_PATH)); Path javaFile2Test = Paths.convert(testRootPath.resolve(JAVA_FILE_2_TEST_PATH)); Path javaFile3Main = Paths.convert(testRootPath.resolve(JAVA_FILE_3_MAIN_PATH)); Path javaFile3Test = Paths.convert(testRootPath.resolve(JAVA_FILE_3_TEST_PATH)); Path javaFileInOtherModule = Paths.convert(testRootPath.resolve(JAVA_FILE_IN_OTHER_MODULE)); assertNull(serviceHelper.calculateClassName(module, null)); assertNull(serviceHelper.calculateClassName(module, javaFile1Main)); assertNull(serviceHelper.calculateClassName(module, javaFile1Test)); assertNull(serviceHelper.calculateClassName(module, javaFile2Main)); assertNull(serviceHelper.calculateClassName(module, javaFile2Test)); assertNull(serviceHelper.calculateClassName(module, javaFile3Main)); assertNull(serviceHelper.calculateClassName(module, javaFile3Test)); assertNull(serviceHelper.calculateClassName(module, javaFileInOtherModule)); when(moduleService.resolveDefaultPackage(module)).thenReturn(defaultPackage); Path mainSrcPath = Paths.convert(testRootPath.resolve("myProject/src/main/java")); Path testSrcPath = Paths.convert(testRootPath.resolve("myProject/src/test/java")); when(defaultPackage.getPackageMainSrcPath()).thenReturn(mainSrcPath); when(defaultPackage.getPackageTestSrcPath()).thenReturn(testSrcPath); assertNull(serviceHelper.calculateClassName(module, null)); assertEquals(JAVA_FILE_1_CLASS, serviceHelper.calculateClassName(module, javaFile1Main)); assertEquals(JAVA_FILE_1_CLASS, serviceHelper.calculateClassName(module, javaFile1Test)); assertEquals(JAVA_FILE_2_CLASS, serviceHelper.calculateClassName(module, javaFile2Main)); assertEquals(JAVA_FILE_2_CLASS, serviceHelper.calculateClassName(module, javaFile2Test)); assertEquals(JAVA_FILE_3_CLASS, serviceHelper.calculateClassName(module, javaFile3Main)); assertEquals(JAVA_FILE_3_CLASS, serviceHelper.calculateClassName(module, javaFile3Test)); assertNull(serviceHelper.calculateClassName(module, javaFileInOtherModule)); }
public String calculateClassName(final Module module, final org.uberfire.backend.vfs.Path path) { PortablePreconditions.checkNotNull("module", module); if (path == null) { return null; } final Package defaultPackage = moduleService.resolveDefaultPackage(module); if (defaultPackage == null) { return null; } final Path mainSrcNioPath = Paths.convert(defaultPackage.getPackageMainSrcPath()); final Path testSrcNioPath = Paths.convert(defaultPackage.getPackageTestSrcPath()); final Path nioPath = Paths.convert(path); Path relativePath = null; if (mainSrcNioPath != null && nioPath.startsWith(mainSrcNioPath)) { relativePath = mainSrcNioPath.relativize(nioPath); } else if (testSrcNioPath != null && nioPath.startsWith(testSrcNioPath)) { relativePath = testSrcNioPath.relativize(nioPath); } if (relativePath != null) { String className = relativePath.toString().replace("/", "."); return className.substring(0, className.lastIndexOf(".java")); } return null; }
DataModelerServiceHelper { public String calculateClassName(final Module module, final org.uberfire.backend.vfs.Path path) { PortablePreconditions.checkNotNull("module", module); if (path == null) { return null; } final Package defaultPackage = moduleService.resolveDefaultPackage(module); if (defaultPackage == null) { return null; } final Path mainSrcNioPath = Paths.convert(defaultPackage.getPackageMainSrcPath()); final Path testSrcNioPath = Paths.convert(defaultPackage.getPackageTestSrcPath()); final Path nioPath = Paths.convert(path); Path relativePath = null; if (mainSrcNioPath != null && nioPath.startsWith(mainSrcNioPath)) { relativePath = mainSrcNioPath.relativize(nioPath); } else if (testSrcNioPath != null && nioPath.startsWith(testSrcNioPath)) { relativePath = testSrcNioPath.relativize(nioPath); } if (relativePath != null) { String className = relativePath.toString().replace("/", "."); return className.substring(0, className.lastIndexOf(".java")); } return null; } }
DataModelerServiceHelper { public String calculateClassName(final Module module, final org.uberfire.backend.vfs.Path path) { PortablePreconditions.checkNotNull("module", module); if (path == null) { return null; } final Package defaultPackage = moduleService.resolveDefaultPackage(module); if (defaultPackage == null) { return null; } final Path mainSrcNioPath = Paths.convert(defaultPackage.getPackageMainSrcPath()); final Path testSrcNioPath = Paths.convert(defaultPackage.getPackageTestSrcPath()); final Path nioPath = Paths.convert(path); Path relativePath = null; if (mainSrcNioPath != null && nioPath.startsWith(mainSrcNioPath)) { relativePath = mainSrcNioPath.relativize(nioPath); } else if (testSrcNioPath != null && nioPath.startsWith(testSrcNioPath)) { relativePath = testSrcNioPath.relativize(nioPath); } if (relativePath != null) { String className = relativePath.toString().replace("/", "."); return className.substring(0, className.lastIndexOf(".java")); } return null; } DataModelerServiceHelper(); @Inject  DataModelerServiceHelper(final KieModuleService moduleService,
                                    final @Named("ioStrategy") IOService ioService,
                                    final CommentedOptionFactory commentedOptionFactory); }
DataModelerServiceHelper { public String calculateClassName(final Module module, final org.uberfire.backend.vfs.Path path) { PortablePreconditions.checkNotNull("module", module); if (path == null) { return null; } final Package defaultPackage = moduleService.resolveDefaultPackage(module); if (defaultPackage == null) { return null; } final Path mainSrcNioPath = Paths.convert(defaultPackage.getPackageMainSrcPath()); final Path testSrcNioPath = Paths.convert(defaultPackage.getPackageTestSrcPath()); final Path nioPath = Paths.convert(path); Path relativePath = null; if (mainSrcNioPath != null && nioPath.startsWith(mainSrcNioPath)) { relativePath = mainSrcNioPath.relativize(nioPath); } else if (testSrcNioPath != null && nioPath.startsWith(testSrcNioPath)) { relativePath = testSrcNioPath.relativize(nioPath); } if (relativePath != null) { String className = relativePath.toString().replace("/", "."); return className.substring(0, className.lastIndexOf(".java")); } return null; } 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); }
DataModelerServiceHelper { public String calculateClassName(final Module module, final org.uberfire.backend.vfs.Path path) { PortablePreconditions.checkNotNull("module", module); if (path == null) { return null; } final Package defaultPackage = moduleService.resolveDefaultPackage(module); if (defaultPackage == null) { return null; } final Path mainSrcNioPath = Paths.convert(defaultPackage.getPackageMainSrcPath()); final Path testSrcNioPath = Paths.convert(defaultPackage.getPackageTestSrcPath()); final Path nioPath = Paths.convert(path); Path relativePath = null; if (mainSrcNioPath != null && nioPath.startsWith(mainSrcNioPath)) { relativePath = mainSrcNioPath.relativize(nioPath); } else if (testSrcNioPath != null && nioPath.startsWith(testSrcNioPath)) { relativePath = testSrcNioPath.relativize(nioPath); } if (relativePath != null) { String className = relativePath.toString().replace("/", "."); return className.substring(0, className.lastIndexOf(".java")); } return null; } 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);  }