aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorSaid Belhadj <71043286+Said-Belhadj@users.noreply.github.com>2021-06-27 15:43:57 +0200
committerGitHub <noreply@github.com>2021-06-27 15:43:57 +0200
commit703425d435ac7d0b6a3337f5730199fbaad82ff1 (patch)
tree63c26d58a831eec503940ad616533f35b3b3ccfe /src/test
parent6c977eff192830096d4d5cde27d31bfd21d16b7e (diff)
parente13eea333d7af2786dbbbb5ed60cea4593d5ee12 (diff)
Merge branch 'develop' into feature/STZ-0008
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/musichub/business/PlayListTest.java54
-rw-r--r--src/test/java/musichub/business/SongTest.java83
-rw-r--r--src/test/java/musichub/util/LogHandlerTest.java41
-rw-r--r--src/test/java/musichub/util/PathValidationTest.java (renamed from src/test/java/musichub/business/PathValidationTest.java)24
-rw-r--r--src/test/java/musichub/util/XMLHandlerTest.java30
5 files changed, 220 insertions, 12 deletions
diff --git a/src/test/java/musichub/business/PlayListTest.java b/src/test/java/musichub/business/PlayListTest.java
new file mode 100644
index 0000000..9fe63cf
--- /dev/null
+++ b/src/test/java/musichub/business/PlayListTest.java
@@ -0,0 +1,54 @@
+package musichub.business;
+
+import musichub.util.XMLHandler;
+import org.junit.jupiter.api.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import java.util.ArrayList;
+import java.util.UUID;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class PlayListTest {
+ final String DIR = System.getProperty("user.dir");
+ final String PLAYLISTS_FILE_PATH = DIR + "/files/playlists.xml";
+ final XMLHandler xmlHandler = new XMLHandler();
+ String title = "Side To Side";
+ String id = "66d277ca-cbc4-471c-a07e-082363375bcc";
+ ArrayList<UUID> elementUUIDs = null;
+
+ @Test
+ void testPlaylistClass() {
+ new PlayList(title, id, elementUUIDs);
+ new PlayList(title);
+
+ }
+
+ @Test
+ void testPlaylistClassXML() {
+ NodeList playlistNodes = xmlHandler.parseXMLFile(PLAYLISTS_FILE_PATH);
+ Element playlistElement = (Element) playlistNodes.item(1);
+ new PlayList(playlistElement);
+ }
+
+ @Test
+ void testGetElements() {
+ assertNull(new PlayList(title, id, elementUUIDs).getElements());
+ }
+
+ @Test
+ void testGetTitle() {
+ assertEquals(new PlayList(title).getTitle(), "Side To Side");
+ assertNotEquals(new PlayList(title).getTitle(), "God Is A Woman");
+ }
+
+ @Test
+ void testCreateXMLElement() {
+ PlayList p = new PlayList(title);
+ Document document = xmlHandler.createXMLDocument();
+ Element root = document.createElement("playlists");
+ p.createXMLElement(document, root);
+ }
+}
diff --git a/src/test/java/musichub/business/SongTest.java b/src/test/java/musichub/business/SongTest.java
new file mode 100644
index 0000000..14f9af1
--- /dev/null
+++ b/src/test/java/musichub/business/SongTest.java
@@ -0,0 +1,83 @@
+package musichub.business;
+
+import musichub.util.XMLHandler;
+import org.junit.jupiter.api.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+public class SongTest {
+ String title = "Side To Side";
+ String artist = "Ariana Grande";
+ int length = 186;
+ String uid = "66d277ca-cbc4-471c-a07e-082363375bcc";
+ String content = "Song/Side_To_Side.wav";
+ String genre = "rock";
+
+ final String DIR = System.getProperty("user.dir");
+ final String ELEMENTS_FILE_PATH = DIR + "/files/elements.xml";
+ final XMLHandler xmlHandler = new XMLHandler();
+
+
+ @Test
+ void testSongClass() {
+ new Song(title, artist, length, uid, content, genre);
+ new Song(title, artist, length, content, genre);
+
+ }
+
+ @Test
+ void testSongClassXML() {
+ NodeList audioelementsNodes = xmlHandler.parseXMLFile(ELEMENTS_FILE_PATH);
+ Element audioElement = (Element) audioelementsNodes.item(1);
+ new Song(audioElement);
+ }
+
+ @Test
+ void testGetGenre() {
+ assertEquals(new Song(title, artist, length, content, genre)
+ .getGenre(),
+ "rock");
+ assertNotEquals(new Song(title, artist, length, content, genre)
+ .getGenre(),
+ "pop");
+ }
+
+ @Test
+ void testSetGenre() {
+ new Song(title, artist, length, content, "classic");
+ new Song(title, artist, length, content, "hiphop");
+ new Song(title, artist, length, content, "rock");
+ new Song(title, artist, length, content, "pop");
+ new Song(title, artist, length, content, "rap");
+
+ Song s = new Song(title, artist, length, content, "cgfdhdfhj");
+ assertEquals(s.getGenre(), "jazz");
+ }
+
+ @Test
+ void testToString() {
+ assertEquals(
+ new Song(title, artist, length, content, genre)
+ .toString(),
+ "Title = Side To Side, Artist = Ariana Grande, Length = 186, Content = Song/Side_To_Side.wav, Genre = rock\n"
+ );
+ assertNotEquals(
+ new Song(title, artist, length, content, genre)
+ .toString(),
+ "Title = God is a woman, Artist = Ariana Grande, Length = 186, Content = Song/Side_To_Side.wav, Genre = rock\n"
+ );
+ }
+
+ @Test
+ void testCreateXMLElement() {
+ Song s = new Song(title, artist, length, content, genre);
+ Document document = xmlHandler.createXMLDocument();
+ Element root = document.createElement("elements");
+ s.createXMLElement(document, root);
+
+ }
+}
diff --git a/src/test/java/musichub/util/LogHandlerTest.java b/src/test/java/musichub/util/LogHandlerTest.java
new file mode 100644
index 0000000..ab8e160
--- /dev/null
+++ b/src/test/java/musichub/util/LogHandlerTest.java
@@ -0,0 +1,41 @@
+package musichub.util;
+
+
+import org.junit.jupiter.api.Test;
+
+import java.io.IOException;
+
+import static musichub.util.LogHandler.read;
+import static musichub.util.LogHandler.write;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+public class LogHandlerTest {
+ @Test
+ void testLogHandlerClass() {
+ try {
+ LogHandler logHandlerClass = new LogHandler();
+ } catch (Error e) {
+ assertTrue(e instanceof AssertionError);
+ assertEquals("You just can't instantiate this class.", e.getMessage());
+ }
+ }
+
+ @Test
+ void testWrite() {
+ try {
+ write("JUnit test", "TEST");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ void testRead() {
+ try {
+ read();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/test/java/musichub/business/PathValidationTest.java b/src/test/java/musichub/util/PathValidationTest.java
index fffbdde..b0e0c38 100644
--- a/src/test/java/musichub/business/PathValidationTest.java
+++ b/src/test/java/musichub/util/PathValidationTest.java
@@ -1,26 +1,26 @@
-package musichub.business;
+package musichub.util;
import org.junit.jupiter.api.Test;
-import static musichub.business.PathValidation.isPathValid;
+import static musichub.util.PathValidation.isPathValid;
import static org.junit.jupiter.api.Assertions.*;
public class PathValidationTest {
@Test
- void testIsPathValid() {
- assertTrue(isPathValid("Song/Side_To_Side.wav")); //the right path
- assertFalse(isPathValid("wrong_path/Side_To_Side.wav")); //wrong path
- assertFalse(isPathValid("Song/Side_To_Side.mp3")); //wrong extension
- }
-
- @Test
void testPathValidationClass() {
try {
PathValidation pathValidationClass = new PathValidation();
- } catch (Error ex) {
- assertTrue(ex instanceof AssertionError);
- assertEquals("You just can't instantiate this class.", ex.getMessage());
+ } catch (Error e) {
+ assertTrue(e instanceof AssertionError);
+ assertEquals("You just can't instantiate this class.", e.getMessage());
}
}
+
+ @Test
+ void testIsPathValid() {
+ assertTrue(isPathValid("Song/Side_To_Side.wav")); //the right path
+ assertFalse(isPathValid("wrong_path/Side_To_Side.wav")); //wrong path
+ assertFalse(isPathValid("Song/Side_To_Side.mp3")); //wrong extension
+ }
}
diff --git a/src/test/java/musichub/util/XMLHandlerTest.java b/src/test/java/musichub/util/XMLHandlerTest.java
new file mode 100644
index 0000000..7b5a791
--- /dev/null
+++ b/src/test/java/musichub/util/XMLHandlerTest.java
@@ -0,0 +1,30 @@
+package musichub.util;
+
+
+import org.junit.jupiter.api.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+
+public class XMLHandlerTest {
+
+ final String DIR = System.getProperty("user.dir");
+ final String JUNIT_FILE_PATH = DIR + "/files/JUnit.xml";
+
+ @Test
+ void testCreateXML() {
+ XMLHandler xmlHandler = new XMLHandler(); //XML class
+ Document document = xmlHandler.createXMLDocument(); //XMLDocument method
+ xmlHandler.createXMLFile(document, JUNIT_FILE_PATH); //XMLFile method
+ }
+
+ @Test
+ void testParseXMLFile() {
+ final String PARSE_DIR = System.getProperty("user.dir");
+ final String PARSE_FILE_PATH = PARSE_DIR + "/files/parse_JUnit.xml";
+ XMLHandler xmlHandler = new XMLHandler();
+ //wrong content of file resulting in an exception, will print it during test but it's normal
+ NodeList junitNodes = xmlHandler.parseXMLFile(JUNIT_FILE_PATH);
+ //right content of file
+ NodeList parseNodes = xmlHandler.parseXMLFile(PARSE_FILE_PATH);
+ }
+} \ No newline at end of file