|
|
|
@ -23,17 +23,16 @@
|
|
|
|
|
|
|
|
|
|
package com.iluwatar.module;
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
|
import java.io.FileReader;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
|
|
|
|
@ -65,7 +64,7 @@ public final class FileLoggerModuleTest {
|
|
|
|
|
public void testFileMessage() throws IOException {
|
|
|
|
|
|
|
|
|
|
/* Get singletong instance of File Logger Module */
|
|
|
|
|
final FileLoggerModule fileLoggerModule = FileLoggerModule.getSingleton();
|
|
|
|
|
final var fileLoggerModule = FileLoggerModule.getSingleton();
|
|
|
|
|
|
|
|
|
|
/* Prepare the essential sub modules, to perform the sequence of jobs */
|
|
|
|
|
fileLoggerModule.prepare();
|
|
|
|
@ -88,8 +87,8 @@ public final class FileLoggerModuleTest {
|
|
|
|
|
@Test
|
|
|
|
|
public void testNoFileMessage() throws IOException {
|
|
|
|
|
|
|
|
|
|
/* Get singletong instance of File Logger Module */
|
|
|
|
|
final FileLoggerModule fileLoggerModule = FileLoggerModule.getSingleton();
|
|
|
|
|
/* Get singleton instance of File Logger Module */
|
|
|
|
|
final var fileLoggerModule = FileLoggerModule.getSingleton();
|
|
|
|
|
|
|
|
|
|
/* Prepare the essential sub modules, to perform the sequence of jobs */
|
|
|
|
|
fileLoggerModule.prepare();
|
|
|
|
@ -111,7 +110,7 @@ public final class FileLoggerModuleTest {
|
|
|
|
|
public void testFileErrorMessage() throws FileNotFoundException {
|
|
|
|
|
|
|
|
|
|
/* Get singletong instance of File Logger Module */
|
|
|
|
|
final FileLoggerModule fileLoggerModule = FileLoggerModule.getSingleton();
|
|
|
|
|
final var fileLoggerModule = FileLoggerModule.getSingleton();
|
|
|
|
|
|
|
|
|
|
/* Prepare the essential sub modules, to perform the sequence of jobs */
|
|
|
|
|
fileLoggerModule.prepare();
|
|
|
|
@ -122,7 +121,7 @@ public final class FileLoggerModuleTest {
|
|
|
|
|
/* Test if 'Message' is printed in file */
|
|
|
|
|
assertEquals(ERROR, readFirstLine(ERROR_FILE));
|
|
|
|
|
|
|
|
|
|
/* Unprepare to cleanup the modules */
|
|
|
|
|
/* Un-prepare to cleanup the modules */
|
|
|
|
|
fileLoggerModule.unprepare();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -136,7 +135,7 @@ public final class FileLoggerModuleTest {
|
|
|
|
|
public void testNoFileErrorMessage() throws FileNotFoundException {
|
|
|
|
|
|
|
|
|
|
/* Get singletong instance of File Logger Module */
|
|
|
|
|
final FileLoggerModule fileLoggerModule = FileLoggerModule.getSingleton();
|
|
|
|
|
final var fileLoggerModule = FileLoggerModule.getSingleton();
|
|
|
|
|
|
|
|
|
|
/* Prepare the essential sub modules, to perform the sequence of jobs */
|
|
|
|
|
fileLoggerModule.prepare();
|
|
|
|
@ -154,10 +153,10 @@ public final class FileLoggerModuleTest {
|
|
|
|
|
* @param file as file name to be read
|
|
|
|
|
* @return a string value as first line in file
|
|
|
|
|
*/
|
|
|
|
|
private static final String readFirstLine(final String file) {
|
|
|
|
|
private static String readFirstLine(final String file) {
|
|
|
|
|
|
|
|
|
|
String firstLine = null;
|
|
|
|
|
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
|
|
|
|
|
try (var bufferedReader = new BufferedReader(new FileReader(file))) {
|
|
|
|
|
|
|
|
|
|
while (bufferedReader.ready()) {
|
|
|
|
|
|
|
|
|
|