SuccessObserver implements Observer<Result<D>> { @Override public void onChanged(@Nullable Result<D> result) { if (result == null) { onEmpty(); return; } result.ifPresentOrElse(this::onSuccess, this::onEmpty); }  static SuccessObserver<D> with(Consumer<D> onSuccess); @Override void onChanged(@Nullable Result<D> result);  }
@Test public void testSuccess() { TestSuccessObserver observer = new TestSuccessObserver(); Result<Integer> result = Result.Builder.fromData(1); observer.onChanged(result); assertTrue(observer.hasCalledSuccess); assertEquals(Integer.valueOf(1), observer.successData); assertFalse(observer.hasCalledEmpty); }
@Test public void testEmpty() { TestSuccessObserver observer = new TestSuccessObserver(); Result<Integer> result = Result.Builder.fromException(new RequestException()); observer.onChanged(result); assertFalse(observer.hasCalledSuccess); assertTrue(observer.hasCalledEmpty); }
@Test public void testNull() { TestSuccessObserver observer = new TestSuccessObserver(); observer.onChanged(null); assertFalse(observer.hasCalledSuccess); assertTrue(observer.hasCalledEmpty); }