@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); }
@Test public void enumMethods() { assertEquals(1, DisposableHelper.values().length); assertNotNull(DisposableHelper.valueOf("DISPOSED")); }
@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 testCollectionInjectionFromSameConfigurationClass() { ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class); CollectionInjectionConfiguration bean = ctx.getBean(CollectionInjectionConfiguration.class); assertNotNull(bean.testBeans); assertEquals(1, bean.testBeans.size()); assertSame(ctx.getBean(TestBean.class), bean.testBeans.get(0)); }
@Test public void backpressureKind() { assertEquals(6, BackpressureKind.values().length); assertNotNull(BackpressureKind.valueOf("FULL")); }
@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 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); }
@Test public void emptyObserverEnum() { assertEquals(1, TestObserver.EmptyObserver.values().length); assertNotNull(TestObserver.EmptyObserver.valueOf("INSTANCE")); }
@Test public void switchMapInnerCancelled() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = Flowable.just(1) .switchMap(Functions.justFunction(pp)) .test(); assertTrue(pp.hasSubscribers()); ts.cancel(); assertFalse(pp.hasSubscribers()); }
@Test public void loadPackagePrivateFactory() { List<DummyPackagePrivateFactory> factories = SpringFactoriesLoader.loadFactories(DummyPackagePrivateFactory.class, null); assertEquals(1, factories.size()); assertTrue((factories.get(0).getClass().getModifiers() & Modifier.PUBLIC) == 0); }
@Test public void checkEnum() { assertEquals(2, EmptyDisposable.values().length); assertNotNull(EmptyDisposable.valueOf("INSTANCE")); assertNotNull(EmptyDisposable.valueOf("NEVER")); } }
@Test public void cancelAsFlowable() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = pp.singleOrError().toFlowable().test(); assertTrue(pp.hasSubscribers()); ts.assertEmpty(); ts.cancel(); assertFalse(pp.hasSubscribers()); }
@Test public void testCollectionArgumentOnBeanMethod() { ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class); CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class); assertNotNull(bean.testBeans); assertEquals(1, bean.testBeans.size()); assertSame(ctx.getBean(TestBean.class), bean.testBeans.get(0)); }
@Test public void emptyWithOnNext() { PublishProcessor<Object> pp = PublishProcessor.create(); TestObserver<Integer> to = Maybe.<Integer>empty() .delay(pp).test(); to.assertEmpty(); assertTrue(pp.hasSubscribers()); pp.onNext(1); assertFalse(pp.hasSubscribers()); to.assertResult(); }
@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)); }
@Test public void selectorFallbackTake() { PublishProcessor<Integer> pp = PublishProcessor.create(); TestSubscriber<Integer> ts = pp .timeout(Functions.justFunction(Flowable.never()), Flowable.just(2)) .take(1) .test(); assertTrue(pp.hasSubscribers()); pp.onNext(1); assertFalse(pp.hasSubscribers()); ts.assertResult(1); }
@Test public void testSPR3304() throws Exception { Method bridgedMethod = MegaMessageProducerImpl.class.getDeclaredMethod("receive", MegaMessageEvent.class); assertFalse(bridgedMethod.isBridge()); Method bridgeMethod = MegaMessageProducerImpl.class.getDeclaredMethod("receive", MegaEvent.class); assertTrue(bridgeMethod.isBridge()); assertEquals(bridgedMethod, BridgeMethodResolver.findBridgedMethod(bridgeMethod)); }
@Test public void mergeListWithInnerBeanAsListElement() throws Exception { TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefs"); List list = bean.getSomeList(); assertNotNull(list); assertEquals(3, list.size()); assertNotNull(list.get(2)); assertTrue(list.get(2) instanceof TestBean); }
@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 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()); }