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

config.CRLFLogConverter without any Tests #20138

Closed
1 task done
giraone opened this issue Oct 27, 2022 · 0 comments · Fixed by #24699
Closed
1 task done

config.CRLFLogConverter without any Tests #20138

giraone opened this issue Oct 27, 2022 · 0 comments · Fixed by #24699

Comments

@giraone
Copy link

giraone commented Oct 27, 2022

Overview of the issue

With 7.9.3 a new class config.CRLFLogConverter was introduced. Unfortunately without any tests. This is always a problem of generated classes, because then a JHipster upgrade has an influence on the code coverage of the project. Because of our company rules on at least 50% on new code, I had to write the test myself to commit the upgrade.

Code is below. Please integrate it after a review - I do not fully understand the semantic of the class.

Motivation for or Use Case
Reproduce the error
Related issues
Suggest a Fix
package io.github.jhipster.sample.config;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.LoggingEvent;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiElement;

import static io.github.jhipster.sample.config.CRLFLogConverter.CRLF_SAFE_MARKER;
import static org.assertj.core.api.Assertions.assertThat;

class CRLFLogConverterTest {

    @Test
    void transformForUnsafe() {

        // arrange
        CRLFLogConverter cut = new CRLFLogConverter();
        Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(CRLFLogConverterTest.class);
        LoggingEvent loggingEvent = new LoggingEvent("fqcn", logger, Level.INFO, "message", null, null);
        // act
        String input = "line11\tline12\nline2\r\nline3";
        String result = cut.transform(loggingEvent, input);
        // assert
        assertThat(result).isEqualTo("line11_line12_line2__line3");
    }

    @Test
    void transformForSafe() {

        // arrange
        CRLFLogConverter cut = new CRLFLogConverter();
        Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(CRLFLogConverterTest.class);
        LoggingEvent loggingEvent = new LoggingEvent("fqcn", logger, Level.INFO, "message", null, null);
        loggingEvent.setMarker(CRLF_SAFE_MARKER);
        // act
        String input = "line11\tline12\nline2\r\nline3";
        String result = cut.transform(loggingEvent, input);
        // assert
        assertThat(result).isEqualTo(input);
    }

    @ParameterizedTest
    @CsvSource({
        "org.hibernate,true",
        "org.slf4j,false"
    })
    void isLoggerSafe(String packageName, boolean expected) {

        // arrange
        CRLFLogConverter cut = new CRLFLogConverter();
        Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(packageName);
        LoggingEvent loggingEvent = new LoggingEvent("fqcn", logger, Level.INFO, "message", null, null);
        // act
        boolean result = cut.isLoggerSafe(loggingEvent);
        // assert
        assertThat(result).isEqualTo(expected);
    }

    @Test
    void toAnsiString() {

        // arrange
        CRLFLogConverter cut = new CRLFLogConverter();
        AnsiElement ansiElement = AnsiColor.RED;
        // act
        String result = cut.toAnsiString("input", ansiElement);
        // assert
        assertThat(result).isEqualTo("input");
    }
}
JHipster Version(s)

7.9.3

JHipster configuration
Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System
  • Checking this box is mandatory (this is just to show you read everything)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants