Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ressurect instrumented tests #8

Merged
merged 3 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,5 @@ dependencies {
implementation 'androidx.vectordrawable:vectordrawable:1.0.0'
androidTestImplementation "androidx.test:runner:1.5.2"
androidTestImplementation "androidx.test:rules:1.5.0"
androidTestImplementation group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version: '1.7.10'
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class SubsonicFragmentActivityTest {
public ActivityTestRule<SubsonicFragmentActivity> activityRule = new ActivityTestRule<>(SubsonicFragmentActivity.class, true, true);

@Before
protected void setUp() throws Exception {
public void setUp() throws Exception {
activity = activityRule.getActivity();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
import github.daneren2005.dsub.domain.PlayerState;

import java.util.LinkedList;

import android.app.Instrumentation;
import android.content.Context;
import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.rule.ActivityTestRule;

import org.junit.Before;
Expand All @@ -33,7 +37,7 @@ public class DownloadServiceTest {
private DownloadService downloadService;

@Before
protected void setUp() throws Exception {
public void setUp() throws Exception {
activity = activityRule.getActivity();
downloadService = activity.getDownloadService();
downloadService.clear();
Expand Down Expand Up @@ -239,7 +243,7 @@ public void testTogglePlayPauseWithPlayList() throws InterruptedException {
* @throws InterruptedException
*/
@Test
public void testAutoplay() throws InterruptedException {
public void testAutoplay() throws InterruptedException, Exception {
// Download one songs
downloadService.getDownloads().clear();
downloadService.download(this.createMusicSongs(1), false, true, false,
Expand Down Expand Up @@ -290,42 +294,42 @@ public void testAddMusicToDownload() {
}

/**
* Generate a list containing some music directory entries.
* Generate a list containing some music directory entries. Produced from current subsonic
* server. Is uses *alphabeticalByName* album list. Given server stays with the
* same music content, this method should produce the same results for every call with
* unique *size* argument. It is important for this method to return really existing on server
* songs, as other tests rely on it.
*
* @return list containing some music directory entries.
*/
private List<MusicDirectory.Entry> createMusicSongs(int size) {
MusicDirectory.Entry musicEntry = new MusicDirectory.Entry();
musicEntry.setAlbum("Itchy Hitchhiker");
musicEntry.setBitRate(198);
musicEntry.setAlbumId("49");
musicEntry.setDuration(247);
musicEntry.setSize(Long.valueOf(6162717));
musicEntry.setArtistId("23");
musicEntry.setArtist("The Dada Weatherman");
musicEntry.setCloseness(0);
musicEntry.setContentType("audio/mpeg");
musicEntry.setCoverArt("433");
musicEntry.setDirectory(false);
musicEntry.setGenre("Easy Listening/New Age");
musicEntry.setGrandParent("306");
musicEntry.setId("466");
musicEntry.setParent("433");
musicEntry
.setPath("The Dada Weatherman/Itchy Hitchhiker/08 - The Dada Weatherman - Harmonies.mp3");
musicEntry.setStarred(true);
musicEntry.setSuffix("mp3");
musicEntry.setTitle("Harmonies");
musicEntry.setType(0);
musicEntry.setVideo(false);

List<MusicDirectory.Entry> musicEntries = new LinkedList<MusicDirectory.Entry>();

for (int i = 0; i < size; i++) {
musicEntries.add(musicEntry);
try {
Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
MusicService service = MusicServiceFactory.getMusicService(context);
String albumId = service
.getAlbumList("alphabeticalByName", 1, 0, false, context, null)
.getChildren().get(0).getId();

MusicDirectory.Entry musicEntry = service
.getAlbum(albumId, "", false, context, null)
.getSongs()
.get(0);


List<MusicDirectory.Entry> musicEntries = new LinkedList<>();

for (int i = 0; i < size; i++) {
musicEntries.add(musicEntry);
}

return musicEntries;

} catch (Exception ex) {
throw new AssertionError("Failed to fetch songs");
// Throwing exactly AssertError because it will not require to add *throws Exception*
// to every test case where this method gets used
}

return musicEntries;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import github.daneren2005.dsub.util.Constants;
import github.daneren2005.dsub.util.SilentBackgroundTask;
import github.daneren2005.dsub.util.FileUtil;
import github.daneren2005.dsub.util.SongDBHandler;
import github.daneren2005.dsub.util.Util;
import github.daneren2005.dsub.util.CacheCleaner;
import github.daneren2005.serverproxy.BufferFile;
Expand Down Expand Up @@ -171,6 +172,8 @@ public synchronized void downloadNow(MusicService musicService) {
}
}
private void preDownload() {
SongDBHandler.getHandler(context).addSong(this); // Add every locally available
// song to db so we can use their serverId for offline scrobbling
FileUtil.createDirectoryForParent(saveFile);
failedDownload = false;
if(!partialFile.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ public void scrobble(String id, boolean submission, Context context, ProgressLis
SharedPreferences.Editor offlineEditor = offline.edit();

if(id.indexOf(cacheLocn) != -1) {
Pair<Integer, String> cachedSongId = SongDBHandler.getHandler(context).getIdFromPath(id);
Pair<Integer, String> cachedSongId = SongDBHandler.getHandler(context).getIdFromPath(id.replace(".complete", ""));
if(cachedSongId != null) {
offlineEditor.putString(Constants.OFFLINE_SCROBBLE_ID + scrobbles, cachedSongId.getSecond());
offlineEditor.remove(Constants.OFFLINE_SCROBBLE_SEARCH + scrobbles);
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/album_list_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
android:id="@+id/item_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/main.albums_per_folder"
android:layout_gravity="end|center_vertical"
android:textColor="?android:textColorPrimary"/>
</LinearLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/basic_count_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:layout_marginBottom="4px"
android:background="@drawable/ic_number_border"
android:focusable="false"
android:gravity="right|center_vertical"
android:gravity="center|center_vertical"
android:text="99"
android:textAppearance="?android:attr/textAppearanceSmallPopupMenu"
android:textColor="?android:textColorPrimary"
Expand Down