Skip to content

Commit f1b27ef

Browse files
Java 11 migraiton: module
1 parent 99c70af commit f1b27ef

File tree

4 files changed

+59
-63
lines changed

4 files changed

+59
-63
lines changed

module/pom.xml

+35-34
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,39 @@
2323
THE SOFTWARE.
2424
2525
-->
26-
<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">
27-
<modelVersion>4.0.0</modelVersion>
28-
<parent>
29-
<groupId>com.iluwatar</groupId>
30-
<artifactId>java-design-patterns</artifactId>
31-
<version>1.23.0-SNAPSHOT</version>
32-
</parent>
33-
<artifactId>module</artifactId>
34-
<dependencies>
35-
<dependency>
36-
<groupId>org.junit.jupiter</groupId>
37-
<artifactId>junit-jupiter-engine</artifactId>
38-
<scope>test</scope>
39-
</dependency>
40-
</dependencies>
41-
<build>
42-
<plugins>
43-
<plugin>
44-
<groupId>org.apache.maven.plugins</groupId>
45-
<artifactId>maven-assembly-plugin</artifactId>
46-
<executions>
47-
<execution>
48-
<configuration>
49-
<archive>
50-
<manifest>
51-
<mainClass>com.iluwatar.module.App</mainClass>
52-
</manifest>
53-
</archive>
54-
</configuration>
55-
</execution>
56-
</executions>
57-
</plugin>
58-
</plugins>
59-
</build>
26+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
27+
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
28+
<modelVersion>4.0.0</modelVersion>
29+
<parent>
30+
<groupId>com.iluwatar</groupId>
31+
<artifactId>java-design-patterns</artifactId>
32+
<version>1.23.0-SNAPSHOT</version>
33+
</parent>
34+
<artifactId>module</artifactId>
35+
<dependencies>
36+
<dependency>
37+
<groupId>org.junit.jupiter</groupId>
38+
<artifactId>junit-jupiter-engine</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
</dependencies>
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-assembly-plugin</artifactId>
47+
<executions>
48+
<execution>
49+
<configuration>
50+
<archive>
51+
<manifest>
52+
<mainClass>com.iluwatar.module.App</mainClass>
53+
</manifest>
54+
</archive>
55+
</configuration>
56+
</execution>
57+
</executions>
58+
</plugin>
59+
</plugins>
60+
</build>
6061
</project>

module/src/main/java/com/iluwatar/module/App.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,8 @@ public static void unprepare() {
6565

6666
/**
6767
* Following method is main executor.
68-
*
69-
* @param args for providing default program arguments
7068
*/
71-
public static void execute(final String... args) {
69+
public static void execute() {
7270

7371
/* Send logs on file system */
7472
fileLoggerModule.printString("Message");
@@ -88,7 +86,7 @@ public static void execute(final String... args) {
8886
*/
8987
public static void main(final String... args) throws FileNotFoundException {
9088
prepare();
91-
execute(args);
89+
execute();
9290
unprepare();
9391
}
9492
}

module/src/test/java/com/iluwatar/module/AppTest.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323

2424
package com.iluwatar.module;
2525

26-
import org.junit.jupiter.api.Test;
27-
2826
import java.io.FileNotFoundException;
27+
import org.junit.jupiter.api.Test;
2928

3029
/**
3130
* Tests that Module example runs without errors.
@@ -34,7 +33,6 @@ public final class AppTest {
3433

3534
@Test
3635
public void test() throws FileNotFoundException {
37-
final String[] args = {};
38-
App.main(args);
36+
App.main();
3937
}
4038
}

module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java

+20-21
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,16 @@
2323

2424
package com.iluwatar.module;
2525

26-
import org.junit.jupiter.api.Test;
27-
import org.slf4j.Logger;
28-
import org.slf4j.LoggerFactory;
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertNull;
2928

3029
import java.io.BufferedReader;
3130
import java.io.FileNotFoundException;
3231
import java.io.FileReader;
3332
import java.io.IOException;
34-
35-
import static org.junit.jupiter.api.Assertions.assertEquals;
36-
import static org.junit.jupiter.api.Assertions.assertNull;
33+
import org.junit.jupiter.api.Test;
34+
import org.slf4j.Logger;
35+
import org.slf4j.LoggerFactory;
3736

3837
/**
3938
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
@@ -58,14 +57,14 @@ public final class FileLoggerModuleTest {
5857

5958
/**
6059
* This test verify that 'MESSAGE' is perfectly printed in output file
61-
*
60+
*
6261
* @throws IOException if program is not able to find log files (output.txt and error.txt)
6362
*/
6463
@Test
6564
public void testFileMessage() throws IOException {
6665

6766
/* Get singletong instance of File Logger Module */
68-
final FileLoggerModule fileLoggerModule = FileLoggerModule.getSingleton();
67+
final var fileLoggerModule = FileLoggerModule.getSingleton();
6968

7069
/* Prepare the essential sub modules, to perform the sequence of jobs */
7170
fileLoggerModule.prepare();
@@ -82,14 +81,14 @@ public void testFileMessage() throws IOException {
8281

8382
/**
8483
* This test verify that nothing is printed in output file
85-
*
84+
*
8685
* @throws IOException if program is not able to find log files (output.txt and error.txt)
8786
*/
8887
@Test
8988
public void testNoFileMessage() throws IOException {
9089

91-
/* Get singletong instance of File Logger Module */
92-
final FileLoggerModule fileLoggerModule = FileLoggerModule.getSingleton();
90+
/* Get singleton instance of File Logger Module */
91+
final var fileLoggerModule = FileLoggerModule.getSingleton();
9392

9493
/* Prepare the essential sub modules, to perform the sequence of jobs */
9594
fileLoggerModule.prepare();
@@ -103,15 +102,15 @@ public void testNoFileMessage() throws IOException {
103102

104103
/**
105104
* This test verify that 'ERROR' is perfectly printed in error file
106-
*
105+
*
107106
* @throws FileNotFoundException if program is not able to find log files (output.txt and
108-
* error.txt)
107+
* error.txt)
109108
*/
110109
@Test
111110
public void testFileErrorMessage() throws FileNotFoundException {
112111

113112
/* Get singletong instance of File Logger Module */
114-
final FileLoggerModule fileLoggerModule = FileLoggerModule.getSingleton();
113+
final var fileLoggerModule = FileLoggerModule.getSingleton();
115114

116115
/* Prepare the essential sub modules, to perform the sequence of jobs */
117116
fileLoggerModule.prepare();
@@ -122,21 +121,21 @@ public void testFileErrorMessage() throws FileNotFoundException {
122121
/* Test if 'Message' is printed in file */
123122
assertEquals(ERROR, readFirstLine(ERROR_FILE));
124123

125-
/* Unprepare to cleanup the modules */
124+
/* Un-prepare to cleanup the modules */
126125
fileLoggerModule.unprepare();
127126
}
128127

129128
/**
130129
* This test verify that nothing is printed in error file
131-
*
130+
*
132131
* @throws FileNotFoundException if program is not able to find log files (output.txt and
133-
* error.txt)
132+
* error.txt)
134133
*/
135134
@Test
136135
public void testNoFileErrorMessage() throws FileNotFoundException {
137136

138137
/* Get singletong instance of File Logger Module */
139-
final FileLoggerModule fileLoggerModule = FileLoggerModule.getSingleton();
138+
final var fileLoggerModule = FileLoggerModule.getSingleton();
140139

141140
/* Prepare the essential sub modules, to perform the sequence of jobs */
142141
fileLoggerModule.prepare();
@@ -150,14 +149,14 @@ public void testNoFileErrorMessage() throws FileNotFoundException {
150149

151150
/**
152151
* Utility method to read first line of a file
153-
*
152+
*
154153
* @param file as file name to be read
155154
* @return a string value as first line in file
156155
*/
157-
private static final String readFirstLine(final String file) {
156+
private static String readFirstLine(final String file) {
158157

159158
String firstLine = null;
160-
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
159+
try (var bufferedReader = new BufferedReader(new FileReader(file))) {
161160

162161
while (bufferedReader.ready()) {
163162

0 commit comments

Comments
 (0)