diff --git a/core-java/pom.xml b/core-java/pom.xml
index cce714451e..cad458596b 100644
--- a/core-java/pom.xml
+++ b/core-java/pom.xml
@@ -10,8 +10,8 @@
com.baeldung
parent-java
- 0.0.1-SNAPSHOT
- ../parent-java
+ 0.0.1-SNAPSHOT
+ ../parent-java
@@ -197,12 +197,7 @@
javax.mail
mail
${javax.mail.version}
-
-
- javax.mail
- mail
- 1.5.0-b01
-
+
com.ibm.icu
icu4j
@@ -255,6 +250,7 @@
org.apache.maven.plugins
maven-jar-plugin
+ ${maven-jar-plugin.version}
@@ -293,6 +289,7 @@
org.apache.maven.plugins
maven-shade-plugin
+ ${maven-shade-plugin.version}
@@ -314,6 +311,7 @@
com.jolira
onejar-maven-plugin
+ ${onejar-maven-plugin.version}
@@ -331,6 +329,7 @@
org.springframework.boot
spring-boot-maven-plugin
+ ${spring-boot-maven-plugin.version}
@@ -478,6 +477,10 @@
3.0.0-M1
1.6.0
1.5.0-b01
+ 3.0.2
+ 1.4.4
+ 3.1.1
+ 2.0.3.RELEASE
61.1
diff --git a/core-java/src/main/java/com/baeldung/customexception/FileManager.java b/core-java/src/main/java/com/baeldung/customexception/FileManager.java
new file mode 100644
index 0000000000..b6f4d960aa
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/customexception/FileManager.java
@@ -0,0 +1,43 @@
+package com.baeldung.customexception;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.util.Scanner;
+
+public class FileManager {
+
+ public static String getFirstLine(String fileName) throws IncorrectFileNameException {
+ try (Scanner file = new Scanner(new File(fileName))) {
+ if (file.hasNextLine()) {
+ return file.nextLine();
+ } else {
+ throw new IllegalArgumentException("Non readable file");
+ }
+ } catch (FileNotFoundException err) {
+ if (!isCorrectFileName(fileName)) {
+ throw new IncorrectFileNameException("Incorrect filename : " + fileName, err);
+ }
+ // Logging etc
+ } catch (IllegalArgumentException err) {
+ if (!containsExtension(fileName)) {
+ throw new IncorrectFileExtensionException("Filename does not contain extension : " + fileName, err);
+ }
+ // Other error cases and logging
+ }
+ return "Default First Line";
+ }
+
+ private static boolean containsExtension(String fileName) {
+ if (fileName.contains(".txt") || fileName.contains(".doc"))
+ return true;
+ return false;
+ }
+
+ private static boolean isCorrectFileName(String fileName) {
+ if (fileName.equals("wrongFileName.txt"))
+ return false;
+ else
+ return true;
+ }
+
+}
diff --git a/core-java/src/main/java/com/baeldung/customexception/IncorrectFileExtensionException.java b/core-java/src/main/java/com/baeldung/customexception/IncorrectFileExtensionException.java
new file mode 100644
index 0000000000..c6dc6d6964
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/customexception/IncorrectFileExtensionException.java
@@ -0,0 +1,9 @@
+package com.baeldung.customexception;
+
+public class IncorrectFileExtensionException extends RuntimeException{
+ private static final long serialVersionUID = 1L;
+
+ public IncorrectFileExtensionException(String errorMessage, Throwable err) {
+ super(errorMessage, err);
+ }
+}
diff --git a/core-java/src/main/java/com/baeldung/customexception/IncorrectFileNameException.java b/core-java/src/main/java/com/baeldung/customexception/IncorrectFileNameException.java
new file mode 100644
index 0000000000..a804cadb84
--- /dev/null
+++ b/core-java/src/main/java/com/baeldung/customexception/IncorrectFileNameException.java
@@ -0,0 +1,9 @@
+package com.baeldung.customexception;
+
+public class IncorrectFileNameException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public IncorrectFileNameException(String errorMessage, Throwable err) {
+ super(errorMessage, err);
+ }
+}
diff --git a/core-java/src/test/java/com/baeldung/customexception/IncorrectFileExtensionExceptionUnitTest.java b/core-java/src/test/java/com/baeldung/customexception/IncorrectFileExtensionExceptionUnitTest.java
new file mode 100644
index 0000000000..230698f719
--- /dev/null
+++ b/core-java/src/test/java/com/baeldung/customexception/IncorrectFileExtensionExceptionUnitTest.java
@@ -0,0 +1,29 @@
+package com.baeldung.customexception;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+
+import org.junit.Test;
+
+public class IncorrectFileExtensionExceptionUnitTest {
+
+ @Test
+ public void testWhenCorrectFileExtensionGiven_ReceivesNoException() throws IncorrectFileNameException {
+ assertThat(FileManager.getFirstLine("correctFileNameWithProperExtension.txt")).isEqualTo("Default First Line");
+ }
+
+ @Test(expected = IncorrectFileExtensionException.class)
+ public void testWhenCorrectFileNameExceptionThrown_ReceivesNoException() throws IncorrectFileNameException {
+ StringBuffer sBuffer = new StringBuffer();
+ sBuffer.append("src");
+ sBuffer.append(File.separator);
+ sBuffer.append("test");
+ sBuffer.append(File.separator);
+ sBuffer.append("resources");
+ sBuffer.append(File.separator);
+ sBuffer.append("correctFileNameWithoutProperExtension");
+ FileManager.getFirstLine(sBuffer.toString());
+ }
+
+}
diff --git a/core-java/src/test/java/com/baeldung/customexception/IncorrectFileNameExceptionUnitTest.java b/core-java/src/test/java/com/baeldung/customexception/IncorrectFileNameExceptionUnitTest.java
new file mode 100644
index 0000000000..acb05eb763
--- /dev/null
+++ b/core-java/src/test/java/com/baeldung/customexception/IncorrectFileNameExceptionUnitTest.java
@@ -0,0 +1,19 @@
+package com.baeldung.customexception;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.junit.Test;
+
+public class IncorrectFileNameExceptionUnitTest {
+
+ @Test(expected = IncorrectFileNameException.class)
+ public void testWhenIncorrectFileNameExceptionThrown_ReceivesIncorrectFileNameException() throws IncorrectFileNameException {
+ FileManager.getFirstLine("wrongFileName.txt");
+ }
+
+ @Test
+ public void testWhenCorrectFileNameExceptionThrown_ReceivesNoException() throws IncorrectFileNameException {
+ assertThat(FileManager.getFirstLine("correctFileName.txt")).isEqualTo("Default First Line");
+ }
+
+}
diff --git a/core-java/src/test/resources/correctFileNameWithoutProperExtension b/core-java/src/test/resources/correctFileNameWithoutProperExtension
new file mode 100644
index 0000000000..e69de29bb2