added testing

This commit is contained in:
aj 2019-05-25 15:02:15 +01:00
parent d720645735
commit 59bb4fdb6f
9 changed files with 194 additions and 40 deletions

View File

@ -40,9 +40,13 @@ dependencies {
implementation 'com.mashape.unirest:unirest-java:1.4.9'
implementation 'org.json:json:20180813'
testImplementation 'junit:junit:4.12'
testImplementation('org.junit.jupiter:junit-jupiter-api:5.4.2')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.4.2')
}
test {
useJUnitPlatform()
}
jar {
manifest {

View File

@ -1,8 +1,6 @@
package sarsoo.fmframework.cache;
import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import sarsoo.fmframework.cache.puller.AlbumPuller;
import sarsoo.fmframework.cache.puller.ArtistPuller;
@ -35,7 +33,7 @@ public class AlbumCacheTest {
artistCache.dumpToLog(new Log());
cache.dumpToLog(new Log());
assertTrue(true);
// assertThat();
}
}

View File

@ -1,8 +1,8 @@
package sarsoo.fmframework.cache;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import sarsoo.fmframework.cache.puller.AlbumPuller;
import sarsoo.fmframework.fm.FmUserNetwork;

View File

@ -1,8 +1,8 @@
package sarsoo.fmframework.config;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
public class ConfigPersisterTest {

View File

@ -1,11 +1,11 @@
package sarsoo.fmframework.fm;
import static org.junit.Assert.*;
import java.util.HashMap;
import java.util.Scanner;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import sarsoo.fmframework.music.Scrobble;
import sarsoo.fmframework.music.Track.TrackBuilder;

View File

@ -1,7 +1,8 @@
package sarsoo.fmframework.fm;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import sarsoo.fmframework.error.ApiCallException;
import sarsoo.fmframework.music.Album;

View File

@ -1,7 +1,5 @@
package sarsoo.fmframework.fm;
import org.junit.Test;
import sarsoo.fmframework.music.Scrobble;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.music.Track.TrackBuilder;
@ -10,7 +8,9 @@ import sarsoo.fmframework.music.Artist.ArtistBuilder;
import sarsoo.fmframework.net.Key;
import sarsoo.fmframework.util.FMObjList;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
@ -26,7 +26,7 @@ public class FmUserNetworkTest {
try {
assertNotNull(new FmUserNetwork(Key.getKey(), "sarsoo").getLastTrack());
} catch (ApiCallException e) {
e.printStackTrace();
fail("APICallException" + e.getMessage());
}
}
@ -34,18 +34,16 @@ public class FmUserNetworkTest {
public void testGetRecentTracks() {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
int limit = 50;
int limit = 30;
ArrayList<Scrobble> scrobbles;
try {
scrobbles = net.getRecentScrobbles(limit);
// scrobbles.stream().forEach(System.out::println);
System.out.println(scrobbles.size());
assertEquals(limit, scrobbles.size());
} catch (ApiCallException e) {
e.printStackTrace();
fail("APICallException" + e.getMessage());
}
}
@ -53,17 +51,16 @@ public class FmUserNetworkTest {
public void testGetTopAlbums() {
FmUserNetwork net = new FmUserNetwork(Key.getKey(), "sarsoo");
int limit = 50;
int limit = 30;
FMObjList list;
try {
list = net.getTopAlbums("7day", limit);
// list.stream().forEach(System.out::println);
assertEquals(limit, list.size());
} catch (ApiCallException e) {
e.printStackTrace();
fail("APICallException" + e.getMessage());
}
}

View File

@ -1,8 +1,8 @@
package sarsoo.fmframework.log;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import sarsoo.fmframework.log.entry.ErrorEntry;
import sarsoo.fmframework.log.entry.InfoEntry;
@ -13,15 +13,7 @@ public class LogTest {
@Test
public void testDump() {
Log log = Logger.getLog();
log.log(new LogEntry("log test"));
log.logInfo(new InfoEntry("log test"));
log.logError(new ErrorEntry("log test"));
// log.dumpLog();
// log.dumpInfoLog();
// log.dumpErrorLog();
Log log = new Log();
assertTrue(true);
}

View File

@ -1,16 +1,178 @@
package sarsoo.fmframework.util;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import sarsoo.fmframework.music.Album;
import sarsoo.fmframework.music.Album.AlbumBuilder;
import sarsoo.fmframework.music.Artist;
import sarsoo.fmframework.music.Artist.ArtistBuilder;
import sarsoo.fmframework.music.Track;
import sarsoo.fmframework.music.Track.TrackBuilder;
@DisplayName("FMObjList tests")
public class FMObjListTest {
@Test
public void testSeparateAlbumAddition() {
@DisplayName("empty instantiation not null")
public void testNotNull() {
FMObjList list = new FMObjList();
// Album album = new Album();
assertNotNull(list);
}
// fail("Not yet implemented");
@Test
@DisplayName("test get name")
public void testGetName() {
String testName = "test name";
FMObjList list = new FMObjList(testName);
assertEquals(testName, list.getGroupName());
}
@Test
@DisplayName("test artist total count")
public void testArtistsGetScrobbleCount() {
FMObjList list = new FMObjList();
int scrobbleCount = 20;
int scrobbleCount2 = 30;
Artist artist = new ArtistBuilder("artist name").setUserPlayCount(scrobbleCount).build();
Artist artist2 = new ArtistBuilder("artist name2").setUserPlayCount(scrobbleCount2).build();
list.add(artist);
list.add(artist2);
assertEquals(scrobbleCount + scrobbleCount2, list.getTotalUserScrobbles());
}
@Test
@DisplayName("test album count ignored with present artist")
public void testArtistsAlbumsGetScrobbleCount() {
FMObjList list = new FMObjList();
int artistScrobbleCount = 20;
int artistScrobbleCount2 = 30;
Artist artist = new ArtistBuilder("artist name").setUserPlayCount(artistScrobbleCount).build();
Artist artist2 = new ArtistBuilder("artist name2").setUserPlayCount(artistScrobbleCount2).build();
Album album = new AlbumBuilder("album name", artist).setUserPlayCount(10).build();
list.add(artist);
list.add(artist2);
list.add(album);
assertEquals(artistScrobbleCount + artistScrobbleCount2, list.getTotalUserScrobbles());
}
@Test
@DisplayName("test multiple album count ignored with present artist")
public void testArtistsMultipleAlbumsGetScrobbleCount() {
FMObjList list = new FMObjList();
int artistScrobbleCount = 20;
int artistScrobbleCount2 = 30;
Artist artist = new ArtistBuilder("artist name").setUserPlayCount(artistScrobbleCount).build();
Artist artist2 = new ArtistBuilder("artist name2").setUserPlayCount(artistScrobbleCount2).build();
Album album = new AlbumBuilder("album name", artist).setUserPlayCount(10).build();
Album album2 = new AlbumBuilder("album name2", artist2).setUserPlayCount(5).build();
list.add(artist);
list.add(artist2);
list.add(album);
list.add(album2);
assertEquals(artistScrobbleCount + artistScrobbleCount2, list.getTotalUserScrobbles());
}
@Test
@DisplayName("test track count ignored with present artist")
public void testArtistsTrackGetScrobbleCount() {
FMObjList list = new FMObjList();
int artistScrobbleCount = 20;
int artistScrobbleCount2 = 30;
Artist artist = new ArtistBuilder("artist name").setUserPlayCount(artistScrobbleCount).build();
Artist artist2 = new ArtistBuilder("artist name2").setUserPlayCount(artistScrobbleCount2).build();
Track track = new TrackBuilder("track name", artist2).setUserPlayCount(5).build();
list.add(artist);
list.add(artist2);
list.add(track);
assertEquals(artistScrobbleCount + artistScrobbleCount2, list.getTotalUserScrobbles());
}
@Test
@DisplayName("test track/album count ignored with present artist")
public void testArtistAlbumTrackGetScrobbleCount() {
FMObjList list = new FMObjList();
int artistScrobbleCount = 20;
int artistScrobbleCount2 = 30;
Artist artist = new ArtistBuilder("artist name").setUserPlayCount(artistScrobbleCount).build();
Artist artist2 = new ArtistBuilder("artist name2").setUserPlayCount(artistScrobbleCount2).build();
Album album = new AlbumBuilder("album name", artist).setUserPlayCount(10).build();
Track track = new TrackBuilder("track name", artist).setAlbum(album).setUserPlayCount(5).build();
list.add(artist);
list.add(artist2);
list.add(album);
list.add(track);
assertEquals(artistScrobbleCount + artistScrobbleCount2, list.getTotalUserScrobbles());
}
@Test
@DisplayName("test track count ignored with present album")
public void testAlbumTrackGetScrobbleCount() {
FMObjList list = new FMObjList();
int artistScrobbleCount = 20;
Artist artist = new ArtistBuilder("artist name").setUserPlayCount(artistScrobbleCount).build();
Album album = new AlbumBuilder("album name", artist).setUserPlayCount(10).build();
Track track = new TrackBuilder("track name", artist).setAlbum(album).setUserPlayCount(5).build();
list.add(album);
list.add(track);
assertEquals(10, list.getTotalUserScrobbles());
}
@Test
@DisplayName("test multiple tracks count ignored with present album")
public void testAlbumTracksGetScrobbleCount() {
FMObjList list = new FMObjList();
int artistScrobbleCount = 20;
Artist artist = new ArtistBuilder("artist name").setUserPlayCount(artistScrobbleCount).build();
Album album = new AlbumBuilder("album name", artist).setUserPlayCount(20).build();
Track track = new TrackBuilder("track name", artist).setAlbum(album).setUserPlayCount(5).build();
Track track2 = new TrackBuilder("track name2", artist).setAlbum(album).setUserPlayCount(10).build();
list.add(album);
list.add(track);
list.add(track2);
assertEquals(20, list.getTotalUserScrobbles());
}
}