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
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
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
public final class WithoutDefaultConstructor { | |
private final int intValue; | |
@NotNull | |
private final String strValue; | |
public WithoutDefaultConstructor(int intValue, @NotNull String strValue) { | |
super(); | |
this.intValue = intValue; | |
this.strValue = strValue; | |
} |
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
data class WithoutDefaultConstructor( | |
val intValue: Int, | |
val strValue: String = "default" | |
) | |
data class WithDefaultConstructor( | |
val intValue: Int = 1, | |
val strValue: String = "default" | |
) |
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
data class SomeData( | |
val intValue: Int = 0, | |
val strValue: String = "default value" | |
) |
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
data class SomeData( | |
val intValue: Int, | |
val strValue: String = "default value" | |
) |
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 SomeStrictActivity : Activity() { | |
companion object { | |
@JvmStatic | |
fun createIntent(context: Context, importantParameter: Parameter): Intent { | |
val intent = Intent(context, SomeStrictActivity::class.java) | |
intent.putExtra(EXTRA_PARAMETER, importantParameter) | |
return intent | |
} | |
} |
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
// try-ignore approach | |
try { | |
doAction() | |
} catch (exc: SomePreconditionViolated) { | |
//ignore | |
} finally { | |
finalize() | |
} | |
/* ^ COMPARE v */ |
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
// try-fail-catch approach | |
try { | |
doMainAction() | |
} catch (exc: SomePreconditionViolated) { | |
doFallbackAction() | |
} | |
/* ^ COMPARE v */ | |
// check-and-execute approach |