aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/musichub/util
diff options
context:
space:
mode:
authorClyhtsuriva <aimeric@adjutor.xyz>2021-06-27 13:24:40 +0200
committerClyhtsuriva <aimeric@adjutor.xyz>2021-06-27 13:24:40 +0200
commitf5117515ab26658e93d9efc2d99651c332840782 (patch)
tree9695b8cbd65fa1e914b30597b64c79e484cacdcd /src/main/java/musichub/util
parente13eea333d7af2786dbbbb5ed60cea4593d5ee12 (diff)
Added an extension check for songs and covered it with a test.
Diffstat (limited to 'src/main/java/musichub/util')
-rw-r--r--src/main/java/musichub/util/PathValidation.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/main/java/musichub/util/PathValidation.java b/src/main/java/musichub/util/PathValidation.java
index df11388..ea00c24 100644
--- a/src/main/java/musichub/util/PathValidation.java
+++ b/src/main/java/musichub/util/PathValidation.java
@@ -25,15 +25,25 @@ public final class PathValidation {
}
/**
- * Method that checks the validity of a given path
+ * Method that checks the validity of a given path and file.
*
* @param inputPath the path given by the user
* @return a boolean
*/
public static boolean isPathValid(String inputPath) {
+ boolean isExtensionValid = false;
+
+ int index = inputPath.lastIndexOf('.');
+ if (index > 0) {
+ String extension = inputPath.substring(index + 1);
+ if (extension.equals("wav")) {
+ isExtensionValid = true;
+ }
+ }
+
Path path = Paths.get(inputPath);
- return Files.exists(path);
+ return (Files.exists(path) & isExtensionValid);
}
} \ No newline at end of file