ScalarSubscription extends AtomicInteger implements QueueSubscription<T> { @Override public void request(long n) { if (!SubscriptionHelper.validate(n)) { return; } if (compareAndSet(NO_REQUEST, REQUESTED)) { Subscriber<? super T> s = subscriber; s.onNext(value); if (get() != CANCELLED) { s.onComplete(); } } } ScalarSubscription(Subscriber<? super T> subscriber, T value); @Override void request(long n); @Override void cancel(); boolean isCancelled(); @Override boolean offer(T e); @Override boolean offer(T v1, T v2); @Nullable @Override T poll(); @Override boolean isEmpty(); @Override void clear(); @Override int requestFusion(int mode);  }
@Test public void badRequest() { TestSubscriber<Integer> ts = new TestSubscriber<Integer>(0L); ScalarSubscription<Integer> sc = new ScalarSubscription<Integer>(ts, 1); List<Throwable> errors = TestHelper.trackPluginErrors(); try { sc.request(-99); TestHelper.assertError(errors, 0, IllegalArgumentException.class, "n > 0 required but it was -99"); } finally { RxJavaPlugins.reset(); } }