Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mockito inline #3156

Merged
merged 1 commit into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,6 @@
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<!--Explicitly added for the latest versions of Mockito (> 4.5.0) to be working-->
<groupId>net.bytebuddy</groupId>
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/tech/jhipster/lite/JHLiteApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;
import tech.jhipster.lite.common.domain.Generated;

@Generated(reason = "Not interesting and hard to test")
@SpringBootApplication
public class JHLiteApp {

Expand Down Expand Up @@ -45,44 +47,44 @@ private static void logApplicationStartup(Environment env) {
log.info(welcomeMessage);
}

public static String applicationRunning(String value) {
private static String applicationRunning(String value) {
return String.format(" Application '%s' is running!", value) + LF;
}

public static String accessUrlLocal(String protocol, String serverPort, String contextPath) {
private static String accessUrlLocal(String protocol, String serverPort, String contextPath) {
if (StringUtils.isBlank(serverPort)) {
return "";
}
return String.format(" Local: \t%s://localhost:%s%s", protocol, serverPort, contextPath) + LF;
}

public static String accessUrlExternal(String protocol, String hostAddress, String serverPort, String contextPath) {
private static String accessUrlExternal(String protocol, String hostAddress, String serverPort, String contextPath) {
if (StringUtils.isBlank(serverPort)) {
return "";
}
return String.format(" External: \t%s://%s:%s%s", protocol, hostAddress, serverPort, contextPath) + LF;
}

public static String profile(String profiles) {
private static String profile(String profiles) {
return String.format(" Profile(s): \t%s", profiles) + LF;
}

public static String configServer(String configServerStatus) {
private static String configServer(String configServerStatus) {
if (StringUtils.isBlank(configServerStatus)) {
return "";
}
return LF + String.format(" Config Server: %s", configServerStatus) + LF + SEPARATOR + LF;
}

public static String getProtocol(String value) {
private static String getProtocol(String value) {
return Optional.ofNullable(value).map(key -> "https").orElse("http");
}

public static String getContextPath(String value) {
private static String getContextPath(String value) {
return Optional.ofNullable(value).filter(StringUtils::isNotBlank).orElse("/");
}

public static String getHostAddress() {
private static String getHostAddress() {
String hostAddress = "localhost";
try {
hostAddress = InetAddress.getLocalHost().getHostAddress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.function.Consumer;
import org.springframework.stereotype.Repository;
import tech.jhipster.lite.common.domain.FileUtils;
import tech.jhipster.lite.common.domain.Generated;
import tech.jhipster.lite.error.domain.Assert;
import tech.jhipster.lite.error.domain.GeneratorException;
import tech.jhipster.lite.generator.project.domain.FilePath;
Expand All @@ -20,6 +21,7 @@
import tech.jhipster.lite.generator.project.domain.ProjectRepository;

@Repository
@Generated(reason = "Candidate for deletion")
public class ProjectLocalRepository implements ProjectRepository {

private static final String FILE_SEPARATOR = "/";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package tech.jhipster.lite.technical.infrastructure.primary.exception;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpHeaders;
Expand All @@ -16,73 +13,6 @@ public final class HeaderUtil {

private HeaderUtil() {}

/**
* <p>createAlert.</p>
*
* @param applicationName a {@link String} object.
* @param message a {@link String} object.
* @param param a {@link String} object.
* @return a {@link HttpHeaders} object.
*/
public static HttpHeaders createAlert(String applicationName, String message, String param) {
HttpHeaders headers = new HttpHeaders();
headers.add("X-" + applicationName + "-alert", message);
try {
headers.add("X-" + applicationName + "-params", URLEncoder.encode(param, StandardCharsets.UTF_8.toString()));
} catch (UnsupportedEncodingException e) {
// StandardCharsets are supported by every Java implementation so this exception will never happen
}
return headers;
}

/**
* <p>createEntityCreationAlert.</p>
*
* @param applicationName a {@link String} object.
* @param enableTranslation a boolean.
* @param entityName a {@link String} object.
* @param param a {@link String} object.
* @return a {@link HttpHeaders} object.
*/
public static HttpHeaders createEntityCreationAlert(String applicationName, boolean enableTranslation, String entityName, String param) {
String message = enableTranslation
? applicationName + "." + entityName + ".created"
: "A new " + entityName + " is created with identifier " + param;
return createAlert(applicationName, message, param);
}

/**
* <p>createEntityUpdateAlert.</p>
*
* @param applicationName a {@link String} object.
* @param enableTranslation a boolean.
* @param entityName a {@link String} object.
* @param param a {@link String} object.
* @return a {@link HttpHeaders} object.
*/
public static HttpHeaders createEntityUpdateAlert(String applicationName, boolean enableTranslation, String entityName, String param) {
String message = enableTranslation
? applicationName + "." + entityName + ".updated"
: "A " + entityName + " is updated with identifier " + param;
return createAlert(applicationName, message, param);
}

/**
* <p>createEntityDeletionAlert.</p>
*
* @param applicationName a {@link String} object.
* @param enableTranslation a boolean.
* @param entityName a {@link String} object.
* @param param a {@link String} object.
* @return a {@link HttpHeaders} object.
*/
public static HttpHeaders createEntityDeletionAlert(String applicationName, boolean enableTranslation, String entityName, String param) {
String message = enableTranslation
? applicationName + "." + entityName + ".deleted"
: "A " + entityName + " is deleted with identifier " + param;
return createAlert(applicationName, message, param);
}

/**
* <p>createFailureAlert.</p>
*
Expand Down
144 changes: 0 additions & 144 deletions src/test/java/tech/jhipster/lite/JHLiteAppTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
package tech.jhipster.lite.generator.project.infrastructure.secondary;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static tech.jhipster.lite.TestUtils.*;
import static tech.jhipster.lite.common.domain.FileUtils.*;
import static tech.jhipster.lite.generator.project.domain.Constants.*;

import com.github.mustachejava.MustacheNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import tech.jhipster.lite.TestFileUtils;
import tech.jhipster.lite.UnitTest;
import tech.jhipster.lite.error.domain.GeneratorException;
import tech.jhipster.lite.error.domain.MissingMandatoryValueException;
Expand All @@ -44,18 +35,6 @@ void shouldNotAddFileToUnknownFolder() {
assertThatThrownBy(() -> repository.add(file)).isExactlyInstanceOf(GeneratorException.class);
}

@Test
void shouldHandleCopyError() {
Project project = tmpProject();

try (MockedStatic<Files> files = Mockito.mockStatic(Files.class)) {
files.when(() -> Files.copy(any(InputStream.class), any(Path.class), any(CopyOption.class))).thenThrow(new IOException());

ProjectFile file = ProjectFile.forProject(project).withSource("mustache", "README.txt").withSameDestination();
assertThatThrownBy(() -> repository.add(file)).isInstanceOf(GeneratorException.class);
}
}

@Test
void shouldAddFiles() {
Project project = tmpProject();
Expand All @@ -67,18 +46,6 @@ void shouldAddFiles() {
assertFileExist(project, "gitignore");
}

@Test
void shouldHandleTemplatingError() {
Project project = Project.builder().folder(TestFileUtils.tmpDirForTest()).build();

try (MockedStatic<MustacheUtils> mustacheUtils = Mockito.mockStatic(MustacheUtils.class)) {
mustacheUtils.when(() -> MustacheUtils.template(anyString(), any())).thenThrow(new IOException());

List<ProjectFile> files = List.of(ProjectFile.forProject(project).withSource("mustache", README_MD).withSameDestination());
assertThatThrownBy(() -> repository.template(files)).isExactlyInstanceOf(GeneratorException.class);
}
}

@Test
void shouldNotTemplateForUnknownFile() {
Project project = tmpProject();
Expand Down
Loading