-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4JavaSongTest.java.txt
More file actions
49 lines (41 loc) · 1.33 KB
/
Copy path4JavaSongTest.java.txt
File metadata and controls
49 lines (41 loc) · 1.33 KB
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
// Code that Java2 TA used for test the Song.java code
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class SongTest {
@Test
void testGetters() {
String title = "The Sound of Muzak";
String artist = "Porcupine Tree";
int[] time = {59, 4};
Song song = new Song(title, artist, time);
assertEquals(title, song.getTitle());
assertEquals(artist, song.getArtist());
assertArrayEquals(time, song.getDuration());
title = "Her Majesty";
artist = "The Beatles";
time = new int[] {23};
song = new Song(title, artist, time);
assertEquals(title, song.getTitle());
assertEquals(artist, song.getArtist());
assertArrayEquals(time, song.getDuration());
}
@Test
void testImmutability() {
String title = "Ten Years Gone";
String artist = "Led Zeppelin";
int seconds = 55;
int minutes = 6;
int[] time = {seconds, minutes};
Song song = new Song(title, artist, time);
time[0] = -12345;
time[1] = -54321;
assertEquals(seconds, song.getDuration()[0]);
assertEquals(minutes, song.getDuration()[1]);
int[] returnedTime = song.getDuration();
returnedTime[0] = -12345;
returnedTime[1] = -54321;
assertEquals(seconds, song.getDuration()[0]);
assertEquals(minutes, song.getDuration()[1]);
}
}