mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 06:17:57 +01:00 
			
		
		
		
	Download chapter images
This commit is contained in:
		
							
								
								
									
										40
									
								
								app/src/test/java/eu/kanade/mangafeed/BatotoTest.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										40
									
								
								app/src/test/java/eu/kanade/mangafeed/BatotoTest.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,40 @@ | ||||
| package eu.kanade.mangafeed; | ||||
|  | ||||
| import android.os.Build; | ||||
|  | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.robolectric.RobolectricGradleTestRunner; | ||||
| import org.robolectric.RuntimeEnvironment; | ||||
| import org.robolectric.annotation.Config; | ||||
|  | ||||
| import eu.kanade.mangafeed.data.caches.CacheManager; | ||||
| import eu.kanade.mangafeed.data.helpers.NetworkHelper; | ||||
| import eu.kanade.mangafeed.sources.Batoto; | ||||
| import rx.observers.TestSubscriber; | ||||
|  | ||||
| @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) | ||||
| @RunWith(RobolectricGradleTestRunner.class) | ||||
| public class BatotoTest { | ||||
|  | ||||
|     NetworkHelper net; | ||||
|     CacheManager cache; | ||||
|     Batoto b; | ||||
|     final String chapterUrl ="http://bato.to/read/_/345144/minamoto-kun-monogatari_ch178_by_vortex-scans"; | ||||
|  | ||||
|     @Before | ||||
|     public void setUp() { | ||||
|         net = new NetworkHelper(); | ||||
|         cache = new CacheManager(RuntimeEnvironment.application.getApplicationContext()); | ||||
|         b = new Batoto(net, cache); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void testImageList() { | ||||
|         TestSubscriber a = new TestSubscriber(); | ||||
|  | ||||
|         b.pullImageUrlsFromNetwork(chapterUrl).subscribe(a); | ||||
|         a.assertNoErrors(); | ||||
|     } | ||||
| } | ||||
| @@ -1,70 +0,0 @@ | ||||
| package eu.kanade.mangafeed; | ||||
|  | ||||
|  | ||||
| import android.database.Cursor; | ||||
|  | ||||
| import eu.kanade.mangafeed.data.local.DatabaseHelper; | ||||
| import eu.kanade.mangafeed.data.local.Db; | ||||
| import eu.kanade.mangafeed.data.local.PreferencesHelper; | ||||
| import eu.kanade.mangafeed.data.model.Character; | ||||
| import eu.kanade.mangafeed.data.remote.AndroidBoilerplateService; | ||||
| import eu.kanade.mangafeed.util.DefaultConfig; | ||||
|  | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.robolectric.RobolectricTestRunner; | ||||
| import org.robolectric.RuntimeEnvironment; | ||||
| import org.robolectric.annotation.Config; | ||||
|  | ||||
| import java.util.List; | ||||
|  | ||||
| import rx.Observable; | ||||
| import rx.observers.TestSubscriber; | ||||
| import rx.schedulers.Schedulers; | ||||
|  | ||||
| import static junit.framework.Assert.assertEquals; | ||||
| import static org.mockito.Mockito.mock; | ||||
| import static org.mockito.Mockito.when; | ||||
|  | ||||
| @RunWith(RobolectricTestRunner.class) | ||||
| @Config(constants = BuildConfig.class, sdk = DefaultConfig.EMULATE_SDK, manifest = DefaultConfig.MANIFEST) | ||||
| public class DataManagerTest { | ||||
|  | ||||
|     private DataManager mDataManager; | ||||
|     private AndroidBoilerplateService mMockAndroidBoilerplateService; | ||||
|     private DatabaseHelper mDatabaseHelper; | ||||
|  | ||||
|     @Before | ||||
|     public void setUp() { | ||||
|         mMockAndroidBoilerplateService = mock(AndroidBoilerplateService.class); | ||||
|         mDatabaseHelper = new DatabaseHelper(RuntimeEnvironment.application); | ||||
|         mDatabaseHelper.clearTables().subscribe(); | ||||
|         mDataManager = new DataManager(mMockAndroidBoilerplateService, | ||||
|                 mDatabaseHelper, | ||||
|                 mock(Bus.class), | ||||
|                 new PreferencesHelper(RuntimeEnvironment.application), | ||||
|                 Schedulers.immediate()); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldSyncCharacters() throws Exception { | ||||
|         int[] ids = new int[]{ 10034, 14050, 10435, 35093 }; | ||||
|         List<Character> characters = MockModelsUtil.createListOfMockCharacters(4); | ||||
|         for (int i = 0; i < ids.length; i++) { | ||||
|             when(mMockAndroidBoilerplateService.getCharacter(ids[i])) | ||||
|                     .thenReturn(Observable.just(characters.get(i))); | ||||
|         } | ||||
|  | ||||
|         TestSubscriber<Character> result = new TestSubscriber<>(); | ||||
|         mDataManager.syncCharacters(ids).subscribe(result); | ||||
|         result.assertNoErrors(); | ||||
|         result.assertReceivedOnNext(characters); | ||||
|  | ||||
|         Cursor cursor = mDatabaseHelper.getBriteDb() | ||||
|                 .query("SELECT * FROM " + Db.CharacterTable.TABLE_NAME); | ||||
|         assertEquals(4, cursor.getCount()); | ||||
|         cursor.close(); | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -1,65 +0,0 @@ | ||||
| package eu.kanade.mangafeed; | ||||
|  | ||||
| import android.database.Cursor; | ||||
|  | ||||
| import eu.kanade.mangafeed.data.local.DatabaseHelper; | ||||
| import eu.kanade.mangafeed.data.local.Db; | ||||
| import eu.kanade.mangafeed.data.model.Character; | ||||
| import eu.kanade.mangafeed.util.DefaultConfig; | ||||
|  | ||||
| import org.junit.Before; | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.robolectric.RobolectricTestRunner; | ||||
| import org.robolectric.RuntimeEnvironment; | ||||
| import org.robolectric.annotation.Config; | ||||
|  | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
|  | ||||
| import rx.observers.TestSubscriber; | ||||
|  | ||||
| import static junit.framework.Assert.assertEquals; | ||||
|  | ||||
| @RunWith(RobolectricTestRunner.class) | ||||
| @Config(constants = BuildConfig.class, sdk = DefaultConfig.EMULATE_SDK, manifest = DefaultConfig.MANIFEST) | ||||
| public class DatabaseHelperTest { | ||||
|  | ||||
|     private DatabaseHelper mDatabaseHelper; | ||||
|  | ||||
|     @Before | ||||
|     public void setUp() { | ||||
|         mDatabaseHelper = new DatabaseHelper(RuntimeEnvironment.application); | ||||
|         mDatabaseHelper.clearTables().subscribe(); | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldSetCharacters() throws Exception { | ||||
|         List<Character> characters = MockModelsUtil.createListOfMockCharacters(5); | ||||
|  | ||||
|         TestSubscriber<Character> result = new TestSubscriber<>(); | ||||
|         mDatabaseHelper.setCharacters(characters).subscribe(result); | ||||
|         result.assertNoErrors(); | ||||
|         result.assertReceivedOnNext(characters); | ||||
|  | ||||
|         Cursor cursor = mDatabaseHelper.getBriteDb() | ||||
|                 .query("SELECT * FROM " + Db.CharacterTable.TABLE_NAME); | ||||
|         assertEquals(5, cursor.getCount()); | ||||
|         for (Character character : characters) { | ||||
|             cursor.moveToNext(); | ||||
|             assertEquals(character, Db.CharacterTable.parseCursor(cursor)); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     @Test | ||||
|     public void shouldGetCharacters() throws Exception { | ||||
|         List<Character> characters = MockModelsUtil.createListOfMockCharacters(5); | ||||
|  | ||||
|         mDatabaseHelper.setCharacters(characters).subscribe(); | ||||
|  | ||||
|         TestSubscriber<List<Character>> result = new TestSubscriber<>(); | ||||
|         mDatabaseHelper.getCharacters().subscribe(result); | ||||
|         result.assertNoErrors(); | ||||
|         result.assertReceivedOnNext(Collections.singletonList(characters)); | ||||
|     } | ||||
| } | ||||
| @@ -1,31 +0,0 @@ | ||||
| package eu.kanade.mangafeed; | ||||
|  | ||||
| import org.junit.Test; | ||||
| import org.junit.runner.RunWith; | ||||
| import org.robolectric.RobolectricGradleTestRunner; | ||||
| import org.robolectric.RobolectricTestRunner; | ||||
| import org.robolectric.annotation.Config; | ||||
|  | ||||
|  | ||||
| import static org.robolectric.util.FragmentTestUtil.startFragment; | ||||
| import static org.junit.Assert.assertNotNull; | ||||
|  | ||||
| import eu.kanade.mangafeed.BuildConfig; | ||||
| import eu.kanade.mangafeed.ui.fragment.LibraryFragment; | ||||
| import eu.kanade.mangafeed.util.DefaultConfig; | ||||
|  | ||||
| /** | ||||
|  * Created by len on 1/10/15. | ||||
|  */ | ||||
|  | ||||
| @RunWith(RobolectricGradleTestRunner.class) | ||||
| @Config(constants = BuildConfig.class, sdk = DefaultConfig.EMULATE_SDK) | ||||
| public class LibraryFragmentTest { | ||||
|  | ||||
|     @Test | ||||
|     public void mangaList_shouldNotBeEmpty() { | ||||
|         LibraryFragment fragment = LibraryFragment.newInstance(); | ||||
|         startFragment(fragment); | ||||
|         assertNotNull(fragment); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user