From f1b27ef5c78eb379ca5f2ef539cca8c533ddc0a8 Mon Sep 17 00:00:00 2001 From: Anurag Agarwal Date: Sun, 12 Apr 2020 22:38:00 +0000 Subject: [PATCH] Java 11 migraiton: module --- module/pom.xml | 69 ++++++++++--------- .../main/java/com/iluwatar/module/App.java | 6 +- .../java/com/iluwatar/module/AppTest.java | 6 +- .../iluwatar/module/FileLoggerModuleTest.java | 41 ++++++----- 4 files changed, 59 insertions(+), 63 deletions(-) diff --git a/module/pom.xml b/module/pom.xml index 25ad707eb..5d9a6d529 100644 --- a/module/pom.xml +++ b/module/pom.xml @@ -23,38 +23,39 @@ THE SOFTWARE. --> - - 4.0.0 - - com.iluwatar - java-design-patterns - 1.23.0-SNAPSHOT - - module - - - org.junit.jupiter - junit-jupiter-engine - test - - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - - - - com.iluwatar.module.App - - - - - - - - + + 4.0.0 + + com.iluwatar + java-design-patterns + 1.23.0-SNAPSHOT + + module + + + org.junit.jupiter + junit-jupiter-engine + test + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + + + + com.iluwatar.module.App + + + + + + + + diff --git a/module/src/main/java/com/iluwatar/module/App.java b/module/src/main/java/com/iluwatar/module/App.java index 1b6cbbd23..77034d76b 100644 --- a/module/src/main/java/com/iluwatar/module/App.java +++ b/module/src/main/java/com/iluwatar/module/App.java @@ -65,10 +65,8 @@ public class App { /** * 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 */ fileLoggerModule.printString("Message"); @@ -88,7 +86,7 @@ public class App { */ public static void main(final String... args) throws FileNotFoundException { prepare(); - execute(args); + execute(); unprepare(); } } diff --git a/module/src/test/java/com/iluwatar/module/AppTest.java b/module/src/test/java/com/iluwatar/module/AppTest.java index 88fa4c68c..8dcfd565e 100644 --- a/module/src/test/java/com/iluwatar/module/AppTest.java +++ b/module/src/test/java/com/iluwatar/module/AppTest.java @@ -23,9 +23,8 @@ package com.iluwatar.module; -import org.junit.jupiter.api.Test; - import java.io.FileNotFoundException; +import org.junit.jupiter.api.Test; /** * Tests that Module example runs without errors. @@ -34,7 +33,6 @@ public final class AppTest { @Test public void test() throws FileNotFoundException { - final String[] args = {}; - App.main(args); + App.main(); } } diff --git a/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java b/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java index e88b466f2..6497aa89d 100644 --- a/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java +++ b/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java @@ -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 @@ -58,14 +57,14 @@ public final class FileLoggerModuleTest { /** * 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) */ @Test 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(); @@ -82,14 +81,14 @@ public final class FileLoggerModuleTest { /** * 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) */ @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(); @@ -103,15 +102,15 @@ public final class FileLoggerModuleTest { /** * 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 - * error.txt) + * error.txt) */ @Test 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,21 +121,21 @@ 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(); } /** * This test verify that nothing is printed in error file - * + * * @throws FileNotFoundException if program is not able to find log files (output.txt and - * error.txt) + * error.txt) */ @Test 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(); @@ -150,14 +149,14 @@ public final class FileLoggerModuleTest { /** * Utility method to read first line of a file - * + * * @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()) {