// Path: app/src/main/java/com/zsorg/neteasecloudmusic/models/ScanMusicModel.java
// public class ScanMusicModel implements IMusicModel {
// 
//     private boolean isFilter60s;
// 
//     @Override
//     public Flowable<MusicBean> scanMusicFile() {
//         return mScanMusicOnStorage(Environment.getExternalStorageDirectory())
//                 .observeOn(Schedulers.computation())
//                 .flatMap(new Function<File, Publisher<MusicBean>>() {
//                     @Override
//                     public Publisher<MusicBean> apply(File file) throws Exception {
//                         MusicBean bean = MP3Util.parseMP3File(file.getAbsolutePath());
//                         if (null!=bean && (bean.getDuration()>60000 || !isFilter60s)) {
//                             return Flowable.just(bean).subscribeOn(Schedulers.computation());
//                         }
//                         return Flowable.empty();
//                     }
//                 });
//     }
// 
//     @Override
//     public Flowable<MusicBean> loadMusicFile() {
//         return null;
//     }
// 
//     @Override
//     public void setIsFilter60s(boolean isFilter60s) {
//         this.isFilter60s = isFilter60s;
//     }
// 
//     private Flowable<File> mScanMusicOnStorage(@NonNull final File file) {
//         File[] items = file.listFiles();
//         if (null != items) {
//             return Flowable.fromArray(items).observeOn(Schedulers.computation()).flatMap(new Function<File, Publisher<File>>() {
//                 @Override
//                 public Publisher<File> apply(File file) throws Exception {
//                     if (file != null) {
//                         if (file.isDirectory()) {
//                             return mScanMusicOnStorage(file);
//                         } else {
//                             return Flowable.just(file).filter(new Predicate<File>() {
//                                 @Override
//                                 public boolean test(File file) throws Exception {
//                                     return file.exists() && file.canRead() && MusicUtil.isMusic(file);
//                                 }
//                             });
//                         }
// 
//                     }
//                     //null is forbidden in RxJava2
//                     return Flowable.empty();
//                 }
//             });
//         } else {
//             return Flowable.empty();
//         }
//     }
// }


import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import com.zsorg.neteasecloudmusic.models.ScanMusicModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
package com.zsorg.neteasecloudmusic;





/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

// Path: app/src/main/java/com/zsorg/neteasecloudmusic/models/ScanMusicModel.java
// public class ScanMusicModel implements IMusicModel {
// 
//     private boolean isFilter60s;
// 
//     @Override
//     public Flowable<MusicBean> scanMusicFile() {
//         return mScanMusicOnStorage(Environment.getExternalStorageDirectory())
//                 .observeOn(Schedulers.computation())
//                 .flatMap(new Function<File, Publisher<MusicBean>>() {
//                     @Override
//                     public Publisher<MusicBean> apply(File file) throws Exception {
//                         MusicBean bean = MP3Util.parseMP3File(file.getAbsolutePath());
//                         if (null!=bean && (bean.getDuration()>60000 || !isFilter60s)) {
//                             return Flowable.just(bean).subscribeOn(Schedulers.computation());
//                         }
//                         return Flowable.empty();
//                     }
//                 });
//     }
// 
//     @Override
//     public Flowable<MusicBean> loadMusicFile() {
//         return null;
//     }
// 
//     @Override
//     public void setIsFilter60s(boolean isFilter60s) {
//         this.isFilter60s = isFilter60s;
//     }
// 
//     private Flowable<File> mScanMusicOnStorage(@NonNull final File file) {
//         File[] items = file.listFiles();
//         if (null != items) {
//             return Flowable.fromArray(items).observeOn(Schedulers.computation()).flatMap(new Function<File, Publisher<File>>() {
//                 @Override
//                 public Publisher<File> apply(File file) throws Exception {
//                     if (file != null) {
//                         if (file.isDirectory()) {
//                             return mScanMusicOnStorage(file);
//                         } else {
//                             return Flowable.just(file).filter(new Predicate<File>() {
//                                 @Override
//                                 public boolean test(File file) throws Exception {
//                                     return file.exists() && file.canRead() && MusicUtil.isMusic(file);
//                                 }
//                             });
//                         }
// 
//                     }
//                     //null is forbidden in RxJava2
//                     return Flowable.empty();
//                 }
//             });
//         } else {
//             return Flowable.empty();
//         }
//     }
// }


// Path: app/src/androidTest/java/com/zsorg/neteasecloudmusic/ExampleInstrumentedTest.java
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import com.zsorg.neteasecloudmusic.models.ScanMusicModel;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;

package com.zsorg.neteasecloudmusic;





/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws Exception {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        new ScanMusicModel().scanMusicFile();