OpenWebNetObservable { static Func1<String, Observable<OpenContext>> expectedAck(OpenContext context) { return s -> Statement.ifThen( () -> s.startsWith(ACK), Observable.just(context), Observable.error(new IllegalStateException("expected ACK"))); } private  OpenWebNetObservable();   }
@Test public void testExpectedAckValid() { TestSubscriber<OpenContext> tester = new TestSubscriber<>(); Observable.just(OpenMessage.ACK) .flatMap(OpenWebNetObservable.expectedAck(mockedContext)) .subscribe(tester); tester.assertValue(mockedContext); tester.assertCompleted(); tester.assertNoErrors(); }
@Test public void testExpectedAckInvalid() { TestSubscriber<OpenContext> tester = new TestSubscriber<>(); Observable.just("INVALID-ACK") .flatMap(OpenWebNetObservable.expectedAck(mockedContext)) .subscribe(tester); tester.assertNotCompleted(); tester.assertError(IllegalStateException.class); }