### Question:
MaybeOnSubscribeExecuteAsBlocking implements MaybeOnSubscribe<Result> { @Override public void subscribe(@NonNull MaybeEmitter<Result> emitter) throws Exception { try { final Result value = preparedOperation.executeAsBlocking(); if (value != null) { emitter.onSuccess(value); } else { emitter.onComplete(); } } catch (Exception e) { emitter.onError(e); } } MaybeOnSubscribeExecuteAsBlocking(@NonNull PreparedMaybeOperation<Result, WrappedResult, Data> preparedOperation); @Override void subscribe(@NonNull MaybeEmitter<Result> emitter);  }### Answer:
@SuppressWarnings("CheckResult") @Test public void shouldExecuteAsBlockingAfterSubscription() { final PreparedMaybeOperation<String, String, String> preparedOperation = mock(PreparedMaybeOperation.class); String expectedResult = "test"; when(preparedOperation.executeAsBlocking()).thenReturn(expectedResult); TestObserver<String> testObserver = new TestObserver<String>(); verifyZeroInteractions(preparedOperation); Maybe<String> maybe = Maybe.create(new MaybeOnSubscribeExecuteAsBlocking<String, String, String>(preparedOperation)); verifyZeroInteractions(preparedOperation); maybe.subscribe(testObserver); testObserver.assertValue(expectedResult); testObserver.assertNoErrors(); testObserver.assertComplete(); verify(preparedOperation).executeAsBlocking(); }
@SuppressWarnings("CheckResult") @Test public void shouldCompleteIfNullOccurred() { final PreparedMaybeOperation<String, String, String> preparedOperation = mock(PreparedMaybeOperation.class); when(preparedOperation.executeAsBlocking()).thenReturn(null); TestObserver<String> testObserver = new TestObserver<String>(); verifyZeroInteractions(preparedOperation); Maybe<String> maybe = Maybe.create(new MaybeOnSubscribeExecuteAsBlocking<String, String, String>(preparedOperation)); verifyZeroInteractions(preparedOperation); maybe.subscribe(testObserver); testObserver.assertNoErrors(); testObserver.assertComplete(); verify(preparedOperation).executeAsBlocking(); }
@SuppressWarnings("CheckResult") @Test public void shouldCallOnErrorIfExceptionOccurred() { final PreparedMaybeOperation<Object, Object, Object> preparedOperation = mock(PreparedMaybeOperation.class); StorIOException expectedException = new StorIOException("test exception"); when(preparedOperation.executeAsBlocking()).thenThrow(expectedException); TestObserver<Object> testObserver = new TestObserver<Object>(); Maybe<Object> maybe = Maybe.create(new MaybeOnSubscribeExecuteAsBlocking<Object, Object, Object>(preparedOperation)); verifyZeroInteractions(preparedOperation); maybe.subscribe(testObserver); testObserver.assertError(expectedException); testObserver.assertNotComplete(); verify(preparedOperation).executeAsBlocking(); }