-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #210 from Kernel360/lee
[#169] 테스트 코드 수정, 미사용 코드 삭제
- Loading branch information
Showing
3 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/com/speech/up/common/aspect/LoggingAspectTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.speech.up.common.aspect; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.MockitoAnnotations; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.core.read.ListAppender; | ||
|
||
public class LoggingAspectTest { | ||
|
||
private ListAppender<ch.qos.logback.classic.spi.ILoggingEvent> listAppender; | ||
|
||
@InjectMocks | ||
private LoggingAspect loggingAspect; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
|
||
LoggerContext loggerContext = (LoggerContext)LoggerFactory.getILoggerFactory(); | ||
listAppender = new ListAppender<>(); | ||
listAppender.setContext(loggerContext); | ||
listAppender.start(); | ||
((ch.qos.logback.classic.Logger)LoggerFactory.getLogger(LoggingAspect.class)).addAppender(listAppender); | ||
} | ||
|
||
@Test | ||
void testLogAfterThrowing() { | ||
// Given | ||
RuntimeException exception = new RuntimeException("Test Exception"); | ||
|
||
// When | ||
loggingAspect.logAfterThrowing(exception); | ||
|
||
// Then | ||
var logs = listAppender.list; | ||
assertTrue(logs.stream() | ||
.anyMatch(event -> event.getFormattedMessage().contains("Exception in method: Test Exception"))); | ||
} | ||
} |