@Test public void test() { assertNotNull("TestRule should have been @Autowired", autowiredTestRule); // Rationale for the following assertion: // // The field value for the custom rule is null when JUnit sees it. JUnit then // ignores the null value, and at a later point in time Spring injects the rule // from the ApplicationContext and overrides the null field value. But that's too // late: JUnit never sees the rule supplied by Spring via dependency injection. assertFalse("@Autowired TestRule should NOT have been applied", autowiredTestRule.applied); }
@Test public void verifyRootWacConfig() { ApplicationContext parent = wac.getParent(); assertNotNull(parent); assertFalse(parent instanceof WebApplicationContext); assertEquals("ear", ear); assertEquals("root", root); }
@Test public void hidden() { assertTrue(Maybe.just(1) instanceof ScalarCallable); assertFalse(Maybe.just(1).hide() instanceof ScalarCallable); }
private void assertLines(final List<String> lines, final LineIterator iterator) { try { for (int i = 0; i < lines.size(); i++) { final String line = iterator.nextLine(); assertEquals("nextLine() line " + i, lines.get(i), line); } assertFalse("No more expected", iterator.hasNext()); } finally { LineIterator.closeQuietly(iterator); } }
@Test public void testTakeOneSubscriber() { BehaviorSubject<Integer> source = BehaviorSubject.createDefault(1); final Observer<Object> o = TestHelper.mockObserver(); source.take(1).subscribe(o); verify(o).onNext(1); verify(o).onComplete(); verify(o, never()).onError(any(Throwable.class)); assertEquals(0, source.subscriberCount()); assertFalse(source.hasObservers()); }
/** Tests that basic executeQuery() (with query statement) works. */ @Test public void testExecuteQueryBasicCaseWorks() throws SQLException { try (PreparedStatement stmt = connection.prepareStatement( "VALUES 11" )) { try(ResultSet rs = stmt.executeQuery()) { assertThat("Unexpected column count", rs.getMetaData().getColumnCount(), equalTo(1) ); assertTrue("No expected first row", rs.next()); assertThat(rs.getInt(1), equalTo(11)); assertFalse("Unexpected second row", rs.next()); } } }
private void doTestLazyResourceInjection(Class<? extends TestBeanHolder> annotatedBeanClass) { AnnotationConfigApplicationContext ac = new AnnotationConfigApplicationContext(); RootBeanDefinition abd = new RootBeanDefinition(annotatedBeanClass); abd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE); ac.registerBeanDefinition("annotatedBean", abd); RootBeanDefinition tbd = new RootBeanDefinition(TestBean.class); tbd.setLazyInit(true); ac.registerBeanDefinition("testBean", tbd); ac.refresh(); TestBeanHolder bean = ac.getBean("annotatedBean", TestBeanHolder.class); assertFalse(ac.getBeanFactory().containsSingleton("testBean")); assertNotNull(bean.getTestBean()); assertNull(bean.getTestBean().getName()); assertTrue(ac.getBeanFactory().containsSingleton("testBean")); TestBean tb = (TestBean) ac.getBean("testBean"); tb.setName("tb"); assertSame("tb", bean.getTestBean().getName()); }
@Test public void testStaticScriptWithInlineDefinedInstanceUsingJsr223() throws Exception { ApplicationContext ctx = new ClassPathXmlApplicationContext("groovyContextWithJsr223.xml", getClass()); assertTrue(Arrays.asList(ctx.getBeanNamesForType(Messenger.class)).contains("messengerInstanceInline")); Messenger messenger = (Messenger) ctx.getBean("messengerInstanceInline"); assertFalse("Shouldn't get proxy when refresh is disabled", AopUtils.isAopProxy(messenger)); assertFalse("Scripted object should not be instance of Refreshable", messenger instanceof Refreshable); String desiredMessage = "Hello World!"; assertEquals("Message is incorrect", desiredMessage, messenger.getMessage()); assertTrue(ctx.getBeansOfType(Messenger.class).values().contains(messenger)); }
@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); }
@Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() { ReplaySubject<Object> rs = ReplaySubject.createUnbounded(); rs.onComplete(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); }
/** Tests that basic executeQuery() (with query statement) works. */ @Test public void testExecuteQueryBasicCaseWorks() throws SQLException { try (PreparedStatement stmt = connection.prepareStatement( "VALUES 11" )) { try(ResultSet rs = stmt.executeQuery()) { assertThat("Unexpected column count", rs.getMetaData().getColumnCount(), equalTo(1) ); assertTrue("No expected first row", rs.next()); assertThat(rs.getInt(1), equalTo(11)); assertFalse("Unexpected second row", rs.next()); } } }
@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()); }
@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()); }
@Test public void testSizeAndHasAnyValueUnboundedEmptyCompleted() { ReplayProcessor<Object> rs = ReplayProcessor.create(); rs.onComplete(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); }
@Test public void normal() { TestSingle<Integer> tc = new TestSingle<Integer>(); assertFalse(tc.isDisposed()); assertEquals(0, tc.start); assertTrue(tc.values.isEmpty()); assertTrue(tc.errors.isEmpty()); Single.just(1).subscribe(tc); assertFalse(tc.isDisposed()); assertEquals(1, tc.start); assertEquals(1, tc.values.get(0).intValue()); assertTrue(tc.errors.isEmpty()); }
@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()); }
@Test public void testSizeAndHasAnyValueEffectivelyUnboundedEmptyCompleted() { ReplayProcessor<Object> rs = ReplayProcessor.createUnbounded(); rs.onComplete(); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); }
@Test @SuppressWarnings("unchecked") public void testEntityManagerProxyIsProxy() { EntityManager em = entityManagerFactory.createEntityManager(); assertTrue(Proxy.isProxyClass(em.getClass())); Query q = em.createQuery("select p from Person as p"); List<Person> people = q.getResultList(); assertNotNull(people); assertTrue("Should be open to start with", em.isOpen()); em.close(); assertFalse("Close should work on application managed EM", em.isOpen()); }
@Test public void dispose() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestObserver<Integer> to = pp.singleElement().switchIfEmpty(Single.just(2)).test(); assertTrue(pp.hasSubscribers()); to.cancel(); assertFalse(pp.hasSubscribers()); }
@Test public void testSizeAndHasAnyValueUnboundedEmptyError() { ReplayProcessor<Object> rs = ReplayProcessor.create(); rs.onError(new TestException()); assertEquals(0, rs.size()); assertFalse(rs.hasValue()); }