Skip to content

Instantly share code, notes, and snippets.


Eric Silverberg esilverberg

View GitHub Profile
esilverberg / BlockingFirstTest.kt
Last active Nov 29, 2021
blockingMostRecent vs blockingFirst
View BlockingFirstTest.kt
@DisplayName("Given we are testing blockingFirst")
class BlockingFirstTest : KoinTest() {
private val behaviorSubject: BehaviorSubject<Int> = BehaviorSubject.createDefault(0)
private val observableSubject: Observable<Int> = behaviorSubject
fun `then it should have emitted six times`() {
var didEmit = 0
observableSubject.doOnNext { didEmit += 1 }.blockingMostRecent(null).iterator().next()
View Naming API
Platform Interface Implementation Example
iOS <feature>ApiImplementing <feature>Api MatchApiImplementing / MatchApi
Android I<feature>Api <feature>Api IMatchApi / MatchApi
View API class method
iOS SignalProducer<T, TError> or AnyPublisher<T, TError> SignalProducer<Void, Error> or AnyPublisher<Void, TError>
Android Single Completable
View ViewModel
Type RxJava ReactiveSwift Combine
properties Observable<T>, where Observable is often backed by a BehaviorSubject Property<T>, where it wraps a MutableProperty CurrentValueSubject or @Published
retrieving values Single<T> SignalProducer<T> Publisher<T, Error>, or Deferred + Future
modifying state Completable SignalProducer<Void, Error> Publisher<T, Error>
View API error mapping
static func mapError(apiError: Error) -> PSSFreeTrialError {
if let apiError = apiError as? PSSApiError {
switch apiError.statusCode {
return PSSFreeTrialError.cannotBeActivated
View TestObserver in Java
@DisplayName("given I flag someone")
inner class FlagSomeone {
lateinit var testObserver: TestObserver<MatchEvent>
lateinit var targetProfile: Profile
fun setup() {
testObserver =
View TestObserver in ReactiveSwift
context("given I flag someone") {
var testObs: TestObserver<PSSMatchViewModel.Event, Never>!
var targetProfile: PSSProfile!
beforeEach {
testObs = TestObserver<PSSMatchViewModel.Event, Never>()
for _ in 0..<instructionCardsNum {
viewModel.swipe(rating: PSSMatchRating.interested)
View Test thread execution in Java
class InstantExecutorExtension : BeforeEachCallback, AfterEachCallback {
override fun beforeEach(context: ExtensionContext?) {
.setDelegate(object : TaskExecutor() {
override fun executeOnDiskIO(runnable: Runnable) =
override fun postToMainThread(runnable: Runnable) =
override fun isMainThread(): Boolean = true
View BDD style tests in Kotlin
@DisplayName("given instruction cards should be shown")
inner class InstructionCards {
fun setup() {
fun `then swipe right card shown first`() {
View BDD style tests in Swift
context("given instruction cards should be shown") {
var testObs: TestObserver<PSSMatchViewModel.Event, Never>!
beforeEach {
testObs = TestObserver<PSSMatchViewModel.Event, Never>()
it("then swipe right card shown first") {
guard case .started(let context) = viewModel.state.value else {