aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/musichub/business/SongTest.java
blob: 14f9af14f13bb7945a0fbff6c8d6129568580957 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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);

    }
}