@Test public void verifyAnnotationAutowiredFields() { assertNull("The nonrequiredLong property should NOT have been autowired.", this.nonrequiredLong); assertNotNull("The application context should have been autowired.", this.applicationContext); assertNotNull("The pet field should have been autowired.", this.pet); assertEquals("Dogbert", this.pet.getName()); }
@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 mergeListWithInnerBeanAsListElementInConstructor() throws Exception { TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefsInConstructor"); List list = bean.getSomeList(); assertNotNull(list); assertEquals(3, list.size()); assertNotNull(list.get(2)); assertTrue(list.get(2) instanceof TestBean); }
@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 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 resolveMultipartFileArray() throws Exception { Object actual = resolver.resolveArgument(paramMultipartFileArray, null, webRequest, null); assertNotNull(actual); assertTrue(actual instanceof MultipartFile[]); MultipartFile[] parts = (MultipartFile[]) actual; assertEquals(2, parts.length); assertEquals(parts[0], multipartFile1); assertEquals(parts[1], multipartFile2); }
@Test public void loadContextHierarchy() { assertNotNull("child ApplicationContext", context); assertNull("parent ApplicationContext", context.getParent()); assertEquals("foo-level-1", foo); assertEquals("bar", bar); }
@Test public void ofEmptyOptional() { ResponseEntity<Integer> responseEntity = ResponseEntity.of(Optional.empty()); assertNotNull(responseEntity); assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertNull(responseEntity.getBody()); }
@Test public void loadContextHierarchy() { assertNotNull("child ApplicationContext", context); assertNull("parent ApplicationContext", context.getParent()); assertEquals("foo-level-1", foo); assertEquals("bar", bar); }
@Test public void convertFromStreamToRawList() throws NoSuchFieldException { Stream<Integer> stream = Arrays.asList(1, 2, 3).stream(); TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("rawList")); Object result = this.conversionService.convert(stream, listOfStrings); assertNotNull("Converted object must not be null", result); assertTrue("Converted object must be a list", result instanceof List); @SuppressWarnings("unchecked") List<Object> content = (List<Object>) result; assertEquals(1, content.get(0)); assertEquals(2, content.get(1)); assertEquals(3, content.get(2)); assertEquals("Wrong number of elements", 3, content.size()); }
private void testReturnValueHandlers(Object bean) { assertNotNull(bean); Object value = new DirectFieldAccessor(bean).getPropertyValue("customReturnValueHandlers"); assertNotNull(value); assertTrue(value instanceof List); @SuppressWarnings("unchecked") List<HandlerMethodReturnValueHandler> handlers = (List<HandlerMethodReturnValueHandler>) value; assertEquals(2, handlers.size()); assertEquals(TestHandlerMethodReturnValueHandler.class, handlers.get(0).getClass()); assertEquals(TestHandlerMethodReturnValueHandler.class, handlers.get(1).getClass()); assertNotSame(handlers.get(0), handlers.get(1)); }
@Test public void mergeMapWithInnerBeanAsMapEntryValue() throws Exception { TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefs"); Map map = bean.getSomeMap(); assertNotNull(map); assertEquals(2, map.size()); assertNotNull(map.get("Rob")); assertTrue(map.get("Rob") instanceof TestBean); assertEquals("Sally", ((TestBean) map.get("Rob")).getName()); }
@Test public void mergeMapWithInnerBeanAsMapEntryValueInConstructor() throws Exception { TestBean bean = (TestBean) this.beanFactory.getBean("childWithMapOfRefsInConstructor"); Map map = bean.getSomeMap(); assertNotNull(map); assertEquals(2, map.size()); assertNotNull(map.get("Rob")); assertTrue(map.get("Rob") instanceof TestBean); assertEquals("Sally", ((TestBean) map.get("Rob")).getName()); }
@Test public void testSunnyDaySetValue() throws Exception { CustomCollectionEditor editor = new CustomCollectionEditor(ArrayList.class); editor.setValue(new int[] {0, 1, 2}); Object value = editor.getValue(); assertNotNull(value); assertTrue(value instanceof ArrayList); List<?> list = (List<?>) value; assertEquals("There must be 3 elements in the converted collection", 3, list.size()); assertEquals(new Integer(0), list.get(0)); assertEquals(new Integer(1), list.get(1)); assertEquals(new Integer(2), list.get(2)); }
@Test public void resolveConfigAttributesWithMetaAnnotationAndLocations() { Class<MetaLocationsFoo> testClass = MetaLocationsFoo.class; List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass); assertNotNull(attributesList); assertEquals(1, attributesList.size()); assertAttributes(attributesList.get(0), testClass, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true); }
@Test public void resolveConfigAttributesWithLocalAnnotationAndLocations() { List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(LocationsFoo.class); assertNotNull(attributesList); assertEquals(1, attributesList.size()); assertLocationsFooAttributes(attributesList.get(0)); }
@Test public void resolveConfigAttributesWithMetaAnnotationAndLocationsAndOverrides() { Class<MetaLocationsFooWithOverrides> testClass = MetaLocationsFooWithOverrides.class; List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass); assertNotNull(attributesList); assertEquals(1, attributesList.size()); assertAttributes(attributesList.get(0), testClass, new String[] {"/foo.xml"}, EMPTY_CLASS_ARRAY, ContextLoader.class, true); }
@Test public void resolveConfigAttributesWithLocalAnnotationAndClasses() { List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(ClassesFoo.class); assertNotNull(attributesList); assertEquals(1, attributesList.size()); assertClassesFooAttributes(attributesList.get(0)); }
@Test @Override public void loadContextHierarchy() { assertNotNull("child ApplicationContext", context); assertNotNull("parent ApplicationContext", context.getParent()); assertNull("grandparent ApplicationContext", context.getParent().getParent()); assertEquals("parent", parent); assertEquals("parent + test user", user); assertEquals("from TestUserConfig", beanFromTestUserConfig); assertNull("Bean from UserConfig should not be present.", beanFromUserConfig); }
@Test public void resolveConfigAttributesWithBareAnnotations() { Class<BareAnnotations> testClass = BareAnnotations.class; List<ContextConfigurationAttributes> attributesList = resolveContextConfigurationAttributes(testClass); assertNotNull(attributesList); assertEquals(1, attributesList.size()); assertAttributes(attributesList.get(0), testClass, EMPTY_STRING_ARRAY, EMPTY_CLASS_ARRAY, ContextLoader.class, true); }