Java 11 migraiton: module
This commit is contained in:
parent
99c70af16a
commit
f1b27ef5c7
@ -23,38 +23,39 @@
|
|||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
|
|
||||||
-->
|
-->
|
||||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||||
<modelVersion>4.0.0</modelVersion>
|
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<parent>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.iluwatar</groupId>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.23.0-SNAPSHOT</version>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
</parent>
|
<version>1.23.0-SNAPSHOT</version>
|
||||||
<artifactId>module</artifactId>
|
</parent>
|
||||||
<dependencies>
|
<artifactId>module</artifactId>
|
||||||
<dependency>
|
<dependencies>
|
||||||
<groupId>org.junit.jupiter</groupId>
|
<dependency>
|
||||||
<artifactId>junit-jupiter-engine</artifactId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<scope>test</scope>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
</dependency>
|
<scope>test</scope>
|
||||||
</dependencies>
|
</dependency>
|
||||||
<build>
|
</dependencies>
|
||||||
<plugins>
|
<build>
|
||||||
<plugin>
|
<plugins>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<plugin>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<executions>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<execution>
|
<executions>
|
||||||
<configuration>
|
<execution>
|
||||||
<archive>
|
<configuration>
|
||||||
<manifest>
|
<archive>
|
||||||
<mainClass>com.iluwatar.module.App</mainClass>
|
<manifest>
|
||||||
</manifest>
|
<mainClass>com.iluwatar.module.App</mainClass>
|
||||||
</archive>
|
</manifest>
|
||||||
</configuration>
|
</archive>
|
||||||
</execution>
|
</configuration>
|
||||||
</executions>
|
</execution>
|
||||||
</plugin>
|
</executions>
|
||||||
</plugins>
|
</plugin>
|
||||||
</build>
|
</plugins>
|
||||||
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -65,10 +65,8 @@ public class App {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Following method is main executor.
|
* Following method is main executor.
|
||||||
*
|
|
||||||
* @param args for providing default program arguments
|
|
||||||
*/
|
*/
|
||||||
public static void execute(final String... args) {
|
public static void execute() {
|
||||||
|
|
||||||
/* Send logs on file system */
|
/* Send logs on file system */
|
||||||
fileLoggerModule.printString("Message");
|
fileLoggerModule.printString("Message");
|
||||||
@ -88,7 +86,7 @@ public class App {
|
|||||||
*/
|
*/
|
||||||
public static void main(final String... args) throws FileNotFoundException {
|
public static void main(final String... args) throws FileNotFoundException {
|
||||||
prepare();
|
prepare();
|
||||||
execute(args);
|
execute();
|
||||||
unprepare();
|
unprepare();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,9 +23,8 @@
|
|||||||
|
|
||||||
package com.iluwatar.module;
|
package com.iluwatar.module;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that Module example runs without errors.
|
* Tests that Module example runs without errors.
|
||||||
@ -34,7 +33,6 @@ public final class AppTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws FileNotFoundException {
|
public void test() throws FileNotFoundException {
|
||||||
final String[] args = {};
|
App.main();
|
||||||
App.main(args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,17 +23,16 @@
|
|||||||
|
|
||||||
package com.iluwatar.module;
|
package com.iluwatar.module;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.slf4j.Logger;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import org.slf4j.Logger;
|
||||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
|
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
|
||||||
@ -58,14 +57,14 @@ public final class FileLoggerModuleTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This test verify that 'MESSAGE' is perfectly printed in output file
|
* This test verify that 'MESSAGE' is perfectly printed in output file
|
||||||
*
|
*
|
||||||
* @throws IOException if program is not able to find log files (output.txt and error.txt)
|
* @throws IOException if program is not able to find log files (output.txt and error.txt)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFileMessage() throws IOException {
|
public void testFileMessage() throws IOException {
|
||||||
|
|
||||||
/* Get singletong instance of File Logger Module */
|
/* 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 */
|
/* Prepare the essential sub modules, to perform the sequence of jobs */
|
||||||
fileLoggerModule.prepare();
|
fileLoggerModule.prepare();
|
||||||
@ -82,14 +81,14 @@ public final class FileLoggerModuleTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This test verify that nothing is printed in output file
|
* This test verify that nothing is printed in output file
|
||||||
*
|
*
|
||||||
* @throws IOException if program is not able to find log files (output.txt and error.txt)
|
* @throws IOException if program is not able to find log files (output.txt and error.txt)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNoFileMessage() throws IOException {
|
public void testNoFileMessage() throws IOException {
|
||||||
|
|
||||||
/* Get singletong instance of File Logger Module */
|
/* Get singleton 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 */
|
/* Prepare the essential sub modules, to perform the sequence of jobs */
|
||||||
fileLoggerModule.prepare();
|
fileLoggerModule.prepare();
|
||||||
@ -103,15 +102,15 @@ public final class FileLoggerModuleTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This test verify that 'ERROR' is perfectly printed in error file
|
* This test verify that 'ERROR' is perfectly printed in error file
|
||||||
*
|
*
|
||||||
* @throws FileNotFoundException if program is not able to find log files (output.txt and
|
* @throws FileNotFoundException if program is not able to find log files (output.txt and
|
||||||
* error.txt)
|
* error.txt)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFileErrorMessage() throws FileNotFoundException {
|
public void testFileErrorMessage() throws FileNotFoundException {
|
||||||
|
|
||||||
/* Get singletong instance of File Logger Module */
|
/* 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 */
|
/* Prepare the essential sub modules, to perform the sequence of jobs */
|
||||||
fileLoggerModule.prepare();
|
fileLoggerModule.prepare();
|
||||||
@ -122,21 +121,21 @@ public final class FileLoggerModuleTest {
|
|||||||
/* Test if 'Message' is printed in file */
|
/* Test if 'Message' is printed in file */
|
||||||
assertEquals(ERROR, readFirstLine(ERROR_FILE));
|
assertEquals(ERROR, readFirstLine(ERROR_FILE));
|
||||||
|
|
||||||
/* Unprepare to cleanup the modules */
|
/* Un-prepare to cleanup the modules */
|
||||||
fileLoggerModule.unprepare();
|
fileLoggerModule.unprepare();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test verify that nothing is printed in error file
|
* This test verify that nothing is printed in error file
|
||||||
*
|
*
|
||||||
* @throws FileNotFoundException if program is not able to find log files (output.txt and
|
* @throws FileNotFoundException if program is not able to find log files (output.txt and
|
||||||
* error.txt)
|
* error.txt)
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testNoFileErrorMessage() throws FileNotFoundException {
|
public void testNoFileErrorMessage() throws FileNotFoundException {
|
||||||
|
|
||||||
/* Get singletong instance of File Logger Module */
|
/* 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 */
|
/* Prepare the essential sub modules, to perform the sequence of jobs */
|
||||||
fileLoggerModule.prepare();
|
fileLoggerModule.prepare();
|
||||||
@ -150,14 +149,14 @@ public final class FileLoggerModuleTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method to read first line of a file
|
* Utility method to read first line of a file
|
||||||
*
|
*
|
||||||
* @param file as file name to be read
|
* @param file as file name to be read
|
||||||
* @return a string value as first line in file
|
* @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;
|
String firstLine = null;
|
||||||
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
|
try (var bufferedReader = new BufferedReader(new FileReader(file))) {
|
||||||
|
|
||||||
while (bufferedReader.ready()) {
|
while (bufferedReader.ready()) {
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user