@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 orderOnImplementation() { this.context = new AnnotationConfigApplicationContext( UserServiceTwo.class, UserServiceOne.class, UserServiceCollector.class); UserServiceCollector bean = this.context.getBean(UserServiceCollector.class); assertSame(context.getBean("serviceOne", UserService.class), bean.userServices.get(0)); assertSame(context.getBean("serviceTwo", UserService.class), bean.userServices.get(1)); }
@Test public void collectionMapNotGenericTarget() throws Exception { Map<String, List<String>> map = new HashMap<>(); map.put("1", Arrays.asList("9", "12")); map.put("2", Arrays.asList("37", "23")); assertTrue(conversionService.canConvert(Map.class, Map.class)); assertSame(map, conversionService.convert(map, Map.class)); }
@Test public void badException() { Throwable e = new BadException(); assertSame(e, new CompositeException(e).getCause().getCause()); assertSame(e, new CompositeException(new RuntimeException(e)).getCause().getCause().getCause()); }
@Test public void properties() { Timed<Integer> timed = new Timed<Integer>(1, 5, TimeUnit.SECONDS); assertEquals(1, timed.value().intValue()); assertEquals(5, timed.time()); assertEquals(5000, timed.time(TimeUnit.MILLISECONDS)); assertSame(TimeUnit.SECONDS, timed.unit()); }
@Test public void noHeadRetentionSize() { ReplaySubject<Integer> source = ReplaySubject.createWithSize(1); source.onNext(1); source.onNext(2); SizeBoundReplayBuffer<Integer> buf = (SizeBoundReplayBuffer<Integer>)source.buffer; assertNotNull(buf.head.value); source.cleanupBuffer(); assertNull(buf.head.value); Object o = buf.head; source.cleanupBuffer(); assertSame(o, buf.head); }
@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 testInterfaceProxiesCanBeOrderedThroughAnnotations() { Object proxy1 = new ProxyFactory(new A()).getProxy(); Object proxy2 = new ProxyFactory(new B()).getProxy(); List<Object> list = new ArrayList<>(2); list.add(proxy1); list.add(proxy2); AnnotationAwareOrderComparator.sort(list); assertSame(proxy2, list.get(0)); assertSame(proxy1, list.get(1)); }
@Test public void testTranslatesIllegalStateException() { IllegalStateException ise = new IllegalStateException(); DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ise); assertSame(ise, dex.getCause()); assertTrue(dex instanceof InvalidDataAccessApiUsageException); }
@SuppressWarnings("unchecked") @Test public void emptyArray() { assertSame(Flowable.empty(), Flowable.concatArrayDelayError()); }
private void assertOrder(List<?> actual, Object... expected) { for (int i = 0; i < actual.size(); i++) { assertSame("Wrong instance at index '" + i + "'", expected[i], actual.get(i)); } assertEquals("Wrong number of items", expected.length, actual.size()); }
@Test public void addInterceptorsWithCustomPathMatcher() { PathMatcher pathMatcher = Mockito.mock(PathMatcher.class); this.registry.addInterceptor(interceptor1).addPathPatterns("/path1/**").pathMatcher(pathMatcher); MappedInterceptor mappedInterceptor = (MappedInterceptor) this.registry.getInterceptors().get(0); assertSame(pathMatcher, mappedInterceptor.getPathMatcher()); }
@Test public void source() { Maybe<Integer> m = Maybe.just(1); Single<Integer> s = m.toSingle(); assertTrue(s.getClass().toString(), s instanceof HasUpstreamMaybeSource); assertSame(m, (((HasUpstreamMaybeSource<?>)s).source())); }
@Test public void source() { Observable<Integer> source = Observable.range(1, 3); assertSame(source, (((HasUpstreamObservableSource<?>)source.replay())).source()); }
@Test public void testVarargOnBeanMethod() { ApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class, TestBean.class); VarargConfiguration bean = ctx.getBean(VarargConfiguration.class); assertNotNull(bean.testBeans); assertEquals(1, bean.testBeans.length); assertSame(ctx.getBean(TestBean.class), bean.testBeans[0]); }
@Test public void customViewResolver() { InternalResourceViewResolver viewResolver = new InternalResourceViewResolver("/", ".jsp"); this.registry.viewResolver(viewResolver); assertSame(viewResolver, this.registry.getViewResolvers().get(0)); }
@Test public void collectionToObjectInteraction() throws Exception { List<List<String>> list = new ArrayList<>(); list.add(Arrays.asList("9", "12")); list.add(Arrays.asList("37", "23")); conversionService.addConverter(new CollectionToObjectConverter(conversionService)); assertTrue(conversionService.canConvert(List.class, List.class)); assertSame(list, conversionService.convert(list, List.class)); }
@Test public void testDontWrapSerializedSubjectAgain() { PublishProcessor<Object> s = PublishProcessor.create(); FlowableProcessor<Object> s1 = s.toSerialized(); FlowableProcessor<Object> s2 = s1.toSerialized(); assertSame(s1, s2); }
@Test public void testMapInjectionFromSameConfigurationClass() { ApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class); MapInjectionConfiguration bean = ctx.getBean(MapInjectionConfiguration.class); assertNotNull(bean.testBeans); assertEquals(1, bean.testBeans.size()); assertSame(ctx.getBean(Runnable.class), bean.testBeans.get("testBean")); }
@Test public void convertAndSendWithSimpMessageHeaders() { MessageHeaderAccessor accessor = new MessageHeaderAccessor(); accessor.setHeader("key", "value"); accessor.setLeaveMutable(true); MessageHeaders headers = accessor.getMessageHeaders(); this.template.convertAndSend("channel", "data", headers); List<Message<byte[]>> messages = this.messageChannel.getMessages(); Message<byte[]> message = messages.get(0); assertSame(headers, message.getHeaders()); assertFalse(accessor.isMutable()); }