本文整理了Java中org.junit.Assert
类的一些代码示例,展示了Assert
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert
类的具体详情如下:
包路径:org.junit.Assert
类名称:Assert
[英]A set of assertion methods useful for writing tests. Only failed assertions are recorded. These methods can be used directly: Assert.assertEquals(...)
, however, they read better if they are referenced through static import:
import static org.junit.Assert.*;
...
assertEquals(...);
[中]一组用于编写测试的断言方法。只记录失败的断言。这些方法可以直接使用:Assert.assertEquals(...)
,但是,如果通过静态导入引用,它们的可读性会更好:
import static org.junit.Assert.*;
...
assertEquals(...);
代码示例来源:origin: ReactiveX/RxJava
public void createInvalidCapacity() {
try {
ReplaySubject.create(-99);
fail("Didn't throw IllegalArgumentException");
} catch (IllegalArgumentException ex) {
assertEquals("capacityHint > 0 required but it was -99", ex.getMessage());
}
}
代码示例来源:origin: ReactiveX/RxJava
public static void assertError(TestObserver<?> to, int index, Class<? extends Throwable> clazz, String message) {
Throwable ex = to.errors().get(0);
if (ex instanceof CompositeException) {
CompositeException ce = (CompositeException) ex;
List<Throwable> cel = ce.getExceptions();
assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
assertEquals(message, cel.get(index).getMessage());
} else {
fail(ex.toString() + ": not a CompositeException");
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void checkEnum() {
assertEquals(2, EmptyDisposable.values().length);
assertNotNull(EmptyDisposable.valueOf("INSTANCE"));
assertNotNull(EmptyDisposable.valueOf("NEVER"));
}
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void accept(Object v, Throwable e) throws Exception {
assertNotNull(v);
assertNull(e);
interrupted.set(Thread.currentThread().isInterrupted());
cdl.countDown();
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void onCompleteFailure() {
AtomicReference<Throwable> onError = new AtomicReference<Throwable>();
try {
OBSERVER_ONCOMPLETED_FAIL(onError).onComplete();
fail("expects exception to be thrown");
} catch (Exception e) {
assertNull(onError.get());
assertTrue(e instanceof SafeObserverTestException);
assertEquals("onCompleteFail", e.getMessage());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void errorNotification() {
Object o = NotificationLite.error(new TestException());
assertEquals("NotificationLite.Error[io.reactivex.exceptions.TestException]", o.toString());
assertTrue(NotificationLite.isError(o));
assertFalse(NotificationLite.isComplete(o));
assertFalse(NotificationLite.isDisposable(o));
assertFalse(NotificationLite.isSubscription(o));
assertTrue(NotificationLite.getError(o) instanceof TestException);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testCurrentStateMethodsEmpty() {
PublishProcessor<Object> as = PublishProcessor.create();
assertFalse(as.hasThrowable());
assertFalse(as.hasComplete());
assertNull(as.getThrowable());
as.onComplete();
assertFalse(as.hasThrowable());
assertTrue(as.hasComplete());
assertNull(as.getThrowable());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void hidden() {
assertTrue(Maybe.just(1) instanceof ScalarCallable);
assertFalse(Maybe.just(1).hide() instanceof ScalarCallable);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void disposableNotification() {
Object o = NotificationLite.disposable(Disposables.empty());
assertEquals("NotificationLite.Disposable[RunnableDisposable(disposed=false, EmptyRunnable)]", o.toString());
assertFalse(NotificationLite.isError(o));
assertFalse(NotificationLite.isComplete(o));
assertTrue(NotificationLite.isDisposable(o));
assertFalse(NotificationLite.isSubscription(o));
assertNotNull(NotificationLite.getDisposable(o));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void completeNotification() {
Object o = NotificationLite.complete();
Object o2 = NotificationLite.complete();
assertSame(o, o2);
assertFalse(NotificationLite.isError(o));
assertTrue(NotificationLite.isComplete(o));
assertFalse(NotificationLite.isDisposable(o));
assertFalse(NotificationLite.isSubscription(o));
assertEquals("NotificationLite.Complete", o.toString());
assertTrue(NotificationLite.isComplete(o));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
Queue<Object> q = new ArrayDeque<Object>();
BlockingObserver<Object> bo = new BlockingObserver<Object>(q);
bo.dispose();
assertEquals(BlockingObserver.TERMINATED, q.poll());
bo.dispose();
assertNull(q.poll());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() {
ReplaySubject<Object> rs = ReplaySubject.createUnbounded();
rs.onComplete();
assertEquals(0, rs.size());
assertFalse(rs.hasValue());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void blockingGetErrorTimedOut() {
final BlockingMultiObserver<Integer> bmo = new BlockingMultiObserver<Integer>();
try {
assertNull(bmo.blockingGetError(1, TimeUnit.NANOSECONDS));
fail("Should have thrown");
} catch (RuntimeException expected) {
assertEquals(TimeoutException.class, expected.getCause().getClass());
assertEquals(timeoutMessage(1, TimeUnit.NANOSECONDS), expected.getCause().getMessage());
}
}
}
代码示例来源:origin: ReactiveX/RxJava
public static void assertError(TestSubscriber<?> ts, int index, Class<? extends Throwable> clazz) {
Throwable ex = ts.errors().get(0);
if (ex instanceof CompositeException) {
CompositeException ce = (CompositeException) ex;
List<Throwable> cel = ce.getExceptions();
assertTrue(cel.get(index).toString(), clazz.isInstance(cel.get(index)));
} else {
fail(ex.toString() + ": not a CompositeException");
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void onErrorStatePeeking() {
UnicastProcessor<Object> p = UnicastProcessor.create();
assertFalse(p.hasComplete());
assertFalse(p.hasThrowable());
assertNull(p.getThrowable());
TestException ex = new TestException();
p.onError(ex);
assertFalse(p.hasComplete());
assertTrue(p.hasThrowable());
assertSame(ex, p.getThrowable());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void scalarCallable() {
Maybe<Integer> m = Maybe.empty();
assertTrue(m.getClass().toString(), m instanceof ScalarCallable);
assertNull(((ScalarCallable<?>)m).call());
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testNonNullConnection() {
ConnectableObservable<Object> source = Observable.never().publish();
assertNotNull(source.connect());
assertNotNull(source.connect());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void noHeadRetentionCompleteSize() {
ReplaySubject<Integer> source = ReplaySubject.createWithSize(1);
source.onNext(1);
source.onNext(2);
source.onComplete();
SizeBoundReplayBuffer<Integer> buf = (SizeBoundReplayBuffer<Integer>)source.buffer;
assertNull(buf.head.value);
Object o = buf.head;
source.cleanupBuffer();
assertSame(o, buf.head);
}
代码示例来源:origin: ReactiveX/RxJava
@Override
public void accept(Boolean aBoolean) {
Assert.assertNull(aBoolean);
}
});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestDisposableSubscriber<Integer> tc = new TestDisposableSubscriber<Integer>();
assertFalse(tc.isDisposed());
tc.dispose();
assertTrue(tc.isDisposed());
BooleanSubscription bs = new BooleanSubscription();
tc.onSubscribe(bs);
assertTrue(bs.isCancelled());
assertEquals(0, tc.start);
}
}
内容来源于网络,如有侵权,请联系作者删除!