本文整理了Java中org.junit.Assert.assertTrue()
方法的一些代码示例,展示了Assert.assertTrue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.assertTrue()
方法的具体详情如下:
包路径:org.junit.Assert
类名称:Assert
方法名:assertTrue
[英]Asserts that a condition is true. If it isn't it throws an AssertionError with the given message.
[中]断言某个条件为真。如果不是,则抛出带有给定消息的AssertionError。
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testListWithInconsistentElementType() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spr7283.xml", getClass());
List<?> list = ctx.getBean("list", List.class);
assertEquals(2, list.size());
assertTrue(list.get(0) instanceof A);
assertTrue(list.get(1) instanceof B);
}
代码示例来源: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 hidden() {
assertTrue(Maybe.just(1) instanceof ScalarCallable);
assertFalse(Maybe.just(1).hide() instanceof ScalarCallable);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void loadFactoriesInCorrectOrder() {
List<DummyFactory> factories = SpringFactoriesLoader.loadFactories(DummyFactory.class, null);
assertEquals(2, factories.size());
assertTrue(factories.get(0) instanceof MyDummyFactory1);
assertTrue(factories.get(1) instanceof MyDummyFactory2);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void untilMaybeMainComplete() {
MaybeSubject<Integer> main = MaybeSubject.create();
MaybeSubject<Integer> other = MaybeSubject.create();
TestObserver<Integer> to = main.takeUntil(other).test();
assertTrue("Main no observers?", main.hasObservers());
assertTrue("Other no observers?", other.hasObservers());
main.onComplete();
assertFalse("Main has observers?", main.hasObservers());
assertFalse("Other has observers?", other.hasObservers());
to.assertResult();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void onErrorFailure() {
try {
subscriberOnErrorFail().onError(new SafeSubscriberTestException("error!"));
fail("expects exception to be thrown");
} catch (Exception e) {
assertTrue(e instanceof SafeSubscriberTestException);
assertEquals("onErrorFail", e.getMessage());
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testPrototypeListFactory() throws Exception {
List list = (List) this.beanFactory.getBean("pListFactory");
assertTrue(list instanceof LinkedList);
assertTrue(list.size() == 2);
assertEquals("bar", list.get(0));
assertEquals("jenny", list.get(1));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void untilPublisherMainSuccess() {
MaybeSubject<Integer> main = MaybeSubject.create();
PublishProcessor<Integer> other = PublishProcessor.create();
TestObserver<Integer> to = main.takeUntil(other).test();
assertTrue("Main no observers?", main.hasObservers());
assertTrue("Other no observers?", other.hasSubscribers());
main.onSuccess(1);
assertFalse("Main has observers?", main.hasObservers());
assertFalse("Other has observers?", other.hasSubscribers());
to.assertResult(1);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestMaybe<Integer> tc = new TestMaybe<Integer>();
tc.dispose();
assertTrue(tc.isDisposed());
Disposable d = Disposables.empty();
tc.onSubscribe(d);
assertTrue(d.isDisposed());
assertEquals(0, tc.start);
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testListFactory() throws Exception {
List list = (List) this.beanFactory.getBean("listFactory");
assertTrue(list instanceof LinkedList);
assertTrue(list.size() == 2);
assertEquals("bar", list.get(0));
assertEquals("jenny", list.get(1));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void untilPublisherMainError() {
MaybeSubject<Integer> main = MaybeSubject.create();
PublishProcessor<Integer> other = PublishProcessor.create();
TestObserver<Integer> to = main.takeUntil(other).test();
assertTrue("Main no observers?", main.hasObservers());
assertTrue("Other no observers?", other.hasSubscribers());
main.onError(new TestException());
assertFalse("Main has observers?", main.hasObservers());
assertFalse("Other has observers?", other.hasSubscribers());
to.assertFailure(TestException.class);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
TestCompletable tc = new TestCompletable();
tc.dispose();
assertTrue(tc.isDisposed());
Disposable d = Disposables.empty();
tc.onSubscribe(d);
assertTrue(d.isDisposed());
assertEquals(0, tc.start);
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normal() {
TestResourceObserver<Integer> tc = new TestResourceObserver<Integer>();
assertFalse(tc.isDisposed());
assertEquals(0, tc.start);
assertTrue(tc.values.isEmpty());
assertTrue(tc.errors.isEmpty());
Observable.just(1).subscribe(tc);
assertTrue(tc.isDisposed());
assertEquals(1, tc.start);
assertEquals(1, tc.values.get(0).intValue());
assertTrue(tc.errors.isEmpty());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void mainCompletes() {
PublishProcessor<Integer> pp1 = PublishProcessor.create();
PublishProcessor<Integer> pp2 = PublishProcessor.create();
TestObserver<Integer> to = pp1.singleElement().takeUntil(pp2.singleElement()).test();
assertTrue(pp1.hasSubscribers());
assertTrue(pp2.hasSubscribers());
pp1.onComplete();
assertFalse(pp1.hasSubscribers());
assertFalse(pp2.hasSubscribers());
to.assertResult();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
@Ignore("Observers can't throw")
public void onErrorNotImplementedFailureSafe() {
try {
new SafeObserver<String>(OBSERVER_ONERROR_NOTIMPLEMENTED()).onError(new SafeObserverTestException("error!"));
fail("expects exception to be thrown");
} catch (Exception e) {
// assertTrue(e instanceof OnErrorNotImplementedException);
assertTrue(e.getCause() instanceof SafeObserverTestException);
assertEquals("error!", e.getCause().getMessage());
}
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testGetAllInterfaces() {
DerivedTestObject testBean = new DerivedTestObject();
List<Class<?>> ifcs = Arrays.asList(ClassUtils.getAllInterfaces(testBean));
assertEquals("Correct number of interfaces", 4, ifcs.size());
assertTrue("Contains Serializable", ifcs.contains(Serializable.class));
assertTrue("Contains ITestBean", ifcs.contains(ITestObject.class));
assertTrue("Contains IOther", ifcs.contains(ITestInterface.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void shouldUnsubscribeFromUnderlyingSubscriptionOnDispose() {
final PublishProcessor<String> processor = PublishProcessor.create();
final TestScheduler scheduler = new TestScheduler();
final TestSubscriber<String> subscriber = processor
.timeout(100, TimeUnit.MILLISECONDS, scheduler)
.test();
assertTrue(processor.hasSubscribers());
subscriber.dispose();
assertFalse(processor.hasSubscribers());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void error() {
TestResourceObserver<Integer> tc = new TestResourceObserver<Integer>();
assertFalse(tc.isDisposed());
assertEquals(0, tc.start);
assertTrue(tc.values.isEmpty());
assertTrue(tc.errors.isEmpty());
final RuntimeException error = new RuntimeException("error");
Observable.<Integer>error(error).subscribe(tc);
assertTrue(tc.isDisposed());
assertEquals(1, tc.start);
assertTrue(tc.values.isEmpty());
assertEquals(1, tc.errors.size());
assertTrue(tc.errors.contains(error));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void dispose() {
PublishProcessor<Integer> pp = PublishProcessor.create();
TestObserver<Integer> to = pp.singleElement().delay(100, TimeUnit.MILLISECONDS).test();
assertTrue(pp.hasSubscribers());
to.cancel();
assertFalse(pp.hasSubscribers());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void normal() {
TestDisposableObserver<Integer> tc = new TestDisposableObserver<Integer>();
assertFalse(tc.isDisposed());
assertEquals(0, tc.start);
assertTrue(tc.values.isEmpty());
assertTrue(tc.errors.isEmpty());
Observable.just(1).subscribe(tc);
assertFalse(tc.isDisposed());
assertEquals(1, tc.start);
assertEquals(1, tc.values.get(0).intValue());
assertTrue(tc.errors.isEmpty());
}
内容来源于网络,如有侵权,请联系作者删除!