From 0b9061f99d06187b21414342a1a13ccf754efa2c Mon Sep 17 00:00:00 2001 From: sanagaraj-pivotal Date: Mon, 8 Aug 2022 13:46:23 +0100 Subject: [PATCH] Fixing failed unit tests which were trying to mock a static function --- .../org/springframework/sbm/engine/git/GitSupport.java | 2 +- .../recipes/Boot_24_25_UpgradeReportRecipeTest.java | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/components/sbm-core/src/main/java/org/springframework/sbm/engine/git/GitSupport.java b/components/sbm-core/src/main/java/org/springframework/sbm/engine/git/GitSupport.java index c06e3e331..087d66ee8 100644 --- a/components/sbm-core/src/main/java/org/springframework/sbm/engine/git/GitSupport.java +++ b/components/sbm-core/src/main/java/org/springframework/sbm/engine/git/GitSupport.java @@ -107,7 +107,7 @@ public Commit commit(File repo, String message) { * * @param repo the location of the repo */ - public static Optional getLatestCommit(File repo) { + public Optional getLatestCommit(File repo) { try { Git git = getRepository(repo); Iterable revCommits = git.log() diff --git a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_24_25/recipes/Boot_24_25_UpgradeReportRecipeTest.java b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_24_25/recipes/Boot_24_25_UpgradeReportRecipeTest.java index 4dcc5836d..2fb72f0ee 100644 --- a/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_24_25/recipes/Boot_24_25_UpgradeReportRecipeTest.java +++ b/components/sbm-recipes-boot-upgrade/src/test/java/org/springframework/sbm/boot/upgrade_24_25/recipes/Boot_24_25_UpgradeReportRecipeTest.java @@ -15,15 +15,13 @@ */ package org.springframework.sbm.boot.upgrade_24_25.recipes; -import org.springframework.sbm.engine.git.Commit; import org.springframework.sbm.engine.git.GitSupport; +import org.springframework.sbm.project.resource.SbmApplicationProperties; import org.springframework.sbm.test.RecipeIntegrationTestSupport; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; - -import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; @@ -47,7 +45,8 @@ void generateReportTest() throws IOException { Path resultDir = RecipeIntegrationTestSupport.getResultDir(applicationDir); String generatedReportContent = replaceDynamicPartsInReport(resultDir.resolve("Upgrade-Spring-Boot-2.4-to-2.5.html"), resultDir); - String revision = GitSupport.getLatestCommit(resultDir.toAbsolutePath().toFile()).get().getHash(); + GitSupport gitSupport = new GitSupport(new SbmApplicationProperties()); + String revision = gitSupport.getLatestCommit(resultDir.toAbsolutePath().toFile()).get().getHash(); String expectedReport = getContent(new ClassPathResource("/expected-report").getFile().toPath()) @@ -70,5 +69,4 @@ private String getContent(Path report) throws IOException { Charset charset = StandardCharsets.UTF_8; return new String(Files.readAllBytes(report), charset).replaceAll("\n$", ""); } - }