From 59bb4fdb6fabe80156e4512fda29013d7f7ce369 Mon Sep 17 00:00:00 2001 From: aj Date: Sat, 25 May 2019 15:02:15 +0100 Subject: [PATCH] added testing --- build.gradle | 6 +- .../fmframework/cache/AlbumCacheTest.java | 6 +- .../fmframework/cache/StaticCacheTest.java | 4 +- .../config/ConfigPersisterTest.java | 4 +- .../fmframework/fm/FmAuthNetworkTest.java | 6 +- .../sarsoo/fmframework/fm/FmNetworkTest.java | 5 +- .../fmframework/fm/FmUserNetworkTest.java | 19 +- .../java/sarsoo/fmframework/log/LogTest.java | 14 +- .../fmframework/util/FMObjListTest.java | 170 +++++++++++++++++- 9 files changed, 194 insertions(+), 40 deletions(-) diff --git a/build.gradle b/build.gradle index bb42b68..ffd886a 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/src/test/java/sarsoo/fmframework/cache/AlbumCacheTest.java b/src/test/java/sarsoo/fmframework/cache/AlbumCacheTest.java index e89adde..217a09a 100644 --- a/src/test/java/sarsoo/fmframework/cache/AlbumCacheTest.java +++ b/src/test/java/sarsoo/fmframework/cache/AlbumCacheTest.java @@ -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(); } } diff --git a/src/test/java/sarsoo/fmframework/cache/StaticCacheTest.java b/src/test/java/sarsoo/fmframework/cache/StaticCacheTest.java index bd5bf4a..74d62f6 100644 --- a/src/test/java/sarsoo/fmframework/cache/StaticCacheTest.java +++ b/src/test/java/sarsoo/fmframework/cache/StaticCacheTest.java @@ -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; diff --git a/src/test/java/sarsoo/fmframework/config/ConfigPersisterTest.java b/src/test/java/sarsoo/fmframework/config/ConfigPersisterTest.java index aed8859..0e69afd 100644 --- a/src/test/java/sarsoo/fmframework/config/ConfigPersisterTest.java +++ b/src/test/java/sarsoo/fmframework/config/ConfigPersisterTest.java @@ -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 { diff --git a/src/test/java/sarsoo/fmframework/fm/FmAuthNetworkTest.java b/src/test/java/sarsoo/fmframework/fm/FmAuthNetworkTest.java index 874a5f5..b9d415b 100644 --- a/src/test/java/sarsoo/fmframework/fm/FmAuthNetworkTest.java +++ b/src/test/java/sarsoo/fmframework/fm/FmAuthNetworkTest.java @@ -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; diff --git a/src/test/java/sarsoo/fmframework/fm/FmNetworkTest.java b/src/test/java/sarsoo/fmframework/fm/FmNetworkTest.java index 25ae39b..14cdab8 100644 --- a/src/test/java/sarsoo/fmframework/fm/FmNetworkTest.java +++ b/src/test/java/sarsoo/fmframework/fm/FmNetworkTest.java @@ -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; diff --git a/src/test/java/sarsoo/fmframework/fm/FmUserNetworkTest.java b/src/test/java/sarsoo/fmframework/fm/FmUserNetworkTest.java index 5aa9693..efad9f7 100644 --- a/src/test/java/sarsoo/fmframework/fm/FmUserNetworkTest.java +++ b/src/test/java/sarsoo/fmframework/fm/FmUserNetworkTest.java @@ -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 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()); } } diff --git a/src/test/java/sarsoo/fmframework/log/LogTest.java b/src/test/java/sarsoo/fmframework/log/LogTest.java index f51f28b..07aee0d 100644 --- a/src/test/java/sarsoo/fmframework/log/LogTest.java +++ b/src/test/java/sarsoo/fmframework/log/LogTest.java @@ -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); } diff --git a/src/test/java/sarsoo/fmframework/util/FMObjListTest.java b/src/test/java/sarsoo/fmframework/util/FMObjListTest.java index 9842288..b8bd497 100644 --- a/src/test/java/sarsoo/fmframework/util/FMObjListTest.java +++ b/src/test/java/sarsoo/fmframework/util/FMObjListTest.java @@ -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); + } + + @Test + @DisplayName("test get name") + public void testGetName() { + String testName = "test name"; -// fail("Not yet implemented"); + 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()); } }