-
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathExceptionHighlighterTest.java
More file actions
69 lines (53 loc) · 2.43 KB
/
ExceptionHighlighterTest.java
File metadata and controls
69 lines (53 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.github.stickerifier.stickerify.logger;
import static com.github.stickerifier.stickerify.logger.ExceptionHighlighter.CONTINUE_RED;
import static com.github.stickerifier.stickerify.logger.HighlightHelper.START_GREEN;
import static com.github.stickerifier.stickerify.logger.LoggingEvent.EXCEPTION_CLASS;
import static java.lang.System.lineSeparator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.emptyString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import com.github.stickerifier.stickerify.junit.Tags;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
@Tag(Tags.LOG)
class ExceptionHighlighterTest {
private static final String LOG_MESSAGE = "Received request";
private static final String EXCEPTION_MESSAGE = "The video could not be processed successfully";
private static final String MIME_TYPE = "text/plain";
private ExceptionHighlighter exceptionHighlighter;
@BeforeEach
void setup() {
exceptionHighlighter = new ExceptionHighlighter();
}
@Test
@DisplayName("Log message without any exception")
void processEventWithoutException() {
var event = new LoggingEvent(LOG_MESSAGE);
var convertedMessage = exceptionHighlighter.convert(event);
assertThat(convertedMessage, is(emptyString()));
}
@Test
@DisplayName("Log exception message without MIME type")
void processExceptionEventWithoutMimeType() {
var event = new LoggingEvent(LOG_MESSAGE, EXCEPTION_MESSAGE);
var expectedMessage = "%s: %s".formatted(EXCEPTION_CLASS, EXCEPTION_MESSAGE);
var convertedMessage = getFirstLine(exceptionHighlighter.convert(event));
assertThat(convertedMessage, is(equalTo(expectedMessage)));
}
private static String getFirstLine(String text) {
return text.split(lineSeparator())[0];
}
@Test
@DisplayName("Log exception message with MIME type")
void processExceptionEventWithMimeType() {
var messageFormat = "The file with %s MIME type is not supported";
var event = new LoggingEvent(LOG_MESSAGE, messageFormat.formatted(MIME_TYPE));
var highlightedMimeType = START_GREEN + MIME_TYPE + CONTINUE_RED;
var expectedMessage = "%s: %s".formatted(EXCEPTION_CLASS, messageFormat.formatted(highlightedMimeType));
var convertedMessage = getFirstLine(exceptionHighlighter.convert(event));
assertThat(convertedMessage, is(equalTo(expectedMessage)));
}
}