-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b630cb4
commit 85b14b8
Showing
4 changed files
with
61 additions
and
17 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
8 changes: 0 additions & 8 deletions
8
src/main/java/by/andd3dfx/templateapp/error/exception/UnauthorizedException.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/test/java/by/andd3dfx/templateapp/util/MemoryAppender.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,17 @@ | ||
package by.andd3dfx.templateapp.util; | ||
|
||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import ch.qos.logback.core.read.ListAppender; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Class for testing purposes to catch logs. | ||
*/ | ||
public class MemoryAppender extends ListAppender<ILoggingEvent> { | ||
|
||
public List<ILoggingEvent> getLoggedEvents() { | ||
return Collections.unmodifiableList(this.list); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/java/by/andd3dfx/templateapp/util/StartupHelperTest.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,44 @@ | ||
package by.andd3dfx.templateapp.util; | ||
|
||
import ch.qos.logback.classic.Logger; | ||
import ch.qos.logback.classic.LoggerContext; | ||
import ch.qos.logback.classic.spi.ILoggingEvent; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.core.env.StandardEnvironment; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class StartupHelperTest { | ||
|
||
private MemoryAppender memoryAppender; | ||
|
||
@BeforeEach | ||
public void clearLoggingStatements() { | ||
memoryAppender = new MemoryAppender(); | ||
memoryAppender.setContext((LoggerContext) LoggerFactory.getILoggerFactory()); | ||
Logger logger = (Logger) LoggerFactory.getLogger(StartupHelper.class.getCanonicalName()); | ||
logger.addAppender(memoryAppender); | ||
memoryAppender.start(); | ||
} | ||
|
||
@Test | ||
void logApplicationStartup() { | ||
final StandardEnvironment env = new StandardEnvironment(); | ||
|
||
StartupHelper.logApplicationStartup(env); | ||
|
||
List<ILoggingEvent> loggedEvents = memoryAppender.getLoggedEvents(); | ||
assertEquals(loggedEvents.size(), 1); | ||
assertEquals(loggedEvents.get(0).getMessage(), "\n" | ||
+ "----------------------------------------------------------\n" | ||
+ "\tApplication '{}' is running! Access URLs:\n" | ||
+ "\tLocal: \t\t{}://localhost:{}{}\n" | ||
+ "\tExternal: \t{}://{}:{}{}\n" | ||
+ "\tProfile(s): \t{}\n" | ||
+ "----------------------------------------------------------"); | ||
} | ||
} |