This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun waitAndFail(): Single<Nothing> { | |
return Single.fromCallable { | |
Thread.sleep(500) | |
throw IllegalStateException() | |
} | |
} | |
@Test | |
fun `subscription on failing function and do not expect the exception`() { | |
waitAndFail().subscribe() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RxSchedulersTrampolineRule : ExternalResource() { | |
private var defaultExceptionHandler: Thread.UncaughtExceptionHandler? = null | |
override fun before() { | |
// Remember current default exception handler and replace it with one that rethrows the exception | |
// Rethrowing allows unit test fail in the same place the application would fail. | |
defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler() | |
Thread.setDefaultUncaughtExceptionHandler { _, exc -> throw exc } | |
// Turn on Trampoline rule to execute RX call synchronously |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NonLazyDemoAdapter extends FragmentStatePagerAdapter { | |
static class FragmentBundle implements Serializable { | |
int id; | |
String name; | |
FragmentBundle(int id, String name) { | |
this.id = id; | |
this.name = name; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NonLazyDemoAdapter extends FragmentStatePagerAdapter { | |
private SomePage[] pages = new SomePage[]{FIRST, SECOND}; | |
private PageFragment[] cachedFragments = new PageFragment[pages.length]; | |
NonLazyDemoAdapter(FragmentManager fm) { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NonLazyDemoAdapter extends FragmentStatePagerAdapter { | |
@NonNull | |
private SomePage[] pages = new SomePage[]{FIRST, SECOND}; | |
@NonNull | |
private PageFragment[] cachedFragments = new PageFragment[pages.length]; | |
NonLazyDemoAdapter(@NonNull FragmentManager fm) { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NonLazyDemoAdapter extends FragmentStatePagerAdapter { | |
@NonNull // don't forget to mark array content non-nullable | |
private SomePage[] pages = new SomePage[]{FIRST, SECOND}; | |
@NonNull | |
private PageFragment[] cachedFragments = new PageFragment[pages.length]; | |
NonLazyDemoAdapter(@NonNull FragmentManager fm) { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NonLazyDemoAdapter internal constructor(fm: FragmentManager) : FragmentStatePagerAdapter(fm) { | |
private val pages = arrayOf(SomePage.FIRST, SomePage.SECOND) | |
override fun getItem(position: Int): Fragment { | |
return cachedFragments[position]!! | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NonLazyDemoAdapter internal constructor(fm: FragmentManager) : FragmentStatePagerAdapter(fm) { | |
internal class FragmentBundle( | |
@field:SerializedName("id") var id: Int, | |
@field:SerializedName("name") var name: String | |
) : Serializable | |
companion object { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NonLazyDemoAdapter internal constructor(fm: FragmentManager) : FragmentStatePagerAdapter(fm) { | |
internal class FragmentBundle( | |
@JvmField | |
@SerializedName("id") // if this field was used directly before we need JvmField annotation | |
var id: Int, | |
@JvmField | |
@SerializedName("name") // if this field was used directly before we need JvmField annotation | |
var name: String |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun getItem(position: Int): Fragment { | |
return cachedFragments[position]!! | |
} |