Repository: jhipster/jhipster-lite
Pull request #10389 (2024-07-25 16:09:27)

Prettier config improvements
- node_modules and version control systems directories are already ignored by default: https://prettier.io/docs/en/ignore.html#ignoring-files-prettierignore
- there's no particular reason for ignoring .mvn folder
- use correct formating for .prettierrc


Patch:
diff --git a/.prettierignore b/.prettierignore
index d925baac2..beb941558 100644
--- a/.prettierignore
+++ b/.prettierignore
@@ -1,5 +1,3 @@
-node_modules/
 target/
 package-lock.json
-.git/
 template-infinitest.filters
diff --git a/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactory.java
index 02b4cff4a..94af7af14 100644
--- a/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/client/angular/security/oauth2/domain/AngularOauth2ModuleFactory.java
@@ -58,6 +58,7 @@ public class AngularOauth2ModuleFactory {
   private static final String TEST_IMPORTS =
     """
     import { By } from '@angular/platform-browser';
+    import { Oauth2AuthService } from './auth/oauth2-auth.service';
     import LoginComponent from './login/login.component';
     """;
   private static final ElementReplacer TEST_NEEDLE = lineAfterRegex("^\\s+it\\('should have appName',[^}]+\\}\\);");
@@ -91,6 +92,20 @@ public class AngularOauth2ModuleFactory {
 
   private static final ElementReplacer INJECT_NEEDLE = text("import { Component, OnInit, signal } from '@angular/core';");
 
+  private static final ElementReplacer BEFORE_EACH_NEEDLE = lineAfterRegex("comp = fixture.componentInstance;");
+
+  private static final String TESTBED_INJECT_OAUTH2_AUTH_SERVICE =
+    """
+        oauth2AuthService = TestBed.inject(Oauth2AuthService);\
+    """;
+
+  private static final ElementReplacer TEST_APP_COMPONENT = lineAfterRegex("let comp: AppComponent;");
+
+  private static final String DECLARE_INJECT_OAUTH2_AUTH_SERVICE =
+    """
+      let oauth2AuthService: Oauth2AuthService;\
+    """;
+
   private static final String LOGIN_COMPONENT_TEST =
     """
 
@@ -163,6 +178,8 @@ public class AngularOauth2ModuleFactory {
         .in(path("src/main/webapp/app/app.component.spec.ts"))
           .add(fileStart(), TEST_IMPORTS)
           .add(TEST_NEEDLE, LOGIN_COMPONENT_TEST.indent(indentation.spacesCount() * 2))
+          .add(BEFORE_EACH_NEEDLE, TESTBED_INJECT_OAUTH2_AUTH_SERVICE)
+          .add(TEST_APP_COMPONENT, DECLARE_INJECT_OAUTH2_AUTH_SERVICE)
           .and()
         .in(path("src/main/webapp/app/app.component.html"))
           .add(MENU_NEEDLE, indentation.spaces() + "<jhi-login></jhi-login>")
diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/git/GitCommitException.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/git/GitCommitException.java
index 82cc5d21d..19208de4b 100644
--- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/git/GitCommitException.java
+++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/git/GitCommitException.java
@@ -7,8 +7,4 @@ class GitCommitException extends GeneratorException {
   public GitCommitException(String message, Throwable cause) {
     super(internalServerError(GitErrorKey.COMMIT_ERROR).message(message).cause(cause));
   }
-
-  public GitCommitException(String message) {
-    super(internalServerError(GitErrorKey.COMMIT_ERROR).message(message));
-  }
 }
diff --git a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/git/JGitGitRepository.java b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/git/JGitGitRepository.java
index fd974236b..8610b2e6a 100644
--- a/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/git/JGitGitRepository.java
+++ b/src/main/java/tech/jhipster/lite/module/infrastructure/secondary/git/JGitGitRepository.java
@@ -2,7 +2,6 @@ package tech.jhipster.lite.module.infrastructure.secondary.git;
 
 import java.io.File;
 import java.io.IOException;
-import java.util.Optional;
 import org.eclipse.jgit.api.Git;
 import org.eclipse.jgit.api.errors.GitAPIException;
 import org.eclipse.jgit.api.errors.JGitInternalException;
@@ -14,7 +13,6 @@ import tech.jhipster.lite.module.domain.git.GitCommitMessage;
 import tech.jhipster.lite.module.domain.git.GitRepository;
 import tech.jhipster.lite.module.domain.properties.JHipsterProjectFolder;
 import tech.jhipster.lite.shared.error.domain.Assert;
-import tech.jhipster.lite.shared.generation.domain.ExcludeFromGeneratedCodeCoverage;
 
 @Repository
 class JGitGitRepository implements GitRepository {
@@ -39,23 +37,20 @@ class JGitGitRepository implements GitRepository {
   }
 
   private boolean isGit(JHipsterProjectFolder folder) {
-    return findGitDirectory(folder).isPresent();
-  }
-
-  private Optional<File> findGitDirectory(JHipsterProjectFolder folder) {
     FileRepositoryBuilder repositoryBuilder = new FileRepositoryBuilder();
-    return Optional.ofNullable(repositoryBuilder.findGitDir(folderFile(folder)).getGitDir());
+    repositoryBuilder.findGitDir(folderFile(folder));
+
+    return repositoryBuilder.getGitDir() != null;
   }
 
   @Override
-  @ExcludeFromGeneratedCodeCoverage(reason = "IOException are hard to test")
   public void commitAll(JHipsterProjectFolder folder, GitCommitMessage message) {
     Assert.notNull("folder", folder);
     Assert.notNull("message", message);
 
-    File gitRepository = findGitDirectory(folder).orElseThrow(() -> new GitCommitException("Can't commit in non existing git repository"));
+    File folderFile = folderFile(folder);
 
-    try (Git gitFolder = Git.open(gitRepository)) {
+    try (Git gitFolder = Git.open(folderFile)) {
       gitFolder.add().setUpdate(true).addFilepattern(".").call(); // stage modified and deleted
       gitFolder.add().addFilepattern(".").call(); // stage modified and new
 
diff --git a/src/main/resources/generator/prettier/.prettierignore b/src/main/resources/generator/prettier/.prettierignore
index ab0567f5c..a245c7727 100644
--- a/src/main/resources/generator/prettier/.prettierignore
+++ b/src/main/resources/generator/prettier/.prettierignore
@@ -1,8 +1,5 @@
-node_modules
 target
 build
 package-lock.json
-.git
-.mvn
 gradle
 .gradle
diff --git a/src/main/resources/generator/prettier/.prettierrc.mustache b/src/main/resources/generator/prettier/.prettierrc.mustache
index 685455bab..71ed128e0 100644
--- a/src/main/resources/generator/prettier/.prettierrc.mustache
+++ b/src/main/resources/generator/prettier/.prettierrc.mustache
@@ -4,7 +4,7 @@ printWidth: 140
 singleQuote: true
 tabWidth: {{indentSize}}
 useTabs: false
-endOfLine: "{{endOfLine}}"
+endOfLine: '{{endOfLine}}'
 
 plugins:
   - '@prettier/plugin-xml'


Test patch:
diff --git a/src/test/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactoryTest.java
index f6c4d166c..fc66ce4e6 100644
--- a/src/test/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/prettier/domain/PrettierModuleFactoryTest.java
@@ -33,7 +33,7 @@ class PrettierModuleFactoryTest {
       .and()
       .hasFile(".prettierrc")
       .containing("tabWidth: 4")
-      .containing("endOfLine: \"crlf\"")
+      .containing("endOfLine: 'crlf'")
       .containing("@prettier/plugin-xml")
       .containing("prettier-plugin-gherkin")
       .containing("prettier-plugin-java")
diff --git a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/git/JGitGitRepositoryTest.java b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/git/JGitGitRepositoryTest.java
index 38517af45..02ff14705 100644
--- a/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/git/JGitGitRepositoryTest.java
+++ b/src/test/java/tech/jhipster/lite/module/infrastructure/secondary/git/JGitGitRepositoryTest.java
@@ -5,9 +5,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
 import ch.qos.logback.classic.Level;
 import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.nio.file.*;
 import java.nio.file.attribute.PosixFilePermission;
 import java.util.Set;
 import org.junit.jupiter.api.Nested;
@@ -95,19 +93,6 @@ class JGitGitRepositoryTest {
       assertThat(GitTestUtil.getCommits(path)).contains("Add dummy.txt");
       assertThat(GitTestUtil.getCurrentBranch(path)).contains("main");
     }
-
-    @Test
-    void shouldCommitAllFilesInSubfolderOfAlreadyInitializedGitRepository() throws IOException {
-      Path gitDirectory = gitInit();
-      Path subFolder = gitDirectory.resolve("subFolder");
-      Files.createDirectories(subFolder);
-      Files.copy(Paths.get("src/test/resources/projects/files/dummy.txt"), subFolder.resolve("dummy.txt"));
-
-      git.commitAll(new JHipsterProjectFolder(subFolder.toString()), "Add dummy.txt");
-
-      assertThat(GitTestUtil.getCommits(subFolder)).contains("Add dummy.txt");
-      assertThat(GitTestUtil.getCurrentBranch(subFolder)).contains("main");
-    }
   }
 
   private Path gitInit() throws IOException {