From f5117515ab26658e93d9efc2d99651c332840782 Mon Sep 17 00:00:00 2001 From: Clyhtsuriva Date: Sun, 27 Jun 2021 13:24:40 +0200 Subject: Added an extension check for songs and covered it with a test. --- .../site/jacoco/musichub.util/PathValidation.java.html | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'target/site/jacoco/musichub.util/PathValidation.java.html') diff --git a/target/site/jacoco/musichub.util/PathValidation.java.html b/target/site/jacoco/musichub.util/PathValidation.java.html index 7cb31d4..7518e59 100644 --- a/target/site/jacoco/musichub.util/PathValidation.java.html +++ b/target/site/jacoco/musichub.util/PathValidation.java.html @@ -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) { - Path path = Paths.get(inputPath); - return Files.exists(path); + 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) & isExtensionValid); } } -- cgit v1.2.3