@Test
public void TestRemoveObserverWhileNotifying() {

    PublishSubject<String> observable = new PublishSubject<>();
    final Disposable subscriptionA = observable.subscribe(new Observer<String>() {
        @Override
        public void onChanged(String value) {
            addResult("A" + value);
        }
    });
    observable.subscribe(new Observer<String>() {
        @Override
        public void onChanged(String value) {
            addResult("B" + value);
            subscriptionA.dispose();
        }
    });
    observable.post("1");
    AssertResults("A1", "B1");
    observable.post("2");
    AssertResults("B2");
}