diff --git a/src/main/java/io/github/joselion/prettyjupiter/lib/PrettyLogger.java b/src/main/java/io/github/joselion/prettyjupiter/lib/PrettyLogger.java index f619e00..74f4554 100644 --- a/src/main/java/io/github/joselion/prettyjupiter/lib/PrettyLogger.java +++ b/src/main/java/io/github/joselion/prettyjupiter/lib/PrettyLogger.java @@ -45,9 +45,8 @@ public void logDescriptors(final TestDescriptor descriptor) { if (descriptor.getClassName() != null || isParameterizedTest) { final var tabs = Common.tabsFor(descriptor); - final var desc = Text.colored(Color.WHITE, displayName); - this.project.getLogger().lifecycle(tabs.concat(desc)); + this.project.getLogger().lifecycle(tabs.concat(displayName)); } } @@ -140,9 +139,11 @@ private String getDuration(final TestResult result) { if (duration.getEnabled().get().booleanValue()) { final var timeDiff = result.getEndTime() - result.getStartTime(); final var threshold = duration.getThreshold(testTask); - final var halfColor = timeDiff >= threshold / 2 ? Color.YELLOW : Color.WHITE; - final var color = timeDiff >= threshold ? Color.RED : halfColor; - final var millis = Text.colored(color, Long.toString(timeDiff).concat("ms")); + final var timeMs = Long.toString(timeDiff).concat("ms"); + final var color = timeDiff >= threshold ? Color.RED : Color.YELLOW; + final var millis = timeDiff >= threshold / 2 + ? Text.colored(color, timeMs) + : timeMs; return " (".concat(millis).concat(")"); } diff --git a/src/main/java/io/github/joselion/prettyjupiter/lib/helpers/Color.java b/src/main/java/io/github/joselion/prettyjupiter/lib/helpers/Color.java index 2386dae..4c8d33c 100644 --- a/src/main/java/io/github/joselion/prettyjupiter/lib/helpers/Color.java +++ b/src/main/java/io/github/joselion/prettyjupiter/lib/helpers/Color.java @@ -10,8 +10,7 @@ public enum Color { GRAY(90), GREEN(32), RED(31), - YELLOW(33), - WHITE(97); + YELLOW(33); private final int code; diff --git a/src/test/java/io/github/joselion/prettyjupiter/lib/PrettyLoggerTest.java b/src/test/java/io/github/joselion/prettyjupiter/lib/PrettyLoggerTest.java index bfcd35d..bb320e9 100644 --- a/src/test/java/io/github/joselion/prettyjupiter/lib/PrettyLoggerTest.java +++ b/src/test/java/io/github/joselion/prettyjupiter/lib/PrettyLoggerTest.java @@ -51,7 +51,7 @@ prettyLogger.logDescriptors(descriptor); verify(logger, never()).lifecycle(contains("Gradle Test")); - verify(logger, never()).lifecycle("\u001B[97mGradle Test\u001B[0m"); + verify(logger, never()).lifecycle("Gradle Test"); } } @@ -65,7 +65,7 @@ prettyLogger.logDescriptors(descriptor); verify(logger, never()).lifecycle(contains("Gradle Test")); - verify(logger, never()).lifecycle("\u001B[97mGradle Test\u001B[0m"); + verify(logger, never()).lifecycle("Gradle Test"); } } @@ -79,7 +79,7 @@ prettyLogger.logDescriptors(descriptor); - verify(logger, only()).lifecycle("\u001B[97mThis is a test description!\u001B[0m"); + verify(logger, only()).lifecycle("This is a test description!"); } } } @@ -96,7 +96,7 @@ prettyLogger.logDescriptors(descriptor); verify(logger, never()).lifecycle(contains("Gradle Test")); - verify(logger, never()).lifecycle("\u001B[97mGradle Test\u001B[0m"); + verify(logger, never()).lifecycle("Gradle Test"); } } @@ -110,7 +110,7 @@ prettyLogger.logDescriptors(descriptor); - verify(logger, only()).lifecycle("\u001B[97mThis is a parameterized test description!\u001B[0m"); + verify(logger, only()).lifecycle("This is a parameterized test description!"); } } } @@ -120,9 +120,9 @@ @Nested class when_the_result_has_different_types { @TestFactory Stream logs_the_result_with_the_icon_and_colors_of_the_type() { return Map.of( - ResultType.SUCCESS, Icon.SUCCESS + " \u001B[90mThis is a test result!\u001B[0m (\u001B[97m10ms\u001B[0m)", - ResultType.FAILURE, Icon.FAILURE + " \u001B[31mThis is a test result!\u001B[0m (\u001B[97m10ms\u001B[0m)", - ResultType.SKIPPED, Icon.SKIPPED + " \u001B[33mThis is a test result!\u001B[0m (\u001B[97m10ms\u001B[0m)" + ResultType.SUCCESS, Icon.SUCCESS + " \u001B[90mThis is a test result!\u001B[0m (10ms)", + ResultType.FAILURE, Icon.FAILURE + " \u001B[31mThis is a test result!\u001B[0m (10ms)", + ResultType.SKIPPED, Icon.SKIPPED + " \u001B[33mThis is a test result!\u001B[0m (10ms)" ) .entrySet() .stream() @@ -149,15 +149,31 @@ } } - @Nested class when_the_result_has_different_durations { + @Nested class when_the_result_duration_is_less_the_threshold { + @Test void logs_the_result_without_color() { + final var logger = mock(Logger.class); + final var prettyLogger = prettyLoggerOf(logger); + final var descriptor = MockDescriptor.empty().withDisplayName("This is a test result!"); + final var result = mock(TestResult.class); + when(result.getResultType()).thenReturn(ResultType.SUCCESS); + when(result.getStartTime()).thenReturn(0L); + when(result.getEndTime()).thenReturn(50L); + + prettyLogger.logResults(descriptor, result); + + final var expected = "%s \u001B[90mThis is a test result!\u001B[0m (50ms)".formatted(Icon.SUCCESS); + + verify(logger, only()).lifecycle(expected); + } + } + + @Nested class when_the_result_duration_is_greater_or_equal_to_the_threshold { @TestFactory Stream logs_the_result_with_the_matching_duration_color() { return Stream.of( entry(Color.RED, 250L), entry(Color.RED, 200L), entry(Color.YELLOW, 150L), - entry(Color.YELLOW, 100L), - entry(Color.WHITE, 50L), - entry(Color.WHITE, 0L) + entry(Color.YELLOW, 100L) ) .map(entry -> dynamicTest("[duration: %d]".formatted(entry.getValue()), () -> { @@ -261,7 +277,7 @@ final var reportTrailSpace = " ".repeat(visibleText.length() - plainReport.length()); final var hidden1 = exception.getStackTrace().length - 15; final var hidden2 = causeD.getStackTrace().length - 15; - final var failedTest = Icon.FAILURE + " \u001B[31mTest description 1\u001B[0m (\u001B[97m0ms\u001B[0m)"; + final var failedTest = Icon.FAILURE + " \u001B[31mTest description 1\u001B[0m (0ms)"; final var ordered = inOrder(logger); ordered.verify(logger, times(2)).lifecycle(failedTest);