Polish
This commit is contained in:
parent
e1236a8672
commit
0c42965fc3
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -24,7 +24,7 @@ import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
|
|||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class SpellCheckServiceTests {
|
||||
class SpellCheckServiceTests {
|
||||
|
||||
// tag::hintspredicates[]
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -75,7 +75,7 @@ class AopNamespaceHandlerScopeIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testRequestScoping() throws Exception {
|
||||
void testRequestScoping() {
|
||||
MockHttpServletRequest oldRequest = new MockHttpServletRequest();
|
||||
MockHttpServletRequest newRequest = new MockHttpServletRequest();
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ class AopNamespaceHandlerScopeIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testSessionScoping() throws Exception {
|
||||
void testSessionScoping() {
|
||||
MockHttpSession oldSession = new MockHttpSession();
|
||||
MockHttpSession newSession = new MockHttpSession();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,7 +16,6 @@
|
|||
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -61,12 +60,12 @@ class AdvisorAutoProxyCreatorIntegrationTests {
|
|||
/**
|
||||
* Return a bean factory with attributes and EnterpriseServices configured.
|
||||
*/
|
||||
protected BeanFactory getBeanFactory() throws IOException {
|
||||
protected BeanFactory getBeanFactory() {
|
||||
return new ClassPathXmlApplicationContext(DEFAULT_CONTEXT, CLASS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultExclusionPrefix() throws Exception {
|
||||
void testDefaultExclusionPrefix() {
|
||||
DefaultAdvisorAutoProxyCreator aapc = (DefaultAdvisorAutoProxyCreator) getBeanFactory().getBean(ADVISOR_APC_BEAN_NAME);
|
||||
assertThat(aapc.getAdvisorBeanNamePrefix()).isEqualTo((ADVISOR_APC_BEAN_NAME + DefaultAdvisorAutoProxyCreator.SEPARATOR));
|
||||
assertThat(aapc.isUsePrefix()).isFalse();
|
||||
|
|
@ -76,21 +75,21 @@ class AdvisorAutoProxyCreatorIntegrationTests {
|
|||
* If no pointcuts match (no attrs) there should be proxying.
|
||||
*/
|
||||
@Test
|
||||
void testNoProxy() throws Exception {
|
||||
void testNoProxy() {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
Object o = bf.getBean("noSetters");
|
||||
assertThat(AopUtils.isAopProxy(o)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testTxIsProxied() throws Exception {
|
||||
void testTxIsProxied() {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
ITestBean test = (ITestBean) bf.getBean("test");
|
||||
assertThat(AopUtils.isAopProxy(test)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRegexpApplied() throws Exception {
|
||||
void testRegexpApplied() {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
ITestBean test = (ITestBean) bf.getBean("test");
|
||||
MethodCounter counter = (MethodCounter) bf.getBean("countingAdvice");
|
||||
|
|
@ -100,7 +99,7 @@ class AdvisorAutoProxyCreatorIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testTransactionAttributeOnMethod() throws Exception {
|
||||
void testTransactionAttributeOnMethod() {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
ITestBean test = (ITestBean) bf.getBean("test");
|
||||
|
||||
|
|
@ -166,7 +165,7 @@ class AdvisorAutoProxyCreatorIntegrationTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void testProgrammaticRollback() throws Exception {
|
||||
void testProgrammaticRollback() {
|
||||
BeanFactory bf = getBeanFactory();
|
||||
|
||||
Object bean = bf.getBean(TXMANAGER_BEAN_NAME);
|
||||
|
|
@ -250,7 +249,7 @@ class OrderedTxCheckAdvisor extends StaticMethodMatcherPointcutAdvisor implement
|
|||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterPropertiesSet() {
|
||||
setAdvice(new TxCountingBeforeAdvice());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -46,7 +46,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
* @author Brian Clozel
|
||||
*/
|
||||
@EnabledIfRuntimeHintsAgent
|
||||
public class RuntimeHintsAgentTests {
|
||||
class RuntimeHintsAgentTests {
|
||||
|
||||
private static final ClassLoader classLoader = ClassLoader.getSystemClassLoader();
|
||||
|
||||
|
|
@ -58,7 +58,7 @@ public class RuntimeHintsAgentTests {
|
|||
|
||||
|
||||
@BeforeAll
|
||||
public static void classSetup() throws NoSuchMethodException {
|
||||
static void classSetup() throws NoSuchMethodException {
|
||||
defaultConstructor = String.class.getConstructor();
|
||||
toStringMethod = String.class.getMethod("toString");
|
||||
privateGreetMethod = PrivateClass.class.getDeclaredMethod("greet");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -39,7 +39,7 @@ class ComponentBeanDefinitionParserTests {
|
|||
|
||||
|
||||
@BeforeAll
|
||||
void setUp() throws Exception {
|
||||
void setUp() {
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("component-config.xml", ComponentBeanDefinitionParserTests.class));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -34,7 +34,7 @@ public class ComponentFactoryBean implements FactoryBean<Component> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Component getObject() throws Exception {
|
||||
public Component getObject() {
|
||||
if (this.children != null && this.children.size() > 0) {
|
||||
for (Component child : children) {
|
||||
this.parent.addComponent(child);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -42,7 +42,6 @@ import static org.assertj.core.api.Assertions.assertThatException;
|
|||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
class EnableCachingIntegrationTests {
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -87,7 +87,6 @@ import static org.springframework.core.env.EnvironmentSystemIntegrationTests.Con
|
|||
* @author Sam Brannen
|
||||
* @see org.springframework.context.support.EnvironmentIntegrationTests
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public class EnvironmentSystemIntegrationTests {
|
||||
|
||||
private final ConfigurableEnvironment prodEnv = new StandardEnvironment();
|
||||
|
|
@ -618,7 +617,7 @@ public class EnvironmentSystemIntegrationTests {
|
|||
@Import({DevConfig.class, ProdConfig.class})
|
||||
static class Config {
|
||||
@Bean
|
||||
public EnvironmentAwareBean envAwareBean() {
|
||||
EnvironmentAwareBean envAwareBean() {
|
||||
return new EnvironmentAwareBean();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -51,7 +51,6 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
|||
* @author Juergen Hoeller
|
||||
* @since 3.1
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
class ScheduledAndTransactionalAnnotationIntegrationTests {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -54,7 +54,6 @@ import static org.assertj.core.api.Assertions.assertThatException;
|
|||
* @author Sam Brannen
|
||||
* @since 3.1
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
class EnableTransactionManagementIntegrationTests {
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -27,14 +27,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
/**
|
||||
* Tests proving that regardless the proxy strategy used (JDK interface-based vs. CGLIB
|
||||
* subclass-based), discovery of advice-oriented annotations is consistent.
|
||||
*
|
||||
* <p>
|
||||
* For example, Spring's @Transactional may be declared at the interface or class level,
|
||||
* and whether interface or subclass proxies are used, the @Transactional annotation must
|
||||
* be discovered in a consistent fashion.
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
class ProxyAnnotationDiscoveryTests {
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -354,8 +354,7 @@ class ProxyFactoryTests {
|
|||
list.add(proxy1);
|
||||
list.add(proxy2);
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list).element(0).isSameAs(proxy2);
|
||||
assertThat(list).element(1).isSameAs(proxy1);
|
||||
assertThat(list).containsExactly(proxy2, proxy1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -370,8 +369,7 @@ class ProxyFactoryTests {
|
|||
list.add(proxy1);
|
||||
list.add(proxy2);
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list).element(0).isSameAs(proxy2);
|
||||
assertThat(list).element(1).isSameAs(proxy1);
|
||||
assertThat(list).containsExactly(proxy2, proxy1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ class BeanWrapperAutoGrowingTests {
|
|||
|
||||
@Test
|
||||
void getPropertyValueAutoGrowArray() {
|
||||
assertNotNull(wrapper.getPropertyValue("array[0]"));
|
||||
assertThat(wrapper.getPropertyValue("array[0]")).isNotNull();
|
||||
assertThat(bean.getArray()).hasSize(1);
|
||||
assertThat(bean.getArray()[0]).isInstanceOf(Bean.class);
|
||||
}
|
||||
|
|
@ -75,17 +75,17 @@ class BeanWrapperAutoGrowingTests {
|
|||
|
||||
@Test
|
||||
void getPropertyValueAutoGrowArrayBySeveralElements() {
|
||||
assertNotNull(wrapper.getPropertyValue("array[4]"));
|
||||
assertThat(wrapper.getPropertyValue("array[4]")).isNotNull();
|
||||
assertThat(bean.getArray()).hasSize(5);
|
||||
assertThat(bean.getArray()[0]).isInstanceOf(Bean.class);
|
||||
assertThat(bean.getArray()[1]).isInstanceOf(Bean.class);
|
||||
assertThat(bean.getArray()[2]).isInstanceOf(Bean.class);
|
||||
assertThat(bean.getArray()[3]).isInstanceOf(Bean.class);
|
||||
assertThat(bean.getArray()[4]).isInstanceOf(Bean.class);
|
||||
assertNotNull(wrapper.getPropertyValue("array[0]"));
|
||||
assertNotNull(wrapper.getPropertyValue("array[1]"));
|
||||
assertNotNull(wrapper.getPropertyValue("array[2]"));
|
||||
assertNotNull(wrapper.getPropertyValue("array[3]"));
|
||||
assertThat(wrapper.getPropertyValue("array[0]")).isNotNull();
|
||||
assertThat(wrapper.getPropertyValue("array[1]")).isNotNull();
|
||||
assertThat(wrapper.getPropertyValue("array[2]")).isNotNull();
|
||||
assertThat(wrapper.getPropertyValue("array[3]")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -124,7 +124,7 @@ class BeanWrapperAutoGrowingTests {
|
|||
|
||||
@Test
|
||||
void getPropertyValueAutoGrowList() {
|
||||
assertNotNull(wrapper.getPropertyValue("list[0]"));
|
||||
assertThat(wrapper.getPropertyValue("list[0]")).isNotNull();
|
||||
assertThat(bean.getList()).hasSize(1);
|
||||
assertThat(bean.getList()).element(0).isInstanceOf(Bean.class);
|
||||
}
|
||||
|
|
@ -137,17 +137,13 @@ class BeanWrapperAutoGrowingTests {
|
|||
|
||||
@Test
|
||||
void getPropertyValueAutoGrowListBySeveralElements() {
|
||||
assertNotNull(wrapper.getPropertyValue("list[4]"));
|
||||
assertThat(bean.getList()).hasSize(5);
|
||||
assertThat(bean.getList()).element(0).isInstanceOf(Bean.class);
|
||||
assertThat(bean.getList()).element(1).isInstanceOf(Bean.class);
|
||||
assertThat(bean.getList()).element(2).isInstanceOf(Bean.class);
|
||||
assertThat(bean.getList()).element(3).isInstanceOf(Bean.class);
|
||||
assertThat(bean.getList()).element(4).isInstanceOf(Bean.class);
|
||||
assertNotNull(wrapper.getPropertyValue("list[0]"));
|
||||
assertNotNull(wrapper.getPropertyValue("list[1]"));
|
||||
assertNotNull(wrapper.getPropertyValue("list[2]"));
|
||||
assertNotNull(wrapper.getPropertyValue("list[3]"));
|
||||
assertThat(wrapper.getPropertyValue("list[4]")).isNotNull();
|
||||
assertThat(bean.getList()).hasSize(5).allSatisfy(entry ->
|
||||
assertThat(entry).isInstanceOf(Bean.class));
|
||||
assertThat(wrapper.getPropertyValue("list[0]")).isNotNull();
|
||||
assertThat(wrapper.getPropertyValue("list[1]")).isNotNull();
|
||||
assertThat(wrapper.getPropertyValue("list[2]")).isNotNull();
|
||||
assertThat(wrapper.getPropertyValue("list[3]")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -160,9 +156,9 @@ class BeanWrapperAutoGrowingTests {
|
|||
|
||||
@Test
|
||||
void getPropertyValueAutoGrowMultiDimensionalList() {
|
||||
assertNotNull(wrapper.getPropertyValue("multiList[0][0]"));
|
||||
assertThat(bean.getMultiList()).element(0).asList().hasSize(1);
|
||||
assertThat(bean.getMultiList().get(0)).element(0).isInstanceOf(Bean.class);
|
||||
assertThat(wrapper.getPropertyValue("multiList[0][0]")).isNotNull();
|
||||
assertThat(bean.getMultiList()).hasSize(1);
|
||||
assertThat(bean.getMultiList().get(0)).singleElement().isInstanceOf(Bean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -184,11 +180,6 @@ class BeanWrapperAutoGrowingTests {
|
|||
}
|
||||
|
||||
|
||||
private static void assertNotNull(Object propertyValue) {
|
||||
assertThat(propertyValue).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public static class Bean {
|
||||
|
||||
|
|
|
|||
|
|
@ -94,8 +94,8 @@ class BeanWrapperGenericsTests {
|
|||
input.add("http://localhost:8080");
|
||||
input.add("http://localhost:9090");
|
||||
bw.setPropertyValue("resourceList", input);
|
||||
assertThat(gb.getResourceList()).element(0).isEqualTo(new UrlResource("http://localhost:8080"));
|
||||
assertThat(gb.getResourceList()).element(1).isEqualTo(new UrlResource("http://localhost:9090"));
|
||||
assertThat(gb.getResourceList()).containsExactly(new UrlResource("http://localhost:8080"),
|
||||
new UrlResource("http://localhost:9090"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -104,7 +104,7 @@ class BeanWrapperGenericsTests {
|
|||
gb.setResourceList(new ArrayList<>());
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("resourceList[0]", "http://localhost:8080");
|
||||
assertThat(gb.getResourceList()).element(0).isEqualTo(new UrlResource("http://localhost:8080"));
|
||||
assertThat(gb.getResourceList()).containsExactly(new UrlResource("http://localhost:8080"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -655,9 +655,7 @@ class DefaultListableBeanFactoryTests {
|
|||
lbf.registerSingleton("string2", "B");
|
||||
|
||||
TestBean self = (TestBean) lbf.getBean("self");
|
||||
assertThat(self.getStringArray()).hasSize(2);
|
||||
assertThat(self.getStringArray()).contains("A");
|
||||
assertThat(self.getStringArray()).contains("B");
|
||||
assertThat(self.getStringArray()).containsOnly("A","B");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2237,10 +2235,10 @@ class DefaultListableBeanFactoryTests {
|
|||
|
||||
ObjectProvider<TestBean> testBeanProvider = lbf.getBeanProvider(ResolvableType.forClass(TestBean.class));
|
||||
List<TestBean> resolved = testBeanProvider.orderedStream().toList();
|
||||
assertThat(resolved.size()).isEqualTo(3);
|
||||
assertThat(resolved).element(0).isSameAs(lbf.getBean("highPriorityTestBean"));
|
||||
assertThat(resolved).element(1).isSameAs(lbf.getBean("lowPriorityTestBean"));
|
||||
assertThat(resolved).element(2).isSameAs(lbf.getBean("plainTestBean"));
|
||||
assertThat(resolved).containsExactly(
|
||||
lbf.getBean("highPriorityTestBean", TestBean.class),
|
||||
lbf.getBean("lowPriorityTestBean", TestBean.class),
|
||||
lbf.getBean("plainTestBean", TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ import org.springframework.util.Assert;
|
|||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
|
|
@ -583,15 +584,9 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
assertThat(bean.getTestBean3()).isSameAs(tb);
|
||||
assertThat(bean.getTestBean4()).isSameAs(tb);
|
||||
assertThat(bean.getIndexedTestBean()).isSameAs(itb);
|
||||
assertThat(bean.getNestedTestBeans()).hasSize(2);
|
||||
assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb1);
|
||||
assertThat(bean.getNestedTestBeans()).element(1).isSameAs(ntb2);
|
||||
assertThat(bean.nestedTestBeansSetter).hasSize(2);
|
||||
assertThat(bean.nestedTestBeansSetter).element(0).isSameAs(ntb1);
|
||||
assertThat(bean.nestedTestBeansSetter).element(1).isSameAs(ntb2);
|
||||
assertThat(bean.nestedTestBeansField).hasSize(2);
|
||||
assertThat(bean.nestedTestBeansField).element(0).isSameAs(ntb1);
|
||||
assertThat(bean.nestedTestBeansField).element(1).isSameAs(ntb2);
|
||||
assertThat(bean.getNestedTestBeans()).containsExactly(ntb1, ntb2);
|
||||
assertThat(bean.nestedTestBeansSetter).containsExactly(ntb1, ntb2);
|
||||
assertThat(bean.nestedTestBeansField).containsExactly(ntb1, ntb2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -614,12 +609,9 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
assertThat(bean.getTestBean3()).isSameAs(tb);
|
||||
assertThat(bean.getTestBean4()).isSameAs(tb);
|
||||
assertThat(bean.getIndexedTestBean()).isSameAs(itb);
|
||||
assertThat(bean.getNestedTestBeans()).hasSize(1);
|
||||
assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb1);
|
||||
assertThat(bean.nestedTestBeansSetter).hasSize(1);
|
||||
assertThat(bean.nestedTestBeansSetter).element(0).isSameAs(ntb1);
|
||||
assertThat(bean.nestedTestBeansField).hasSize(1);
|
||||
assertThat(bean.nestedTestBeansField).element(0).isSameAs(ntb1);
|
||||
assertThat(bean.getNestedTestBeans()).containsExactly(ntb1);
|
||||
assertThat(bean.nestedTestBeansSetter).containsExactly(ntb1);
|
||||
assertThat(bean.nestedTestBeansField).containsExactly(ntb1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1057,8 +1049,7 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
ConstructorsCollectionResourceInjectionBean bean = bf.getBean("annotatedBean", ConstructorsCollectionResourceInjectionBean.class);
|
||||
assertThat(bean.getTestBean3()).isNull();
|
||||
assertThat(bean.getTestBean4()).isSameAs(tb);
|
||||
assertThat(bean.getNestedTestBeans()).hasSize(1);
|
||||
assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb2);
|
||||
assertThat(bean.getNestedTestBeans()).containsExactly(ntb2);
|
||||
|
||||
Map<String, NestedTestBean> map = bf.getBeansOfType(NestedTestBean.class);
|
||||
assertThat(map.get("nestedTestBean1")).isNull();
|
||||
|
|
@ -1079,9 +1070,7 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
ConstructorsCollectionResourceInjectionBean bean = bf.getBean("annotatedBean", ConstructorsCollectionResourceInjectionBean.class);
|
||||
assertThat(bean.getTestBean3()).isNull();
|
||||
assertThat(bean.getTestBean4()).isSameAs(tb);
|
||||
assertThat(bean.getNestedTestBeans()).hasSize(2);
|
||||
assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb1);
|
||||
assertThat(bean.getNestedTestBeans()).element(1).isSameAs(ntb2);
|
||||
assertThat(bean.getNestedTestBeans()).contains(ntb1, ntb2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1515,8 +1504,7 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
SelfInjectionCollectionBean bean = bf.getBean("annotatedBean", SelfInjectionCollectionBean.class);
|
||||
SelfInjectionCollectionBean bean2 = bf.getBean("annotatedBean2", SelfInjectionCollectionBean.class);
|
||||
assertThat(bean.reference).isSameAs(bean2);
|
||||
assertThat(bean2.referenceCollection).hasSize(1);
|
||||
assertThat(bean.referenceCollection).element(0).isSameAs(bean2);
|
||||
assertThat(bean2.referenceCollection).containsExactly(bean2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1682,22 +1670,12 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
assertThat(bean.getUniqueTestBean()).isNull();
|
||||
assertThat(bean.consumeUniqueTestBean()).isNull();
|
||||
|
||||
List<?> testBeans = bean.iterateTestBeans();
|
||||
assertThat(testBeans).hasSize(2);
|
||||
assertThat(testBeans).element(0).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(testBeans).element(1).isSameAs(bf.getBean("testBean2"));
|
||||
testBeans = bean.forEachTestBeans();
|
||||
assertThat(testBeans).hasSize(2);
|
||||
assertThat(testBeans).element(0).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(testBeans).element(1).isSameAs(bf.getBean("testBean2"));
|
||||
testBeans = bean.streamTestBeans();
|
||||
assertThat(testBeans).hasSize(2);
|
||||
assertThat(testBeans).element(0).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(testBeans).element(1).isSameAs(bf.getBean("testBean2"));
|
||||
testBeans = bean.sortedTestBeans();
|
||||
assertThat(testBeans).hasSize(2);
|
||||
assertThat(testBeans).element(0).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(testBeans).element(1).isSameAs(bf.getBean("testBean2"));
|
||||
TestBean testBean1 = bf.getBean("testBean1", TestBean.class);
|
||||
TestBean testBean2 = bf.getBean("testBean2", TestBean.class);
|
||||
assertThat(bean.iterateTestBeans()).containsExactly(testBean1, testBean2);
|
||||
assertThat(bean.forEachTestBeans()).containsExactly(testBean1, testBean2);
|
||||
assertThat(bean.streamTestBeans()).containsExactly(testBean1, testBean2);
|
||||
assertThat(bean.sortedTestBeans()).containsExactly(testBean1, testBean2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1713,29 +1691,19 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
bf.registerBeanDefinition("testBean2", tb2);
|
||||
|
||||
ObjectProviderInjectionBean bean = bf.getBean("annotatedBean", ObjectProviderInjectionBean.class);
|
||||
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(bean.getOptionalTestBean()).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(bean.consumeOptionalTestBean()).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(bean.getUniqueTestBean()).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(bean.consumeUniqueTestBean()).isSameAs(bf.getBean("testBean1"));
|
||||
TestBean testBean1 = bf.getBean("testBean1", TestBean.class);
|
||||
assertThat(bean.getTestBean()).isSameAs(testBean1);
|
||||
assertThat(bean.getOptionalTestBean()).isSameAs(testBean1);
|
||||
assertThat(bean.consumeOptionalTestBean()).isSameAs(testBean1);
|
||||
assertThat(bean.getUniqueTestBean()).isSameAs(testBean1);
|
||||
assertThat(bean.consumeUniqueTestBean()).isSameAs(testBean1);
|
||||
assertThat(bf.containsSingleton("testBean2")).isFalse();
|
||||
|
||||
List<?> testBeans = bean.iterateTestBeans();
|
||||
assertThat(testBeans).hasSize(2);
|
||||
assertThat(testBeans).element(0).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(testBeans).element(1).isSameAs(bf.getBean("testBean2"));
|
||||
testBeans = bean.forEachTestBeans();
|
||||
assertThat(testBeans).hasSize(2);
|
||||
assertThat(testBeans).element(0).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(testBeans).element(1).isSameAs(bf.getBean("testBean2"));
|
||||
testBeans = bean.streamTestBeans();
|
||||
assertThat(testBeans).hasSize(2);
|
||||
assertThat(testBeans).element(0).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(testBeans).element(1).isSameAs(bf.getBean("testBean2"));
|
||||
testBeans = bean.sortedTestBeans();
|
||||
assertThat(testBeans).hasSize(2);
|
||||
assertThat(testBeans).element(0).isSameAs(bf.getBean("testBean2"));
|
||||
assertThat(testBeans).element(1).isSameAs(bf.getBean("testBean1"));
|
||||
TestBean testBean2 = bf.getBean("testBean2", TestBean.class);
|
||||
assertThat(bean.iterateTestBeans()).containsExactly(testBean1, testBean2);
|
||||
assertThat(bean.forEachTestBeans()).containsExactly(testBean1, testBean2);
|
||||
assertThat(bean.streamTestBeans()).containsExactly(testBean1, testBean2);
|
||||
assertThat(bean.sortedTestBeans()).containsExactly(testBean2, testBean1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -1751,10 +1719,8 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
bf.registerBeanDefinition("testBean2", tb2);
|
||||
|
||||
ObjectProviderInjectionBean bean = bf.getBean("annotatedBean", ObjectProviderInjectionBean.class);
|
||||
List<?> testBeans = bean.sortedTestBeans();
|
||||
assertThat(testBeans).hasSize(2);
|
||||
assertThat(testBeans).element(0).isSameAs(bf.getBean("testBean2"));
|
||||
assertThat(testBeans).element(1).isSameAs(bf.getBean("testBean1"));
|
||||
assertThat(bean.sortedTestBeans()).containsExactly(bf.getBean("testBean2", TestBean.class),
|
||||
bf.getBean("testBean1", TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2094,18 +2060,12 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
Repository<?> ir = bf.getBean("integerRepository", Repository.class);
|
||||
assertThat(bean.stringRepository).isSameAs(sr);
|
||||
assertThat(bean.integerRepository).isSameAs(ir);
|
||||
assertThat(bean.stringRepositoryArray).hasSize(1);
|
||||
assertThat(bean.integerRepositoryArray).hasSize(1);
|
||||
assertThat(bean.stringRepositoryArray[0]).isSameAs(sr);
|
||||
assertThat(bean.integerRepositoryArray[0]).isSameAs(ir);
|
||||
assertThat(bean.stringRepositoryList).hasSize(1);
|
||||
assertThat(bean.integerRepositoryList).hasSize(1);
|
||||
assertThat(bean.stringRepositoryList).element(0).isSameAs(sr);
|
||||
assertThat(bean.integerRepositoryList).element(0).isSameAs(ir);
|
||||
assertThat(bean.stringRepositoryMap).hasSize(1);
|
||||
assertThat(bean.integerRepositoryMap).hasSize(1);
|
||||
assertThat(bean.stringRepositoryMap.get("stringRepo")).isSameAs(sr);
|
||||
assertThat(bean.integerRepositoryMap.get("integerRepository")).isSameAs(ir);
|
||||
assertThat(bean.stringRepositoryArray).singleElement().isSameAs(sr);
|
||||
assertThat(bean.integerRepositoryArray).singleElement().isSameAs(ir);
|
||||
assertThat(bean.stringRepositoryList).singleElement().isSameAs(sr);
|
||||
assertThat(bean.integerRepositoryList).singleElement().isSameAs(ir);
|
||||
assertThat(bean.stringRepositoryMap).containsOnly(entry("stringRepo", sr));
|
||||
assertThat(bean.integerRepositoryMap).containsOnly(entry("integerRepository", ir));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -2121,16 +2081,14 @@ class AutowiredAnnotationBeanPostProcessorTests {
|
|||
Repository<?> repo = bf.getBean("repo", Repository.class);
|
||||
assertThat(bean.repository).isSameAs(repo);
|
||||
assertThat(bean.stringRepository).isSameAs(repo);
|
||||
assertThat(bean.repositoryArray).hasSize(1);
|
||||
assertThat(bean.repositoryArray).containsExactly(repo);
|
||||
assertThat(bean.stringRepositoryArray).hasSize(1);
|
||||
assertThat(bean.repositoryArray[0]).isSameAs(repo);
|
||||
assertThat(bean.stringRepositoryArray[0]).isSameAs(repo);
|
||||
assertThat(bean.repositoryList).containsExactly(repo);
|
||||
assertThat(bean.stringRepositoryList).hasSize(1);
|
||||
assertThat(bean.stringRepositoryList).element(0).isSameAs(repo);
|
||||
assertThat(bean.repositoryMap).hasSize(1);
|
||||
assertThat(bean.repositoryMap).containsOnly(entry("repo", repo));
|
||||
assertThat(bean.stringRepositoryMap).hasSize(1);
|
||||
assertThat(bean.repositoryMap.get("repo")).isSameAs(repo);
|
||||
assertThat(bean.stringRepositoryMap.get("repo")).isSameAs(repo);
|
||||
|
||||
assertThat(bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class))).isEqualTo(new String[] {"repo"});
|
||||
|
|
|
|||
|
|
@ -195,9 +195,7 @@ class InjectAnnotationBeanPostProcessorTests {
|
|||
ConstructorsCollectionResourceInjectionBean bean = (ConstructorsCollectionResourceInjectionBean) bf.getBean("annotatedBean");
|
||||
assertThat(bean.getTestBean3()).isNull();
|
||||
assertThat(bean.getTestBean4()).isSameAs(tb);
|
||||
assertThat(bean.getNestedTestBeans()).hasSize(2);
|
||||
assertThat(bean.getNestedTestBeans()).element(0).isSameAs(ntb1);
|
||||
assertThat(bean.getNestedTestBeans()).element(1).isSameAs(ntb2);
|
||||
assertThat(bean.getNestedTestBeans()).containsExactly(ntb1, ntb2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -530,8 +528,8 @@ class InjectAnnotationBeanPostProcessorTests {
|
|||
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
|
||||
|
||||
OptionalListFieldInjectionBean bean = (OptionalListFieldInjectionBean) bf.getBean("annotatedBean");
|
||||
assertThat(bean.getTestBean()).isPresent();
|
||||
assertThat(bean.getTestBean().get()).element(0).isSameAs(bf.getBean("testBean"));
|
||||
assertThat(bean.getTestBean()).hasValueSatisfying(list ->
|
||||
assertThat(list).containsExactly(bf.getBean("testBean", TestBean.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -548,8 +546,8 @@ class InjectAnnotationBeanPostProcessorTests {
|
|||
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
|
||||
|
||||
OptionalListMethodInjectionBean bean = (OptionalListMethodInjectionBean) bf.getBean("annotatedBean");
|
||||
assertThat(bean.getTestBean()).isPresent();
|
||||
assertThat(bean.getTestBean().get()).element(0).isSameAs(bf.getBean("testBean"));
|
||||
assertThat(bean.getTestBean()).hasValueSatisfying(list ->
|
||||
assertThat(list).containsExactly(bf.getBean("testBean", TestBean.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -115,7 +115,7 @@ class AotServicesTests {
|
|||
AotServices<?> loaded = AotServices
|
||||
.factories(new TestSpringFactoriesClassLoader("aot-services.factories"))
|
||||
.load(TestService.class);
|
||||
assertThat(loaded).element(0).isInstanceOf(TestServiceImpl.class);
|
||||
assertThat(loaded).singleElement().isInstanceOf(TestServiceImpl.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@ import java.util.ArrayList;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Predicate;
|
||||
|
|
@ -29,6 +28,7 @@ import java.util.function.Supplier;
|
|||
|
||||
import javax.lang.model.element.Modifier;
|
||||
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
|
@ -260,11 +260,11 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
|
|||
compile((actual, compiled) -> {
|
||||
ConstructorArgumentValues argumentValues = actual.getConstructorArgumentValues();
|
||||
List<ValueHolder> values = argumentValues.getGenericArgumentValues();
|
||||
assertThat(values).element(0).satisfies(assertValueHolder(String.class, null, null));
|
||||
assertThat(values).element(1).satisfies(assertValueHolder(2, Long.class, null));
|
||||
assertThat(values).element(2).satisfies(assertValueHolder("value", null, "param1"));
|
||||
assertThat(values).element(3).satisfies(assertValueHolder("another", CharSequence.class, "param2"));
|
||||
assertThat(values).hasSize(4);
|
||||
assertThat(values).satisfiesExactly(
|
||||
assertValueHolder(String.class, null, null),
|
||||
assertValueHolder(2, Long.class, null),
|
||||
assertValueHolder("value", null, "param1"),
|
||||
assertValueHolder("another", CharSequence.class, "param2"));
|
||||
assertThat(argumentValues.getIndexedArgumentValues()).isEmpty();
|
||||
});
|
||||
}
|
||||
|
|
@ -324,8 +324,8 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
|
|||
this.beanDefinition.getPropertyValues().add("value", managedList);
|
||||
compile((actual, compiled) -> {
|
||||
Object value = actual.getPropertyValues().get("value");
|
||||
assertThat(value).isInstanceOf(ManagedList.class);
|
||||
assertThat(((List<?>) value)).element(0).isInstanceOf(BeanReference.class);
|
||||
assertThat(value).isInstanceOf(ManagedList.class).asInstanceOf(InstanceOfAssertFactories.LIST)
|
||||
.singleElement().isInstanceOf(BeanReference.class);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -336,8 +336,9 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
|
|||
this.beanDefinition.getPropertyValues().add("value", managedSet);
|
||||
compile((actual, compiled) -> {
|
||||
Object value = actual.getPropertyValues().get("value");
|
||||
assertThat(value).isInstanceOf(ManagedSet.class);
|
||||
assertThat(((Set<?>) value)).element(0).isInstanceOf(BeanReference.class);
|
||||
assertThat(value).isInstanceOf(ManagedSet.class)
|
||||
.asInstanceOf(InstanceOfAssertFactories.COLLECTION)
|
||||
.singleElement().isInstanceOf(BeanReference.class);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -348,8 +349,9 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
|
|||
this.beanDefinition.getPropertyValues().add("value", managedMap);
|
||||
compile((actual, compiled) -> {
|
||||
Object value = actual.getPropertyValues().get("value");
|
||||
assertThat(value).isInstanceOf(ManagedMap.class);
|
||||
assertThat(((Map<?, ?>) value).get("test")).isInstanceOf(BeanReference.class);
|
||||
assertThat(value).isInstanceOf(ManagedMap.class)
|
||||
.asInstanceOf(InstanceOfAssertFactories.map(String.class, Object.class))
|
||||
.hasEntrySatisfying("test", ref -> assertThat(ref).isInstanceOf(BeanReference.class));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -429,9 +431,8 @@ class BeanDefinitionPropertiesCodeGeneratorTests {
|
|||
this.beanDefinition.addQualifier(new AutowireCandidateQualifier("com.example.Another", ChronoUnit.SECONDS));
|
||||
compile((actual, compiled) -> {
|
||||
List<AutowireCandidateQualifier> qualifiers = new ArrayList<>(actual.getQualifiers());
|
||||
assertThat(qualifiers).element(0).satisfies(isQualifierFor("com.example.Qualifier", "id"));
|
||||
assertThat(qualifiers).element(1).satisfies(isQualifierFor("com.example.Another", ChronoUnit.SECONDS));
|
||||
assertThat(qualifiers).hasSize(2);
|
||||
assertThat(qualifiers).satisfiesExactly(isQualifierFor("com.example.Qualifier", "id"),
|
||||
isQualifierFor("com.example.Another", ChronoUnit.SECONDS));
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -400,12 +400,11 @@ class PropertyResourceConfigurerTests {
|
|||
assertThat(tb1.getSpouse()).isEqualTo(tb2);
|
||||
assertThat(tb1.getSomeMap()).hasSize(1);
|
||||
assertThat(tb1.getSomeMap().get("myKey")).isEqualTo("myValue");
|
||||
assertThat(tb2.getStringArray()).hasSize(2);
|
||||
assertThat(tb2.getStringArray()[0]).isEqualTo(System.getProperty("os.name"));
|
||||
assertThat(tb2.getStringArray()[1]).isEqualTo("98");
|
||||
assertThat(tb2.getFriends()).hasSize(2);
|
||||
assertThat(tb2.getFriends()).element(0).isEqualTo("na98me");
|
||||
assertThat(tb2.getFriends().toArray()[1]).isEqualTo(tb2);
|
||||
assertThat(tb2.getStringArray()).containsExactly(System.getProperty("os.name"), "98");
|
||||
assertThat(tb2.getFriends()).satisfiesExactly(
|
||||
zero -> assertThat(zero).isInstanceOfSatisfying(
|
||||
String.class, value -> assertThat(value).isEqualTo("na98me")),
|
||||
one -> assertThat(one).isEqualTo(tb2));
|
||||
assertThat(tb2.getSomeSet()).hasSize(3);
|
||||
assertThat(tb2.getSomeSet().contains("na98me")).isTrue();
|
||||
assertThat(tb2.getSomeSet().contains(tb2)).isTrue();
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
|
@ -573,9 +572,10 @@ class BeanFactoryGenericsTests {
|
|||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
GenericSetOfIntegerBean gb = (GenericSetOfIntegerBean) bf.getBean("setOfIntegerBean");
|
||||
assertThat(gb.getGenericProperty()).element(0).isEqualTo(10);
|
||||
assertThat(gb.getGenericListProperty().get(0)).containsExactly(20);
|
||||
assertThat(gb.getGenericListProperty().get(1)).containsExactly(30);
|
||||
assertThat(gb.getGenericProperty()).singleElement().isEqualTo(10);
|
||||
assertThat(gb.getGenericListProperty()).satisfiesExactly(
|
||||
zero -> assertThat(zero).containsExactly(20),
|
||||
first -> assertThat(first).containsExactly(30));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -782,8 +782,10 @@ class BeanFactoryGenericsTests {
|
|||
new RootBeanDefinition(NumberBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR, false));
|
||||
|
||||
NumberBean nb = bf.getBean(NumberBean.class);
|
||||
assertThat(nb.getDoubleStore()).isSameAs(bf.getBean("store1"));
|
||||
assertThat(nb.getFloatStore()).isSameAs(bf.getBean("store2"));
|
||||
NumberStore<?> store1 = bf.getBean("store1", NumberStore.class);
|
||||
assertThat(nb.getDoubleStore()).isSameAs(store1);
|
||||
NumberStore<?> store2 = bf.getBean("store2", NumberStore.class);
|
||||
assertThat(nb.getFloatStore()).isSameAs(store2);
|
||||
|
||||
String[] numberStoreNames = bf.getBeanNamesForType(ResolvableType.forClass(NumberStore.class));
|
||||
String[] doubleStoreNames = bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(NumberStore.class, Double.class));
|
||||
|
|
@ -798,54 +800,36 @@ class BeanFactoryGenericsTests {
|
|||
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class).isThrownBy(numberStoreProvider::getObject);
|
||||
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class).isThrownBy(numberStoreProvider::getIfAvailable);
|
||||
assertThat(numberStoreProvider.getIfUnique()).isNull();
|
||||
assertThat(doubleStoreProvider.getObject()).isSameAs(bf.getBean("store1"));
|
||||
assertThat(doubleStoreProvider.getIfAvailable()).isSameAs(bf.getBean("store1"));
|
||||
assertThat(doubleStoreProvider.getIfUnique()).isSameAs(bf.getBean("store1"));
|
||||
assertThat(floatStoreProvider.getObject()).isSameAs(bf.getBean("store2"));
|
||||
assertThat(floatStoreProvider.getIfAvailable()).isSameAs(bf.getBean("store2"));
|
||||
assertThat(floatStoreProvider.getIfUnique()).isSameAs(bf.getBean("store2"));
|
||||
assertThat(doubleStoreProvider.getObject()).isSameAs(store1);
|
||||
assertThat(doubleStoreProvider.getIfAvailable()).isSameAs(store1);
|
||||
assertThat(doubleStoreProvider.getIfUnique()).isSameAs(store1);
|
||||
assertThat(floatStoreProvider.getObject()).isSameAs(store2);
|
||||
assertThat(floatStoreProvider.getIfAvailable()).isSameAs(store2);
|
||||
assertThat(floatStoreProvider.getIfUnique()).isSameAs(store2);
|
||||
|
||||
List<NumberStore<?>> resolved = new ArrayList<>();
|
||||
for (NumberStore<?> instance : numberStoreProvider) {
|
||||
resolved.add(instance);
|
||||
}
|
||||
assertThat(resolved).hasSize(2);
|
||||
assertThat(resolved).element(0).isSameAs(bf.getBean("store1"));
|
||||
assertThat(resolved).element(1).isSameAs(bf.getBean("store2"));
|
||||
|
||||
resolved = numberStoreProvider.stream().toList();
|
||||
assertThat(resolved).hasSize(2);
|
||||
assertThat(resolved).element(0).isSameAs(bf.getBean("store1"));
|
||||
assertThat(resolved).element(1).isSameAs(bf.getBean("store2"));
|
||||
|
||||
resolved = numberStoreProvider.orderedStream().toList();
|
||||
assertThat(resolved).hasSize(2);
|
||||
assertThat(resolved).element(0).isSameAs(bf.getBean("store2"));
|
||||
assertThat(resolved).element(1).isSameAs(bf.getBean("store1"));
|
||||
assertThat(resolved).containsExactly(store1, store2);
|
||||
assertThat(numberStoreProvider.stream()).containsExactly(store1, store2);
|
||||
assertThat(numberStoreProvider.orderedStream()).containsExactly(store2, store1);
|
||||
|
||||
resolved = new ArrayList<>();
|
||||
for (NumberStore<Double> instance : doubleStoreProvider) {
|
||||
resolved.add(instance);
|
||||
}
|
||||
assertThat(resolved).containsExactly(bf.getBean("store1", NumberStore.class));
|
||||
|
||||
resolved = doubleStoreProvider.stream().collect(Collectors.toList());
|
||||
assertThat(resolved).containsExactly(bf.getBean("store1", NumberStore.class));
|
||||
|
||||
resolved = doubleStoreProvider.orderedStream().collect(Collectors.toList());
|
||||
assertThat(resolved).containsExactly(bf.getBean("store1", NumberStore.class));
|
||||
assertThat(resolved).containsExactly(store1);
|
||||
assertThat(doubleStoreProvider.stream()).singleElement().isEqualTo(store1);
|
||||
assertThat(doubleStoreProvider.orderedStream()).singleElement().isEqualTo(store1);
|
||||
|
||||
resolved = new ArrayList<>();
|
||||
for (NumberStore<Float> instance : floatStoreProvider) {
|
||||
resolved.add(instance);
|
||||
}
|
||||
assertThat(resolved).containsExactly(bf.getBean("store2", NumberStore.class));
|
||||
|
||||
resolved = floatStoreProvider.stream().collect(Collectors.toList());
|
||||
assertThat(resolved).containsExactly(bf.getBean("store2", NumberStore.class));
|
||||
|
||||
resolved = floatStoreProvider.orderedStream().collect(Collectors.toList());
|
||||
assertThat(resolved).containsExactly(bf.getBean("store2", NumberStore.class));
|
||||
assertThat(resolved).containsExactly(store2);
|
||||
assertThat(floatStoreProvider.stream()).singleElement().isEqualTo(store2);
|
||||
assertThat(floatStoreProvider.orderedStream()).singleElement().isEqualTo(store2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -862,10 +846,8 @@ class BeanFactoryGenericsTests {
|
|||
bf.registerBeanDefinition("store2", bd2);
|
||||
|
||||
ObjectProvider<NumberStore<?>> numberStoreProvider = bf.getBeanProvider(ResolvableType.forClass(NumberStore.class));
|
||||
List<NumberStore<?>> resolved = numberStoreProvider.orderedStream().toList();
|
||||
assertThat(resolved).hasSize(2);
|
||||
assertThat(resolved).element(0).isSameAs(bf.getBean("store2"));
|
||||
assertThat(resolved).element(1).isSameAs(bf.getBean("store1"));
|
||||
assertThat(numberStoreProvider.orderedStream()).containsExactly(
|
||||
bf.getBean("store2", NumberStore.class), bf.getBean("store1", NumberStore.class));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -131,10 +131,7 @@ class CollectionMergingTests {
|
|||
void mergeListWithInnerBeanAsListElementInConstructor() {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("childWithListOfRefsInConstructor");
|
||||
List<?> list = bean.getSomeList();
|
||||
assertThat(list).isNotNull();
|
||||
assertThat(list).hasSize(3);
|
||||
assertThat(list).element(2).isNotNull();
|
||||
assertThat(list.get(2)).isInstanceOf(TestBean.class);
|
||||
assertThat(list).hasSize(3).element(2).isInstanceOf(TestBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -59,7 +59,6 @@ class EventPublicationTests {
|
|||
@Test
|
||||
void defaultsEventReceived() {
|
||||
List<DefaultsDefinition> defaultsList = this.eventListener.getDefaults();
|
||||
assertThat(defaultsList).isNotEmpty();
|
||||
assertThat(defaultsList).element(0).isInstanceOf(DocumentDefaultsDefinition.class);
|
||||
DocumentDefaultsDefinition defaults = (DocumentDefaultsDefinition) defaultsList.get(0);
|
||||
assertThat(defaults.getLazyInit()).isEqualTo("true");
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import java.util.Properties;
|
|||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -125,36 +126,41 @@ class UtilNamespaceHandlerTests {
|
|||
|
||||
@Test
|
||||
void testSimpleList() {
|
||||
List<?> list = (List) this.beanFactory.getBean("simpleList");
|
||||
assertThat(list).element(0).isEqualTo("Rob Harrop");
|
||||
List<?> list2 = (List) this.beanFactory.getBean("simpleList");
|
||||
assertThat(list).isSameAs(list2);
|
||||
assertThat(this.beanFactory.getBean("simpleList"))
|
||||
.asInstanceOf(InstanceOfAssertFactories.LIST).element(0).isEqualTo("Rob Harrop");
|
||||
assertThat(this.beanFactory.getBean("simpleList"))
|
||||
.isSameAs(this.beanFactory.getBean("simpleList"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testScopedList() {
|
||||
List<?> list = (List) this.beanFactory.getBean("scopedList");
|
||||
assertThat(list).element(0).isEqualTo("Rob Harrop");
|
||||
List<?> list2 = (List) this.beanFactory.getBean("scopedList");
|
||||
assertThat(list2).element(0).isEqualTo("Rob Harrop");
|
||||
assertThat(list).isNotSameAs(list2);
|
||||
assertThat(this.beanFactory.getBean("scopedList"))
|
||||
.asInstanceOf(InstanceOfAssertFactories.LIST).element(0).isEqualTo("Rob Harrop");
|
||||
assertThat(this.beanFactory.getBean("scopedList"))
|
||||
.asInstanceOf(InstanceOfAssertFactories.LIST).element(0).isEqualTo("Rob Harrop");
|
||||
assertThat(this.beanFactory.getBean("scopedList"))
|
||||
.isNotSameAs(this.beanFactory.getBean("scopedList"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSimpleSet() {
|
||||
Set<?> set = (Set) this.beanFactory.getBean("simpleSet");
|
||||
assertThat(set.contains("Rob Harrop")).isTrue();
|
||||
Set<?> set2 = (Set) this.beanFactory.getBean("simpleSet");
|
||||
assertThat(set).isSameAs(set2);
|
||||
assertThat(this.beanFactory.getBean("simpleSet")).isInstanceOf(Set.class)
|
||||
.asInstanceOf(InstanceOfAssertFactories.collection(String.class))
|
||||
.containsOnly("Rob Harrop");
|
||||
assertThat(this.beanFactory.getBean("simpleSet"))
|
||||
.isSameAs(this.beanFactory.getBean("simpleSet"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testScopedSet() {
|
||||
Set<?> set = (Set) this.beanFactory.getBean("scopedSet");
|
||||
assertThat(set.contains("Rob Harrop")).isTrue();
|
||||
Set<?> set2 = (Set) this.beanFactory.getBean("scopedSet");
|
||||
assertThat(set2.contains("Rob Harrop")).isTrue();
|
||||
assertThat(set).isNotSameAs(set2);
|
||||
assertThat(this.beanFactory.getBean("scopedSet")).isInstanceOf(Set.class)
|
||||
.asInstanceOf(InstanceOfAssertFactories.collection(String.class))
|
||||
.containsOnly("Rob Harrop");
|
||||
assertThat(this.beanFactory.getBean("scopedSet")).isInstanceOf(Set.class)
|
||||
.asInstanceOf(InstanceOfAssertFactories.collection(String.class))
|
||||
.containsOnly("Rob Harrop");
|
||||
assertThat(this.beanFactory.getBean("scopedSet"))
|
||||
.isNotSameAs(this.beanFactory.getBean("scopedSet"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -175,95 +181,71 @@ class UtilNamespaceHandlerTests {
|
|||
void testNestedCollections() {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("nestedCollectionsBean");
|
||||
|
||||
List<?> list = bean.getSomeList();
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list).element(0).isEqualTo("foo");
|
||||
|
||||
Set<?> set = bean.getSomeSet();
|
||||
assertThat(set).hasSize(1);
|
||||
assertThat(set.contains("bar")).isTrue();
|
||||
|
||||
Map<?, ?> map = bean.getSomeMap();
|
||||
assertThat(map).hasSize(1);
|
||||
assertThat(map.get("foo")).isInstanceOf(Set.class);
|
||||
Set<?> innerSet = (Set) map.get("foo");
|
||||
assertThat(innerSet).hasSize(1);
|
||||
assertThat(innerSet.contains("bar")).isTrue();
|
||||
assertThat(bean.getSomeList()).singleElement().isEqualTo("foo");
|
||||
assertThat(bean.getSomeSet()).singleElement().isEqualTo("bar");
|
||||
assertThat(bean.getSomeMap()).hasSize(1).allSatisfy((key, nested) -> {
|
||||
assertThat(key).isEqualTo("foo");
|
||||
assertThat(nested).isInstanceOf(Set.class).asInstanceOf(
|
||||
InstanceOfAssertFactories.collection(String.class)).containsOnly("bar");
|
||||
});
|
||||
|
||||
TestBean bean2 = (TestBean) this.beanFactory.getBean("nestedCollectionsBean");
|
||||
assertThat(bean2.getSomeList()).isEqualTo(list);
|
||||
assertThat(bean2.getSomeSet()).isEqualTo(set);
|
||||
assertThat(bean2.getSomeMap()).isEqualTo(map);
|
||||
assertThat(list).isNotSameAs(bean2.getSomeList());
|
||||
assertThat(set).isNotSameAs(bean2.getSomeSet());
|
||||
assertThat(map).isNotSameAs(bean2.getSomeMap());
|
||||
assertThat(bean2.getSomeList()).isEqualTo(bean.getSomeList());
|
||||
assertThat(bean2.getSomeSet()).isEqualTo(bean.getSomeSet());
|
||||
assertThat(bean2.getSomeMap()).isEqualTo(bean.getSomeMap());
|
||||
assertThat(bean.getSomeList()).isNotSameAs(bean2.getSomeList());
|
||||
assertThat(bean.getSomeSet()).isNotSameAs(bean2.getSomeSet());
|
||||
assertThat(bean.getSomeMap()).isNotSameAs(bean2.getSomeMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNestedShortcutCollections() {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("nestedShortcutCollections");
|
||||
|
||||
assertThat(bean.getStringArray()).hasSize(1);
|
||||
assertThat(bean.getStringArray()[0]).isEqualTo("fooStr");
|
||||
|
||||
List<?> list = bean.getSomeList();
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list).element(0).isEqualTo("foo");
|
||||
|
||||
Set<?> set = bean.getSomeSet();
|
||||
assertThat(set).hasSize(1);
|
||||
assertThat(set.contains("bar")).isTrue();
|
||||
assertThat(bean.getStringArray()).containsExactly("fooStr");
|
||||
assertThat(bean.getSomeList()).singleElement().isEqualTo("foo");
|
||||
assertThat(bean.getSomeSet()).singleElement().isEqualTo("bar");
|
||||
|
||||
TestBean bean2 = (TestBean) this.beanFactory.getBean("nestedShortcutCollections");
|
||||
assertThat(Arrays.equals(bean.getStringArray(), bean2.getStringArray())).isTrue();
|
||||
assertThat(bean.getStringArray()).isNotSameAs(bean2.getStringArray());
|
||||
assertThat(bean2.getSomeList()).isEqualTo(list);
|
||||
assertThat(bean2.getSomeSet()).isEqualTo(set);
|
||||
assertThat(list).isNotSameAs(bean2.getSomeList());
|
||||
assertThat(set).isNotSameAs(bean2.getSomeSet());
|
||||
assertThat(bean2.getSomeList()).isEqualTo(bean.getSomeList());
|
||||
assertThat(bean2.getSomeSet()).isEqualTo(bean.getSomeSet());
|
||||
assertThat(bean.getSomeList()).isNotSameAs(bean2.getSomeList());
|
||||
assertThat(bean.getSomeSet()).isNotSameAs(bean2.getSomeSet());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNestedInCollections() {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("nestedCustomTagBean");
|
||||
|
||||
List<?> list = bean.getSomeList();
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list).element(0).isEqualTo(Integer.MIN_VALUE);
|
||||
|
||||
Set<?> set = bean.getSomeSet();
|
||||
assertThat(set).hasSize(2);
|
||||
assertThat(set.contains(Thread.State.NEW)).isTrue();
|
||||
assertThat(set.contains(Thread.State.RUNNABLE)).isTrue();
|
||||
|
||||
Map<?, ?> map = bean.getSomeMap();
|
||||
assertThat(map).hasSize(1);
|
||||
assertThat(map.get("min")).isEqualTo(CustomEnum.VALUE_1);
|
||||
assertThat(bean.getSomeList()).singleElement().isEqualTo(Integer.MIN_VALUE);
|
||||
assertThat(bean.getSomeSet()).asInstanceOf(InstanceOfAssertFactories.collection(Thread.State.class))
|
||||
.containsOnly(Thread.State.NEW,Thread.State.RUNNABLE);
|
||||
assertThat(bean.getSomeMap()).hasSize(1).allSatisfy((key, value) -> {
|
||||
assertThat(key).isEqualTo("min");
|
||||
assertThat(value).isEqualTo(CustomEnum.VALUE_1);
|
||||
});
|
||||
|
||||
TestBean bean2 = (TestBean) this.beanFactory.getBean("nestedCustomTagBean");
|
||||
assertThat(bean2.getSomeList()).isEqualTo(list);
|
||||
assertThat(bean2.getSomeSet()).isEqualTo(set);
|
||||
assertThat(bean2.getSomeMap()).isEqualTo(map);
|
||||
assertThat(list).isNotSameAs(bean2.getSomeList());
|
||||
assertThat(set).isNotSameAs(bean2.getSomeSet());
|
||||
assertThat(map).isNotSameAs(bean2.getSomeMap());
|
||||
assertThat(bean2.getSomeList()).isEqualTo(bean.getSomeList());
|
||||
assertThat(bean2.getSomeSet()).isEqualTo(bean.getSomeSet());
|
||||
assertThat(bean2.getSomeMap()).isEqualTo(bean.getSomeMap());
|
||||
assertThat(bean.getSomeList()).isNotSameAs(bean2.getSomeList());
|
||||
assertThat(bean.getSomeSet()).isNotSameAs(bean2.getSomeSet());
|
||||
assertThat(bean.getSomeMap()).isNotSameAs(bean2.getSomeMap());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCircularCollections() {
|
||||
TestBean bean = (TestBean) this.beanFactory.getBean("circularCollectionsBean");
|
||||
|
||||
List<?> list = bean.getSomeList();
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list).element(0).isEqualTo(bean);
|
||||
|
||||
Set<?> set = bean.getSomeSet();
|
||||
assertThat(set).hasSize(1);
|
||||
assertThat(set.contains(bean)).isTrue();
|
||||
|
||||
Map<?, ?> map = bean.getSomeMap();
|
||||
assertThat(map).hasSize(1);
|
||||
assertThat(map.get("foo")).isEqualTo(bean);
|
||||
assertThat(bean.getSomeList()).singleElement().isEqualTo(bean);
|
||||
assertThat(bean.getSomeSet()).singleElement().isEqualTo(bean);
|
||||
assertThat(bean.getSomeMap()).hasSize(1).allSatisfy((key, value) -> {
|
||||
assertThat(key).isEqualTo("foo");
|
||||
assertThat(value).isEqualTo(bean);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -273,18 +255,18 @@ class UtilNamespaceHandlerTests {
|
|||
|
||||
List<?> list = bean.getSomeList();
|
||||
assertThat(Proxy.isProxyClass(list.getClass())).isTrue();
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list).element(0).isEqualTo(bean);
|
||||
assertThat(list).singleElement().isEqualTo(bean);
|
||||
|
||||
Set<?> set = bean.getSomeSet();
|
||||
assertThat(Proxy.isProxyClass(set.getClass())).isFalse();
|
||||
assertThat(set).hasSize(1);
|
||||
assertThat(set.contains(bean)).isTrue();
|
||||
assertThat(set).singleElement().isEqualTo(bean);
|
||||
|
||||
Map<?, ?> map = bean.getSomeMap();
|
||||
assertThat(Proxy.isProxyClass(map.getClass())).isFalse();
|
||||
assertThat(map).hasSize(1);
|
||||
assertThat(map.get("foo")).isEqualTo(bean);
|
||||
assertThat(map).hasSize(1).allSatisfy((key, value) -> {
|
||||
assertThat(key).isEqualTo("foo");
|
||||
assertThat(value).isEqualTo(bean);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -294,18 +276,18 @@ class UtilNamespaceHandlerTests {
|
|||
|
||||
List<?> list = bean.getSomeList();
|
||||
assertThat(Proxy.isProxyClass(list.getClass())).isFalse();
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list).element(0).isEqualTo(bean);
|
||||
assertThat(list).singleElement().isEqualTo(bean);
|
||||
|
||||
Set<?> set = bean.getSomeSet();
|
||||
assertThat(Proxy.isProxyClass(set.getClass())).isTrue();
|
||||
assertThat(set).hasSize(1);
|
||||
assertThat(set.contains(bean)).isTrue();
|
||||
assertThat(set).singleElement().isEqualTo(bean);
|
||||
|
||||
Map<?, ?> map = bean.getSomeMap();
|
||||
assertThat(Proxy.isProxyClass(map.getClass())).isFalse();
|
||||
assertThat(map).hasSize(1);
|
||||
assertThat(map.get("foo")).isEqualTo(bean);
|
||||
assertThat(map).hasSize(1).allSatisfy((key, value) -> {
|
||||
assertThat(key).isEqualTo("foo");
|
||||
assertThat(value).isEqualTo(bean);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -315,18 +297,18 @@ class UtilNamespaceHandlerTests {
|
|||
|
||||
List<?> list = bean.getSomeList();
|
||||
assertThat(Proxy.isProxyClass(list.getClass())).isFalse();
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list).element(0).isEqualTo(bean);
|
||||
assertThat(list).singleElement().isEqualTo(bean);
|
||||
|
||||
Set<?> set = bean.getSomeSet();
|
||||
assertThat(Proxy.isProxyClass(set.getClass())).isFalse();
|
||||
assertThat(set).hasSize(1);
|
||||
assertThat(set.contains(bean)).isTrue();
|
||||
assertThat(set).singleElement().isEqualTo(bean);
|
||||
|
||||
Map<?, ?> map = bean.getSomeMap();
|
||||
assertThat(Proxy.isProxyClass(map.getClass())).isTrue();
|
||||
assertThat(map).hasSize(1);
|
||||
assertThat(map.get("foo")).isEqualTo(bean);
|
||||
assertThat(map).hasSize(1).allSatisfy((key, value) -> {
|
||||
assertThat(key).isEqualTo("foo");
|
||||
assertThat(value).isEqualTo(bean);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -154,14 +154,13 @@ class XmlBeanCollectionTests {
|
|||
void testRefSubelementsBuildCollectionFromSingleElement() {
|
||||
TestBean loner = (TestBean) this.beanFactory.getBean("loner");
|
||||
TestBean dave = (TestBean) this.beanFactory.getBean("david");
|
||||
assertThat(loner.getFriends().size()).isEqualTo(1);
|
||||
assertThat(loner.getFriends()).contains(dave);
|
||||
assertThat(loner.getFriends()).containsOnly(dave);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBuildCollectionFromMixtureOfReferencesAndValues() {
|
||||
MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble");
|
||||
assertThat(jumble.getJumble().size()).as("Expected 5 elements, not " + jumble.getJumble().size()).isEqualTo(5);
|
||||
assertThat(jumble.getJumble()).as("Expected 5 elements, not " + jumble.getJumble()).hasSize(5);
|
||||
List l = (List) jumble.getJumble();
|
||||
assertThat(l.get(0).equals(this.beanFactory.getBean("david"))).isTrue();
|
||||
assertThat(l.get(1).equals("literal")).isTrue();
|
||||
|
|
@ -183,13 +182,13 @@ class XmlBeanCollectionTests {
|
|||
@Test
|
||||
void testEmptyMap() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyMap");
|
||||
assertThat(hasMap.getMap().size()).isEqualTo(0);
|
||||
assertThat(hasMap.getMap()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMapWithLiteralsOnly() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("literalMap");
|
||||
assertThat(hasMap.getMap().size()).isEqualTo(3);
|
||||
assertThat(hasMap.getMap()).hasSize(3);
|
||||
assertThat(hasMap.getMap().get("foo").equals("bar")).isTrue();
|
||||
assertThat(hasMap.getMap().get("fi").equals("fum")).isTrue();
|
||||
assertThat(hasMap.getMap().get("fa")).isNull();
|
||||
|
|
@ -198,7 +197,7 @@ class XmlBeanCollectionTests {
|
|||
@Test
|
||||
void testMapWithLiteralsAndReferences() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMap");
|
||||
assertThat(hasMap.getMap().size()).isEqualTo(5);
|
||||
assertThat(hasMap.getMap()).hasSize(5);
|
||||
assertThat(hasMap.getMap().get("foo")).isEqualTo(10);
|
||||
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
|
||||
assertThat(hasMap.getMap().get("jenny")).isSameAs(jenny);
|
||||
|
|
@ -213,13 +212,13 @@ class XmlBeanCollectionTests {
|
|||
void testMapWithLiteralsAndPrototypeReferences() {
|
||||
TestBean jenny = (TestBean) this.beanFactory.getBean("pJenny");
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("pMixedMap");
|
||||
assertThat(hasMap.getMap().size()).isEqualTo(2);
|
||||
assertThat(hasMap.getMap()).hasSize(2);
|
||||
assertThat(hasMap.getMap().get("foo").equals("bar")).isTrue();
|
||||
assertThat(hasMap.getMap().get("jenny").toString()).isEqualTo(jenny.toString());
|
||||
assertThat(hasMap.getMap().get("jenny")).as("Not same instance").isNotSameAs(jenny);
|
||||
|
||||
HasMap hasMap2 = (HasMap) this.beanFactory.getBean("pMixedMap");
|
||||
assertThat(hasMap2.getMap().size()).isEqualTo(2);
|
||||
assertThat(hasMap2.getMap()).hasSize(2);
|
||||
assertThat(hasMap2.getMap().get("foo").equals("bar")).isTrue();
|
||||
assertThat(hasMap2.getMap().get("jenny").toString()).isEqualTo(jenny.toString());
|
||||
assertThat(hasMap2.getMap().get("jenny")).as("Not same instance").isNotSameAs(hasMap.getMap().get("jenny"));
|
||||
|
|
@ -228,7 +227,7 @@ class XmlBeanCollectionTests {
|
|||
@Test
|
||||
void testMapWithLiteralsReferencesAndList() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("mixedMapWithList");
|
||||
assertThat(hasMap.getMap().size()).isEqualTo(4);
|
||||
assertThat(hasMap.getMap()).hasSize(4);
|
||||
assertThat(hasMap.getMap().get(null).equals("bar")).isTrue();
|
||||
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
|
||||
assertThat(hasMap.getMap().get("jenny")).isEqualTo(jenny);
|
||||
|
|
@ -236,28 +235,28 @@ class XmlBeanCollectionTests {
|
|||
// Check list
|
||||
List l = (List) hasMap.getMap().get("list");
|
||||
assertThat(l).isNotNull();
|
||||
assertThat(l.size()).isEqualTo(4);
|
||||
assertThat(l).hasSize(4);
|
||||
assertThat(l.get(0).equals("zero")).isTrue();
|
||||
assertThat(l).element(3).isNull();
|
||||
|
||||
// Check nested map in list
|
||||
Map m = (Map) l.get(1);
|
||||
assertThat(m).isNotNull();
|
||||
assertThat(m.size()).isEqualTo(2);
|
||||
assertThat(m).hasSize(2);
|
||||
assertThat(m.get("fo").equals("bar")).isTrue();
|
||||
assertThat(m.get("jen").equals(jenny)).as("Map element 'jenny' should be equal to jenny bean, not " + m.get("jen")).isTrue();
|
||||
|
||||
// Check nested list in list
|
||||
l = (List) l.get(2);
|
||||
assertThat(l).isNotNull();
|
||||
assertThat(l.size()).isEqualTo(2);
|
||||
assertThat(l).hasSize(2);
|
||||
assertThat(l.get(0)).isEqualTo(jenny);
|
||||
assertThat(l.get(1).equals("ba")).isTrue();
|
||||
|
||||
// Check nested map
|
||||
m = (Map) hasMap.getMap().get("map");
|
||||
assertThat(m).isNotNull();
|
||||
assertThat(m.size()).isEqualTo(2);
|
||||
assertThat(m).hasSize(2);
|
||||
assertThat(m.get("foo").equals("bar")).isTrue();
|
||||
assertThat(m.get("jenny").equals(jenny)).as("Map element 'jenny' should be equal to jenny bean, not " + m.get("jenny")).isTrue();
|
||||
}
|
||||
|
|
@ -265,13 +264,13 @@ class XmlBeanCollectionTests {
|
|||
@Test
|
||||
void testEmptySet() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptySet");
|
||||
assertThat(hasMap.getSet().size()).isEqualTo(0);
|
||||
assertThat(hasMap.getSet()).hasSize(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulatedSet() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("set");
|
||||
assertThat(hasMap.getSet().size()).isEqualTo(3);
|
||||
assertThat(hasMap.getSet()).hasSize(3);
|
||||
assertThat(hasMap.getSet().contains("bar")).isTrue();
|
||||
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
|
||||
assertThat(hasMap.getSet().contains(jenny)).isTrue();
|
||||
|
|
@ -285,7 +284,7 @@ class XmlBeanCollectionTests {
|
|||
@Test
|
||||
void testPopulatedConcurrentSet() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("concurrentSet");
|
||||
assertThat(hasMap.getConcurrentSet().size()).isEqualTo(3);
|
||||
assertThat(hasMap.getConcurrentSet()).hasSize(3);
|
||||
assertThat(hasMap.getConcurrentSet().contains("bar")).isTrue();
|
||||
TestBean jenny = (TestBean) this.beanFactory.getBean("jenny");
|
||||
assertThat(hasMap.getConcurrentSet().contains(jenny)).isTrue();
|
||||
|
|
@ -295,7 +294,7 @@ class XmlBeanCollectionTests {
|
|||
@Test
|
||||
void testPopulatedIdentityMap() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("identityMap");
|
||||
assertThat(hasMap.getIdentityMap().size()).isEqualTo(2);
|
||||
assertThat(hasMap.getIdentityMap()).hasSize(2);
|
||||
HashSet set = new HashSet(hasMap.getIdentityMap().keySet());
|
||||
assertThat(set).contains("foo");
|
||||
assertThat(set).contains("jenny");
|
||||
|
|
@ -304,14 +303,14 @@ class XmlBeanCollectionTests {
|
|||
@Test
|
||||
void testEmptyProps() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("emptyProps");
|
||||
assertThat(hasMap.getProps().size()).isEqualTo(0);
|
||||
assertThat(hasMap.getProps()).hasSize(0);
|
||||
assertThat(Properties.class).isEqualTo(hasMap.getProps().getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPopulatedProps() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("props");
|
||||
assertThat(hasMap.getProps().size()).isEqualTo(2);
|
||||
assertThat(hasMap.getProps()).hasSize(2);
|
||||
assertThat(hasMap.getProps().get("foo").equals("bar")).isTrue();
|
||||
assertThat(hasMap.getProps().get("2").equals("TWO")).isTrue();
|
||||
}
|
||||
|
|
@ -344,7 +343,7 @@ class XmlBeanCollectionTests {
|
|||
@Test
|
||||
void testClassList() {
|
||||
HasMap hasMap = (HasMap) this.beanFactory.getBean("classList");
|
||||
assertThat(hasMap.getClassList().size()).isEqualTo(2);
|
||||
assertThat(hasMap.getClassList()).hasSize(2);
|
||||
assertThat(hasMap.getClassList().get(0).equals(String.class)).isTrue();
|
||||
assertThat(hasMap.getClassList().get(1).equals(Exception.class)).isTrue();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import java.util.Properties;
|
|||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
|
|
@ -132,9 +133,8 @@ class PropertiesEditorTests {
|
|||
PropertiesEditor pe= new PropertiesEditor();
|
||||
pe.setAsText(s);
|
||||
Properties p = (Properties) pe.getValue();
|
||||
assertThat(p.size()).as("contains 3 entries, not " + p.size()).isEqualTo(3);
|
||||
assertThat(p.get("foo").equals("bar")).as("foo is bar").isTrue();
|
||||
assertThat(p.get("me").equals("mi")).as("me=mi").isTrue();
|
||||
assertThat(p).contains(entry("foo", "bar"), entry("me", "mi"));
|
||||
assertThat(p).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -45,10 +45,7 @@ public abstract class AbstractCacheOperationTests<O extends JCacheOperation<?>>
|
|||
void simple() {
|
||||
O operation = createSimpleOperation();
|
||||
assertThat(operation.getCacheName()).as("Wrong cache name").isEqualTo("simpleCache");
|
||||
assertThat(operation.getAnnotations()).as("Unexpected number of annotation on " + operation.getMethod())
|
||||
.hasSize(1);
|
||||
assertThat(operation.getAnnotations()).element(0).as("Wrong method annotation").isEqualTo(operation.getCacheAnnotation());
|
||||
|
||||
assertThat(operation.getAnnotations()).singleElement().isEqualTo(operation.getCacheAnnotation());
|
||||
assertThat(operation.getCacheResolver()).as("cache resolver should be set").isNotNull();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,8 @@ import java.lang.annotation.Retention;
|
|||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -49,23 +47,21 @@ class AnnotationCacheOperationSourceTests {
|
|||
@Test
|
||||
void singularAnnotation() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1);
|
||||
assertThat(ops).element(0).isInstanceOf(CacheableOperation.class);
|
||||
assertThat(ops).singleElement().satisfies(cacheOperation(CacheableOperation.class, "test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipleAnnotation() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multiple", 2);
|
||||
Iterator<CacheOperation> it = ops.iterator();
|
||||
assertThat(it.next()).isInstanceOf(CacheableOperation.class);
|
||||
assertThat(it.next()).isInstanceOf(CacheEvictOperation.class);
|
||||
assertThat(ops).satisfiesExactly(cacheOperation(CacheableOperation.class),
|
||||
cacheOperation(CacheEvictOperation.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void caching() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "caching", 2);
|
||||
Iterator<CacheOperation> it = ops.iterator();
|
||||
assertThat(it.next()).isInstanceOf(CacheableOperation.class);
|
||||
assertThat(it.next()).isInstanceOf(CacheEvictOperation.class);
|
||||
assertThat(ops).satisfiesExactly(cacheOperation(CacheableOperation.class),
|
||||
cacheOperation(CacheEvictOperation.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -76,76 +72,69 @@ class AnnotationCacheOperationSourceTests {
|
|||
@Test
|
||||
void singularStereotype() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleStereotype", 1);
|
||||
assertThat(ops).element(0).isInstanceOf(CacheEvictOperation.class);
|
||||
assertThat(ops).satisfiesExactly(cacheOperation(CacheEvictOperation.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipleStereotypes() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleStereotype", 3);
|
||||
Iterator<CacheOperation> it = ops.iterator();
|
||||
assertThat(it.next()).isInstanceOf(CacheableOperation.class);
|
||||
CacheOperation next = it.next();
|
||||
assertThat(next).isInstanceOf(CacheEvictOperation.class);
|
||||
assertThat(next.getCacheNames()).contains("foo");
|
||||
next = it.next();
|
||||
assertThat(next).isInstanceOf(CacheEvictOperation.class);
|
||||
assertThat(next.getCacheNames()).contains("bar");
|
||||
assertThat(ops).satisfiesExactly(cacheOperation(CacheableOperation.class),
|
||||
cacheOperation(CacheEvictOperation.class, "foo"),
|
||||
cacheOperation(CacheEvictOperation.class, "bar")
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void singleComposedAnnotation() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleComposed", 2);
|
||||
Iterator<CacheOperation> it = ops.iterator();
|
||||
|
||||
CacheOperation cacheOperation = it.next();
|
||||
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
|
||||
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("directly declared"));
|
||||
assertThat(cacheOperation.getKey()).isEmpty();
|
||||
|
||||
cacheOperation = it.next();
|
||||
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
|
||||
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("composedCache"));
|
||||
assertThat(cacheOperation.getKey()).isEqualTo("composedKey");
|
||||
assertThat(ops).satisfiesExactly(
|
||||
zero -> {
|
||||
assertThat(zero).satisfies(cacheOperation(CacheOperation.class, "directly declared"));
|
||||
assertThat(zero.getKey()).isEmpty();
|
||||
},
|
||||
first -> {
|
||||
assertThat(first).satisfies(cacheOperation(CacheOperation.class, "composedCache"));
|
||||
assertThat(first.getKey()).isEqualTo("composedKey");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void multipleComposedAnnotations() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleComposed", 4);
|
||||
Iterator<CacheOperation> it = ops.iterator();
|
||||
|
||||
CacheOperation cacheOperation = it.next();
|
||||
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
|
||||
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("directly declared"));
|
||||
assertThat(cacheOperation.getKey()).isEmpty();
|
||||
|
||||
cacheOperation = it.next();
|
||||
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
|
||||
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("composedCache"));
|
||||
assertThat(cacheOperation.getKey()).isEqualTo("composedKey");
|
||||
|
||||
cacheOperation = it.next();
|
||||
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
|
||||
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("foo"));
|
||||
assertThat(cacheOperation.getKey()).isEmpty();
|
||||
|
||||
cacheOperation = it.next();
|
||||
assertThat(cacheOperation).isInstanceOf(CacheEvictOperation.class);
|
||||
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("composedCacheEvict"));
|
||||
assertThat(cacheOperation.getKey()).isEqualTo("composedEvictionKey");
|
||||
assertThat(ops).satisfiesExactly(
|
||||
zero -> {
|
||||
assertThat(zero).satisfies(cacheOperation(CacheOperation.class, "directly declared"));
|
||||
assertThat(zero.getKey()).isEmpty();
|
||||
},
|
||||
first -> {
|
||||
assertThat(first).satisfies(cacheOperation(CacheOperation.class, "composedCache"));
|
||||
assertThat(first.getKey()).isEqualTo("composedKey");
|
||||
},
|
||||
two -> {
|
||||
assertThat(two).satisfies(cacheOperation(CacheOperation.class, "foo"));
|
||||
assertThat(two.getKey()).isEmpty();
|
||||
},
|
||||
three -> {
|
||||
assertThat(three).satisfies(cacheOperation(CacheEvictOperation.class, "composedCacheEvict"));
|
||||
assertThat(three.getKey()).isEqualTo("composedEvictionKey");
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void customKeyGenerator() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGenerator", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertThat(cacheOperation.getKeyGenerator()).as("Custom key generator not set").isEqualTo("custom");
|
||||
assertThat(ops).singleElement().satisfies(cacheOperation ->
|
||||
assertThat(cacheOperation.getKeyGenerator()).isEqualTo("custom"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void customKeyGeneratorInherited() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGeneratorInherited", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertThat(cacheOperation.getKeyGenerator()).as("Custom key generator not set").isEqualTo("custom");
|
||||
assertThat(ops).singleElement().satisfies(cacheOperation ->
|
||||
assertThat(cacheOperation.getKeyGenerator()).isEqualTo("custom"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -157,29 +146,29 @@ class AnnotationCacheOperationSourceTests {
|
|||
@Test
|
||||
void customCacheManager() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheManager", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertThat(cacheOperation.getCacheManager()).as("Custom cache manager not set").isEqualTo("custom");
|
||||
assertThat(ops).singleElement().satisfies(cacheOperation ->
|
||||
assertThat(cacheOperation.getCacheManager()).isEqualTo("custom"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customCacheManagerInherited() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheManagerInherited", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertThat(cacheOperation.getCacheManager()).as("Custom cache manager not set").isEqualTo("custom");
|
||||
assertThat(ops).singleElement().satisfies(cacheOperation ->
|
||||
assertThat(cacheOperation.getCacheManager()).isEqualTo("custom"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customCacheResolver() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheResolver", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertThat(cacheOperation.getCacheResolver()).as("Custom cache resolver not set").isEqualTo("custom");
|
||||
assertThat(ops).singleElement().satisfies(cacheOperation ->
|
||||
assertThat(cacheOperation.getCacheResolver()).isEqualTo("custom"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void customCacheResolverInherited() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheResolverInherited", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertThat(cacheOperation.getCacheResolver()).as("Custom cache resolver not set").isEqualTo("custom");
|
||||
assertThat(ops).singleElement().satisfies(cacheOperation ->
|
||||
assertThat(cacheOperation.getCacheResolver()).isEqualTo("custom"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -191,90 +180,96 @@ class AnnotationCacheOperationSourceTests {
|
|||
@Test
|
||||
void fullClassLevelWithCustomCacheName() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelCacheName", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "classKeyGenerator", "", "classCacheResolver", "custom");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig(
|
||||
"classKeyGenerator", "", "classCacheResolver", "custom"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fullClassLevelWithCustomKeyManager() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelKeyGenerator", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "custom", "", "classCacheResolver" , "classCacheName");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig(
|
||||
"custom", "", "classCacheResolver" , "classCacheName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fullClassLevelWithCustomCacheManager() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelCacheManager", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "classKeyGenerator", "custom", "", "classCacheName");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig(
|
||||
"classKeyGenerator", "custom", "", "classCacheName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fullClassLevelWithCustomCacheResolver() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClassWithFullDefault.class, "methodLevelCacheResolver", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "classKeyGenerator", "", "custom" , "classCacheName");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig(
|
||||
"classKeyGenerator", "", "custom" , "classCacheName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateNoCacheIsValid() {
|
||||
// Valid as a CacheResolver might return the cache names to use with other info
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "noCacheNameSpecified");
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertThat(cacheOperation.getCacheNames()).as("cache names set must not be null").isNotNull();
|
||||
assertThat(cacheOperation.getCacheNames()).as("no cache names specified").isEmpty();
|
||||
assertThat(ops).singleElement().satisfies(cacheOperation ->
|
||||
assertThat(cacheOperation.getCacheNames()).isEmpty());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void customClassLevelWithCustomCacheName() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClassWithCustomDefault.class, "methodLevelCacheName", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "classKeyGenerator", "", "classCacheResolver", "custom");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig(
|
||||
"classKeyGenerator", "", "classCacheResolver", "custom"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void severalCacheConfigUseClosest() {
|
||||
Collection<CacheOperation> ops = getOps(MultipleCacheConfig.class, "multipleCacheConfig");
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "", "", "", "myCache");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig("", "", "", "myCache"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void cacheConfigFromInterface() {
|
||||
Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheConfig");
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "", "", "", "myCache");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig("", "", "", "myCache"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void cacheAnnotationOverride() {
|
||||
Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheableOverride");
|
||||
assertThat(ops.size()).isSameAs(1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
|
||||
assertThat(ops).singleElement().satisfies(cacheOperation(CacheableOperation.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void partialClassLevelWithCustomCacheManager() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClassWithSomeDefault.class, "methodLevelCacheManager", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "classKeyGenerator", "custom", "", "classCacheName");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig(
|
||||
"classKeyGenerator", "custom", "", "classCacheName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void partialClassLevelWithCustomCacheResolver() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClassWithSomeDefault.class, "methodLevelCacheResolver", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "classKeyGenerator", "", "custom", "classCacheName");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig(
|
||||
"classKeyGenerator", "", "custom", "classCacheName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void partialClassLevelWithNoCustomization() {
|
||||
Collection<CacheOperation> ops = getOps(AnnotatedClassWithSomeDefault.class, "noCustomization", 1);
|
||||
CacheOperation cacheOperation = ops.iterator().next();
|
||||
assertSharedConfig(cacheOperation, "classKeyGenerator", "classCacheManager", "", "classCacheName");
|
||||
assertThat(ops).singleElement().satisfies(hasSharedConfig(
|
||||
"classKeyGenerator", "classCacheManager", "", "classCacheName"));
|
||||
}
|
||||
|
||||
private Consumer<CacheOperation> cacheOperation(Class<? extends CacheOperation> type, String... cacheNames) {
|
||||
return candidate -> {
|
||||
assertThat(candidate).isInstanceOf(type);
|
||||
assertThat(candidate.getCacheNames()).containsExactly(cacheNames);
|
||||
};
|
||||
}
|
||||
|
||||
private Consumer<CacheOperation> cacheOperation(Class<? extends CacheOperation> type) {
|
||||
return candidate -> assertThat(candidate).isInstanceOf(type);
|
||||
}
|
||||
|
||||
private Collection<CacheOperation> getOps(Class<?> target, String name, int expectedNumberOfOperations) {
|
||||
Collection<CacheOperation> result = getOps(target, name);
|
||||
|
|
@ -292,14 +287,15 @@ class AnnotationCacheOperationSourceTests {
|
|||
}
|
||||
}
|
||||
|
||||
private void assertSharedConfig(CacheOperation actual, String keyGenerator, String cacheManager,
|
||||
private Consumer<CacheOperation> hasSharedConfig(String keyGenerator, String cacheManager,
|
||||
String cacheResolver, String... cacheNames) {
|
||||
|
||||
assertThat(actual.getKeyGenerator()).as("Wrong key manager").isEqualTo(keyGenerator);
|
||||
assertThat(actual.getCacheManager()).as("Wrong cache manager").isEqualTo(cacheManager);
|
||||
assertThat(actual.getCacheResolver()).as("Wrong cache resolver").isEqualTo(cacheResolver);
|
||||
assertThat(actual.getCacheNames()).as("Wrong number of cache names").hasSameSizeAs(cacheNames);
|
||||
Arrays.stream(cacheNames).forEach(cacheName -> assertThat(actual.getCacheNames()).as("Cache '" + cacheName + "' not found in " + actual.getCacheNames()).contains(cacheName));
|
||||
return actual -> {
|
||||
assertThat(actual.getKeyGenerator()).isEqualTo(keyGenerator);
|
||||
assertThat(actual.getCacheManager()).isEqualTo(cacheManager);
|
||||
assertThat(actual.getCacheResolver()).isEqualTo(cacheResolver);
|
||||
assertThat(actual.getCacheNames()).hasSameSizeAs(cacheNames);
|
||||
assertThat(actual.getCacheNames()).containsExactly(cacheNames);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -490,16 +490,13 @@ class ClassPathBeanDefinitionScannerTests {
|
|||
assertThat(fooService.foo(123)).isEqualTo("bar");
|
||||
assertThat(fooService.lookupFoo(123)).isEqualTo("bar");
|
||||
assertThat(fooService.beanFactory).isSameAs(context.getDefaultListableBeanFactory());
|
||||
assertThat(fooService.listableBeanFactory).hasSize(2);
|
||||
assertThat(fooService.listableBeanFactory).element(0).isSameAs(context.getDefaultListableBeanFactory());
|
||||
assertThat(fooService.listableBeanFactory).element(1).isSameAs(myBf);
|
||||
assertThat(fooService.listableBeanFactory).containsExactly(context.getDefaultListableBeanFactory(), myBf);
|
||||
assertThat(fooService.resourceLoader).isSameAs(context);
|
||||
assertThat(fooService.resourcePatternResolver).isSameAs(context);
|
||||
assertThat(fooService.eventPublisher).isSameAs(context);
|
||||
assertThat(fooService.messageSource).isSameAs(ms);
|
||||
assertThat(fooService.context).isSameAs(context);
|
||||
assertThat(fooService.configurableContext).hasSize(1);
|
||||
assertThat(fooService.configurableContext[0]).isSameAs(context);
|
||||
assertThat(fooService.configurableContext).containsExactly(context);
|
||||
assertThat(fooService.genericContext).isSameAs(context);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ import org.springframework.core.task.SyncTaskExecutor;
|
|||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static java.util.Map.entry;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
|
@ -1048,9 +1049,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testCollectionArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class);
|
||||
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).hasSize(1);
|
||||
assertThat(bean.testBeans).element(0).isSameAs(ctx.getBean(TestBean.class));
|
||||
assertThat(bean.testBeans).containsExactly(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
@ -1058,7 +1057,6 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testEmptyCollectionArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class);
|
||||
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).isEmpty();
|
||||
ctx.close();
|
||||
}
|
||||
|
|
@ -1067,9 +1065,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testMapArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class, DummyRunnable.class);
|
||||
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).hasSize(1);
|
||||
assertThat(bean.testBeans.values()).element(0).isSameAs(ctx.getBean(Runnable.class));
|
||||
assertThat(bean.testBeans).hasSize(1).containsValue(ctx.getBean(Runnable.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
@ -1077,7 +1073,6 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testEmptyMapArgumentOnBeanMethod() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class);
|
||||
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).isEmpty();
|
||||
ctx.close();
|
||||
}
|
||||
|
|
@ -1086,9 +1081,7 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testCollectionInjectionFromSameConfigurationClass() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class);
|
||||
CollectionInjectionConfiguration bean = ctx.getBean(CollectionInjectionConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).hasSize(1);
|
||||
assertThat(bean.testBeans).element(0).isSameAs(ctx.getBean(TestBean.class));
|
||||
assertThat(bean.testBeans).containsExactly(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
@ -1096,18 +1089,14 @@ class ConfigurationClassPostProcessorTests {
|
|||
void testMapInjectionFromSameConfigurationClass() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class);
|
||||
MapInjectionConfiguration bean = ctx.getBean(MapInjectionConfiguration.class);
|
||||
assertThat(bean.testBeans).isNotNull();
|
||||
assertThat(bean.testBeans).hasSize(1);
|
||||
assertThat(bean.testBeans.get("testBean")).isSameAs(ctx.getBean(Runnable.class));
|
||||
assertThat(bean.testBeans).containsOnly(entry("testBean", ctx.getBean(Runnable.class)));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBeanLookupFromSameConfigurationClass() {
|
||||
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(BeanLookupConfiguration.class);
|
||||
BeanLookupConfiguration bean = ctx.getBean(BeanLookupConfiguration.class);
|
||||
assertThat(bean.getTestBean()).isNotNull();
|
||||
assertThat(bean.getTestBean()).isSameAs(ctx.getBean(TestBean.class));
|
||||
assertThat(ctx.getBean(BeanLookupConfiguration.class).getTestBean()).isSameAs(ctx.getBean(TestBean.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -126,8 +126,7 @@ public class ImportSelectorTests {
|
|||
ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
|
||||
ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
|
||||
assertThat(TestImportGroup.instancesCount.get()).isEqualTo(1);
|
||||
assertThat(TestImportGroup.imports).hasSize(1);
|
||||
assertThat(TestImportGroup.imports.values()).element(0).asInstanceOf(LIST).hasSize(2);
|
||||
assertThat(TestImportGroup.imports.values()).singleElement().asInstanceOf(LIST).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -317,17 +317,13 @@ class ClassPathXmlApplicationContextTests {
|
|||
assertThat(beanNamesForType[0]).isEqualTo("myMessageSource");
|
||||
|
||||
Map<?, StaticMessageSource> beansOfType = ctx.getBeansOfType(StaticMessageSource.class);
|
||||
assertThat(beansOfType).hasSize(1);
|
||||
assertThat(beansOfType.values()).element(0).isSameAs(myMessageSource);
|
||||
assertThat(beansOfType.values()).singleElement().isSameAs(myMessageSource);
|
||||
beansOfType = ctx.getBeansOfType(StaticMessageSource.class, true, true);
|
||||
assertThat(beansOfType).hasSize(1);
|
||||
assertThat(beansOfType.values()).element(0).isSameAs(myMessageSource);
|
||||
assertThat(beansOfType.values()).singleElement().isSameAs(myMessageSource);
|
||||
beansOfType = BeanFactoryUtils.beansOfTypeIncludingAncestors(ctx, StaticMessageSource.class);
|
||||
assertThat(beansOfType).hasSize(1);
|
||||
assertThat(beansOfType.values()).element(0).isSameAs(myMessageSource);
|
||||
assertThat(beansOfType.values()).singleElement().isSameAs(myMessageSource);
|
||||
beansOfType = BeanFactoryUtils.beansOfTypeIncludingAncestors(ctx, StaticMessageSource.class, true, true);
|
||||
assertThat(beansOfType).hasSize(1);
|
||||
assertThat(beansOfType.values()).element(0).isSameAs(myMessageSource);
|
||||
assertThat(beansOfType.values()).singleElement().isSameAs(myMessageSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
package org.springframework.context.support;
|
||||
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -194,12 +195,8 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean3.isRunning()).isTrue();
|
||||
assertThat(beanMax.isRunning()).isTrue();
|
||||
context.stop();
|
||||
assertThat(startedBeans).hasSize(5);
|
||||
assertThat(getPhase(startedBeans.get(0))).isEqualTo(Integer.MIN_VALUE);
|
||||
assertThat(getPhase(startedBeans.get(1))).isEqualTo(1);
|
||||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(2);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(3);
|
||||
assertThat(getPhase(startedBeans.get(4))).isEqualTo(Integer.MAX_VALUE);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(Integer.MIN_VALUE),hasPhase(1),
|
||||
hasPhase(2), hasPhase(3), hasPhase(Integer.MAX_VALUE));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
@ -224,17 +221,13 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(smartBean2.isRunning()).isTrue();
|
||||
assertThat(simpleBean1.isRunning()).isFalse();
|
||||
assertThat(simpleBean2.isRunning()).isFalse();
|
||||
assertThat(startedBeans).hasSize(2);
|
||||
assertThat(getPhase(startedBeans.get(0))).isEqualTo(-3);
|
||||
assertThat(getPhase(startedBeans.get(1))).isEqualTo(5);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(-3), hasPhase(5));
|
||||
context.start();
|
||||
assertThat(smartBean1.isRunning()).isTrue();
|
||||
assertThat(smartBean2.isRunning()).isTrue();
|
||||
assertThat(simpleBean1.isRunning()).isTrue();
|
||||
assertThat(simpleBean2.isRunning()).isTrue();
|
||||
assertThat(startedBeans).hasSize(4);
|
||||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(0);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(-3), hasPhase(5), hasPhase(0), hasPhase(0));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
@ -259,9 +252,7 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(smartBean2.isRunning()).isTrue();
|
||||
assertThat(simpleBean1.isRunning()).isFalse();
|
||||
assertThat(simpleBean2.isRunning()).isFalse();
|
||||
assertThat(startedBeans).hasSize(2);
|
||||
assertThat(getPhase(startedBeans.get(0))).isEqualTo(-3);
|
||||
assertThat(getPhase(startedBeans.get(1))).isEqualTo(5);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(-3), hasPhase(5));
|
||||
context.stop();
|
||||
assertThat(simpleBean1.isRunning()).isFalse();
|
||||
assertThat(simpleBean2.isRunning()).isFalse();
|
||||
|
|
@ -272,11 +263,8 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(smartBean2.isRunning()).isTrue();
|
||||
assertThat(simpleBean1.isRunning()).isTrue();
|
||||
assertThat(simpleBean2.isRunning()).isTrue();
|
||||
assertThat(startedBeans).hasSize(6);
|
||||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(-3);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(4))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(5))).isEqualTo(5);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(-3), hasPhase(5),
|
||||
hasPhase(-3), hasPhase(0), hasPhase(0), hasPhase(5));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
@ -305,10 +293,7 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(simpleBean2.isRunning()).isFalse();
|
||||
smartBean2.stop();
|
||||
simpleBean1.start();
|
||||
assertThat(startedBeans).hasSize(3);
|
||||
assertThat(getPhase(startedBeans.get(0))).isEqualTo(-3);
|
||||
assertThat(getPhase(startedBeans.get(1))).isEqualTo(5);
|
||||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(0);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(-3), hasPhase(5), hasPhase(0));
|
||||
lifecycleProcessor.stopForRestart();
|
||||
assertThat(simpleBean1.isRunning()).isFalse();
|
||||
assertThat(simpleBean2.isRunning()).isFalse();
|
||||
|
|
@ -319,17 +304,15 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(smartBean2.isRunning()).isFalse();
|
||||
assertThat(simpleBean1.isRunning()).isTrue();
|
||||
assertThat(simpleBean2.isRunning()).isFalse();
|
||||
assertThat(startedBeans).hasSize(5);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(4))).isEqualTo(5);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(-3), hasPhase(5),
|
||||
hasPhase(0), hasPhase(0), hasPhase(5));
|
||||
context.start();
|
||||
assertThat(smartBean1.isRunning()).isTrue();
|
||||
assertThat(smartBean2.isRunning()).isTrue();
|
||||
assertThat(simpleBean1.isRunning()).isTrue();
|
||||
assertThat(simpleBean2.isRunning()).isTrue();
|
||||
assertThat(startedBeans).hasSize(7);
|
||||
assertThat(getPhase(startedBeans.get(5))).isEqualTo(-3);
|
||||
assertThat(getPhase(startedBeans.get(6))).isEqualTo(0);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(-3), hasPhase(5),
|
||||
hasPhase(0), hasPhase(0), hasPhase(5), hasPhase(-3), hasPhase(0));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
@ -354,13 +337,8 @@ class DefaultLifecycleProcessorTests {
|
|||
context.getBeanFactory().registerSingleton("bean7", bean7);
|
||||
context.refresh();
|
||||
context.stop();
|
||||
assertThat(getPhase(stoppedBeans.get(0))).isEqualTo(Integer.MAX_VALUE);
|
||||
assertThat(getPhase(stoppedBeans.get(1))).isEqualTo(3);
|
||||
assertThat(getPhase(stoppedBeans.get(2))).isEqualTo(3);
|
||||
assertThat(getPhase(stoppedBeans.get(3))).isEqualTo(2);
|
||||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(2);
|
||||
assertThat(getPhase(stoppedBeans.get(5))).isEqualTo(1);
|
||||
assertThat(getPhase(stoppedBeans.get(6))).isEqualTo(1);
|
||||
assertThat(stoppedBeans).satisfiesExactly(hasPhase(Integer.MAX_VALUE), hasPhase(3),
|
||||
hasPhase(3), hasPhase(2), hasPhase(2), hasPhase(1), hasPhase(1));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
@ -390,9 +368,8 @@ class DefaultLifecycleProcessorTests {
|
|||
bean.start();
|
||||
assertThat(bean.isRunning()).isTrue();
|
||||
context.stop();
|
||||
assertThat(stoppedBeans).hasSize(1);
|
||||
assertThat(bean.isRunning()).isFalse();
|
||||
assertThat(stoppedBeans).element(0).isEqualTo(bean);
|
||||
assertThat(stoppedBeans).singleElement().isEqualTo(bean);
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
@ -434,14 +411,8 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean5.isRunning()).isFalse();
|
||||
assertThat(bean6.isRunning()).isFalse();
|
||||
assertThat(bean7.isRunning()).isFalse();
|
||||
assertThat(stoppedBeans).hasSize(7);
|
||||
assertThat(getPhase(stoppedBeans.get(0))).isEqualTo(Integer.MAX_VALUE);
|
||||
assertThat(getPhase(stoppedBeans.get(1))).isEqualTo(500);
|
||||
assertThat(getPhase(stoppedBeans.get(2))).isEqualTo(1);
|
||||
assertThat(getPhase(stoppedBeans.get(3))).isEqualTo(0);
|
||||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(0);
|
||||
assertThat(getPhase(stoppedBeans.get(5))).isEqualTo(-1);
|
||||
assertThat(getPhase(stoppedBeans.get(6))).isEqualTo(Integer.MIN_VALUE);
|
||||
assertThat(stoppedBeans).satisfiesExactly(hasPhase(Integer.MAX_VALUE), hasPhase(500),
|
||||
hasPhase(1), hasPhase(0), hasPhase(0), hasPhase(-1), hasPhase(Integer.MIN_VALUE));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
@ -463,13 +434,11 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean2.isRunning()).isTrue();
|
||||
assertThat(bean99.isRunning()).isTrue();
|
||||
assertThat(beanMax.isRunning()).isTrue();
|
||||
assertThat(startedBeans).hasSize(4);
|
||||
assertThat(getPhase(startedBeans.get(0))).isEqualTo(Integer.MIN_VALUE);
|
||||
assertThat(getPhase(startedBeans.get(1))).isEqualTo(99);
|
||||
assertThat(startedBeans).element(1).isEqualTo(bean99);
|
||||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(2);
|
||||
assertThat(startedBeans).element(2).isEqualTo(bean2);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(Integer.MAX_VALUE);
|
||||
assertThat(startedBeans).satisfiesExactly(
|
||||
hasPhase(Integer.MIN_VALUE),
|
||||
one -> assertThat(one).isEqualTo(bean99).satisfies(hasPhase(99)),
|
||||
two -> assertThat(two).isEqualTo(bean2).satisfies(hasPhase(2)),
|
||||
hasPhase(Integer.MAX_VALUE));
|
||||
context.stop();
|
||||
context.close();
|
||||
}
|
||||
|
|
@ -507,14 +476,11 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean99.isRunning()).isFalse();
|
||||
assertThat(beanMax.isRunning()).isFalse();
|
||||
assertThat(stoppedBeans).hasSize(6);
|
||||
assertThat(getPhase(stoppedBeans.get(0))).isEqualTo(Integer.MAX_VALUE);
|
||||
assertThat(getPhase(stoppedBeans.get(1))).isEqualTo(2);
|
||||
assertThat(stoppedBeans).element(1).isEqualTo(bean2);
|
||||
assertThat(getPhase(stoppedBeans.get(2))).isEqualTo(99);
|
||||
assertThat(stoppedBeans).element(2).isEqualTo(bean99);
|
||||
assertThat(getPhase(stoppedBeans.get(3))).isEqualTo(7);
|
||||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(1);
|
||||
assertThat(getPhase(stoppedBeans.get(5))).isEqualTo(Integer.MIN_VALUE);
|
||||
assertThat(stoppedBeans).satisfiesExactly(
|
||||
hasPhase(Integer.MAX_VALUE),
|
||||
one -> assertThat(one).isEqualTo(bean2).satisfies(hasPhase(2)),
|
||||
two -> assertThat(two).isEqualTo(bean99).satisfies(hasPhase(99)),
|
||||
hasPhase(7), hasPhase(1), hasPhase(Integer.MIN_VALUE));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
@ -540,11 +506,7 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean99.isRunning()).isTrue();
|
||||
assertThat(bean7.isRunning()).isTrue();
|
||||
assertThat(simpleBean.isRunning()).isTrue();
|
||||
assertThat(startedBeans).hasSize(4);
|
||||
assertThat(getPhase(startedBeans.get(0))).isEqualTo(-99);
|
||||
assertThat(getPhase(startedBeans.get(1))).isEqualTo(7);
|
||||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(3))).isEqualTo(99);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(-99), hasPhase(7), hasPhase(0), hasPhase(99));
|
||||
context.stop();
|
||||
context.close();
|
||||
}
|
||||
|
|
@ -582,13 +544,8 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean2.isRunning()).isFalse();
|
||||
assertThat(bean7.isRunning()).isFalse();
|
||||
assertThat(simpleBean.isRunning()).isFalse();
|
||||
assertThat(stoppedBeans).hasSize(6);
|
||||
assertThat(getPhase(stoppedBeans.get(0))).isEqualTo(7);
|
||||
assertThat(getPhase(stoppedBeans.get(1))).isEqualTo(2);
|
||||
assertThat(getPhase(stoppedBeans.get(2))).isEqualTo(1);
|
||||
assertThat(getPhase(stoppedBeans.get(3))).isEqualTo(-99);
|
||||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(0);
|
||||
assertThat(getPhase(stoppedBeans.get(5))).isEqualTo(Integer.MIN_VALUE);
|
||||
assertThat(stoppedBeans).satisfiesExactly(hasPhase(7), hasPhase(2),
|
||||
hasPhase(1), hasPhase(-99), hasPhase(0), hasPhase(Integer.MIN_VALUE));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
|
@ -607,10 +564,7 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(beanMin.isRunning()).isTrue();
|
||||
assertThat(bean7.isRunning()).isTrue();
|
||||
assertThat(simpleBean.isRunning()).isTrue();
|
||||
assertThat(startedBeans).hasSize(3);
|
||||
assertThat(getPhase(startedBeans.get(0))).isEqualTo(0);
|
||||
assertThat(getPhase(startedBeans.get(1))).isEqualTo(Integer.MIN_VALUE);
|
||||
assertThat(getPhase(startedBeans.get(2))).isEqualTo(7);
|
||||
assertThat(startedBeans).satisfiesExactly(hasPhase(0), hasPhase(Integer.MIN_VALUE), hasPhase(7));
|
||||
context.stop();
|
||||
context.close();
|
||||
}
|
||||
|
|
@ -645,21 +599,18 @@ class DefaultLifecycleProcessorTests {
|
|||
assertThat(bean2.isRunning()).isFalse();
|
||||
assertThat(bean7.isRunning()).isFalse();
|
||||
assertThat(simpleBean.isRunning()).isFalse();
|
||||
assertThat(stoppedBeans).hasSize(5);
|
||||
assertThat(getPhase(stoppedBeans.get(0))).isEqualTo(7);
|
||||
assertThat(getPhase(stoppedBeans.get(1))).isEqualTo(0);
|
||||
assertThat(getPhase(stoppedBeans.get(2))).isEqualTo(2);
|
||||
assertThat(getPhase(stoppedBeans.get(3))).isEqualTo(1);
|
||||
assertThat(getPhase(stoppedBeans.get(4))).isEqualTo(Integer.MIN_VALUE);
|
||||
assertThat(stoppedBeans).satisfiesExactly(hasPhase(7), hasPhase(0),
|
||||
hasPhase(2), hasPhase(1), hasPhase(Integer.MIN_VALUE));
|
||||
context.close();
|
||||
}
|
||||
|
||||
|
||||
private static int getPhase(Lifecycle lifecycle) {
|
||||
return (lifecycle instanceof SmartLifecycle smartLifecycle ? smartLifecycle.getPhase() : 0);
|
||||
private Consumer<? super Lifecycle> hasPhase(int phase) {
|
||||
return lifecycle -> {
|
||||
int actual = lifecycle instanceof SmartLifecycle smartLifecycle ? smartLifecycle.getPhase() : 0;
|
||||
assertThat(actual).isEqualTo(phase);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private static class TestLifecycleBean implements Lifecycle {
|
||||
|
||||
private final CopyOnWriteArrayList<Lifecycle> startedBeans;
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ class PropertySourcesPlaceholderConfigurerTests {
|
|||
ppc.setPropertySources(propertySources);
|
||||
ppc.postProcessBeanFactory(bf);
|
||||
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("foo");
|
||||
assertThat(propertySources).element(0).isEqualTo(ppc.getAppliedPropertySources().iterator().next());
|
||||
assertThat(propertySources).containsExactlyElementsOf(ppc.getAppliedPropertySources());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -132,7 +132,7 @@ class PropertySourcesPlaceholderConfigurerTests {
|
|||
ppc.setIgnoreUnresolvablePlaceholders(true);
|
||||
ppc.postProcessBeanFactory(bf);
|
||||
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("${my.name}");
|
||||
assertThat(propertySources).element(0).isEqualTo(ppc.getAppliedPropertySources().iterator().next());
|
||||
assertThat(propertySources).containsExactlyElementsOf(ppc.getAppliedPropertySources());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class SerializableBeanFactoryMemoryLeakTests {
|
|||
*/
|
||||
@BeforeAll
|
||||
@AfterAll
|
||||
public static void zeroOutFactoryCount() throws Exception {
|
||||
static void zeroOutFactoryCount() throws Exception {
|
||||
getSerializableFactoryMap().clear();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -32,9 +32,8 @@ class Spr7283Tests {
|
|||
void listWithInconsistentElementTypes() {
|
||||
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spr7283.xml", getClass());
|
||||
List<?> list = ctx.getBean("list", List.class);
|
||||
assertThat(list).hasSize(2);
|
||||
assertThat(list).element(0).isInstanceOf(A.class);
|
||||
assertThat(list).element(1).isInstanceOf(B.class);
|
||||
assertThat(list).satisfiesExactly(zero -> assertThat(zero).isInstanceOf(A.class),
|
||||
one -> assertThat(one).isInstanceOf(B.class));
|
||||
ctx.close();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -697,10 +697,8 @@ class MBeanExporterTests extends AbstractMBeanServerTests {
|
|||
|
||||
private static void assertListener(MockMBeanExporterListener listener) throws MalformedObjectNameException {
|
||||
ObjectName desired = ObjectNameManager.getInstance(OBJECT_NAME);
|
||||
assertThat(listener.getRegistered()).as("Incorrect number of registrations").hasSize(1);
|
||||
assertThat(listener.getUnregistered()).as("Incorrect number of unregistrations").hasSize(1);
|
||||
assertThat(listener.getRegistered()).element(0).as("Incorrect ObjectName in register").isEqualTo(desired);
|
||||
assertThat(listener.getUnregistered()).element(0).as("Incorrect ObjectName in unregister").isEqualTo(desired);
|
||||
assertThat(listener.getRegistered()).singleElement().isEqualTo(desired);
|
||||
assertThat(listener.getUnregistered()).singleElement().isEqualTo(desired);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ class AsyncResultTests {
|
|||
values.add(ex);
|
||||
}
|
||||
});
|
||||
assertThat(values).element(0).isSameAs(ex);
|
||||
assertThat(values).singleElement().isSameAs(ex);
|
||||
assertThatExceptionOfType(ExecutionException.class)
|
||||
.isThrownBy(future::get)
|
||||
.withCause(ex);
|
||||
|
|
@ -98,7 +98,7 @@ class AsyncResultTests {
|
|||
final Set<Throwable> values = new HashSet<>(1);
|
||||
org.springframework.util.concurrent.ListenableFuture<String> future = AsyncResult.forExecutionException(ex);
|
||||
future.addCallback(result -> new AssertionError("Success callback not expected: " + result), values::add);
|
||||
assertThat(values).element(0).isSameAs(ex);
|
||||
assertThat(values).singleElement().isSameAs(ex);
|
||||
assertThatExceptionOfType(ExecutionException.class)
|
||||
.isThrownBy(future::get)
|
||||
.withCause(ex);
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import java.util.Optional;
|
|||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import org.assertj.core.api.IntegerAssert;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.BeanWrapper;
|
||||
|
|
@ -2041,7 +2042,7 @@ class DataBinderTests {
|
|||
|
||||
binder.bind(pvs);
|
||||
assertThat(tb.getIntegerList()).hasSize(257);
|
||||
assertThat(tb.getIntegerList()).element(256).isEqualTo(1);
|
||||
assertThat(tb.getIntegerList(), IntegerAssert.class).element(256).isEqualTo(1);
|
||||
assertThat(binder.getBindingResult().getFieldValue("integerList[256]")).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -61,9 +61,9 @@ class MockSpringFactoriesLoaderTests {
|
|||
|
||||
private void assertThatLoaderHasTestFactories(MockSpringFactoriesLoader loader) {
|
||||
List<TestFactoryType> factories = loader.load(TestFactoryType.class);
|
||||
assertThat(factories).hasSize(2);
|
||||
assertThat(factories).element(0).isInstanceOf(TestFactoryOne.class);
|
||||
assertThat(factories).element(1).isInstanceOf(TestFactoryTwo.class);
|
||||
assertThat(factories).satisfiesExactly(
|
||||
zero -> assertThat(zero).isInstanceOf(TestFactoryOne.class),
|
||||
one -> assertThat(one).isInstanceOf(TestFactoryTwo.class));
|
||||
}
|
||||
|
||||
interface TestFactoryType {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -41,8 +41,7 @@ class AnnotationAwareOrderComparatorTests {
|
|||
list.add(new B());
|
||||
list.add(new A());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list).element(0).isInstanceOf(A.class);
|
||||
assertThat(list).element(1).isInstanceOf(B.class);
|
||||
assertThat(list).hasExactlyElementsOfTypes(A.class, B.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -51,8 +50,7 @@ class AnnotationAwareOrderComparatorTests {
|
|||
list.add(new B2());
|
||||
list.add(new A2());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list).element(0).isInstanceOf(A2.class);
|
||||
assertThat(list).element(1).isInstanceOf(B2.class);
|
||||
assertThat(list).hasExactlyElementsOfTypes(A2.class, B2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -61,8 +59,7 @@ class AnnotationAwareOrderComparatorTests {
|
|||
list.add(new B());
|
||||
list.add(new A2());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list).element(0).isInstanceOf(A2.class);
|
||||
assertThat(list).element(1).isInstanceOf(B.class);
|
||||
assertThat(list).hasExactlyElementsOfTypes(A2.class, B.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -71,8 +68,7 @@ class AnnotationAwareOrderComparatorTests {
|
|||
list.add(new B());
|
||||
list.add(new C());
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list).element(0).isInstanceOf(C.class);
|
||||
assertThat(list).element(1).isInstanceOf(B.class);
|
||||
assertThat(list).hasExactlyElementsOfTypes(C.class, B.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -81,8 +77,7 @@ class AnnotationAwareOrderComparatorTests {
|
|||
list.add(B.class);
|
||||
list.add(A.class);
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list).element(0).isEqualTo(A.class);
|
||||
assertThat(list).element(1).isEqualTo(B.class);
|
||||
assertThat(list).containsExactly(A.class, B.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -91,8 +86,7 @@ class AnnotationAwareOrderComparatorTests {
|
|||
list.add(B.class);
|
||||
list.add(C.class);
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list).element(0).isEqualTo(C.class);
|
||||
assertThat(list).element(1).isEqualTo(B.class);
|
||||
assertThat(list).containsExactly(C.class, B.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -103,13 +97,9 @@ class AnnotationAwareOrderComparatorTests {
|
|||
list.add(null);
|
||||
list.add(A.class);
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list).element(0).isEqualTo(A.class);
|
||||
assertThat(list).element(1).isEqualTo(B.class);
|
||||
assertThat(list).element(2).isNull();
|
||||
assertThat(list).element(3).isNull();
|
||||
assertThat(list).containsExactly(A.class, B.class, null, null);
|
||||
}
|
||||
|
||||
|
||||
@Order(1)
|
||||
private static class A {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -133,10 +133,11 @@ class CollectionToCollectionConverterTests {
|
|||
TypeDescriptor targetType = new TypeDescriptor(getClass().getField("objectToCollection"));
|
||||
assertThat(conversionService.canConvert(sourceType, targetType)).isTrue();
|
||||
List<List<List<Integer>>> result = (List<List<List<Integer>>>) conversionService.convert(list, sourceType, targetType);
|
||||
assertThat(result.get(0).get(0)).element(0).isEqualTo(9);
|
||||
assertThat(result.get(0).get(1)).element(0).isEqualTo(12);
|
||||
assertThat(result.get(1).get(0)).element(0).isEqualTo(37);
|
||||
assertThat(result.get(1).get(1)).element(0).isEqualTo(23);
|
||||
assertThat(result).hasSize(2);
|
||||
assertThat(result.get(0).get(0)).singleElement().isEqualTo(9);
|
||||
assertThat(result.get(0).get(1)).singleElement().isEqualTo(12);
|
||||
assertThat(result.get(1).get(0)).singleElement().isEqualTo(37);
|
||||
assertThat(result.get(1).get(1)).singleElement().isEqualTo(23);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -153,10 +154,9 @@ class CollectionToCollectionConverterTests {
|
|||
TypeDescriptor targetType = new TypeDescriptor(getClass().getField("objectToCollection"));
|
||||
assertThat(conversionService.canConvert(sourceType, targetType)).isTrue();
|
||||
List<List<List<Integer>>> result = (List<List<List<Integer>>>) conversionService.convert(list, sourceType, targetType);
|
||||
assertThat(result.get(0).get(0)).element(0).isEqualTo(9);
|
||||
assertThat(result.get(0).get(0)).element(1).isEqualTo(12);
|
||||
assertThat(result.get(1).get(0)).element(0).isEqualTo(37);
|
||||
assertThat(result.get(1).get(0)).element(1).isEqualTo(23);
|
||||
assertThat(result).satisfiesExactly(
|
||||
zero -> assertThat(zero.get(0)).containsExactly(9, 12),
|
||||
one -> assertThat(one.get(0)).containsExactly(37, 23));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -122,8 +122,7 @@ class SimpleCommandLinePropertySourceTests {
|
|||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> nonOptionArgsList = env.getProperty("nonOptionArgs", List.class);
|
||||
assertThat(nonOptionArgsList).element(0).isEqualTo("noa1");
|
||||
assertThat(nonOptionArgsList).element(1).isEqualTo("noa2");
|
||||
assertThat(nonOptionArgsList).containsExactly("noa1", "noa2");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -84,9 +84,7 @@ class SpringFactoriesLoaderTests {
|
|||
@Test
|
||||
void loadWhenDuplicateRegistrationsPresentReturnsListInCorrectOrder() {
|
||||
List<DummyFactory> factories = SpringFactoriesLoader.forDefaultResourceLocation().load(DummyFactory.class);
|
||||
assertThat(factories).hasSize(2);
|
||||
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
|
||||
assertThat(factories).element(1).isInstanceOf(MyDummyFactory2.class);
|
||||
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class, MyDummyFactory2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -118,10 +116,8 @@ class SpringFactoriesLoaderTests {
|
|||
ArgumentResolver resolver = ArgumentResolver.of(String.class, "injected");
|
||||
List<DummyFactory> factories = SpringFactoriesLoader.forDefaultResourceLocation(LimitedClassLoader.constructorArgumentFactories)
|
||||
.load(DummyFactory.class, resolver);
|
||||
assertThat(factories).hasSize(3);
|
||||
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
|
||||
assertThat(factories).element(1).isInstanceOf(MyDummyFactory2.class);
|
||||
assertThat(factories).element(2).isInstanceOf(ConstructorArgsDummyFactory.class);
|
||||
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class, MyDummyFactory2.class,
|
||||
ConstructorArgsDummyFactory.class);
|
||||
assertThat(factories).extracting(DummyFactory::getString).containsExactly("Foo", "Bar", "injected");
|
||||
}
|
||||
|
||||
|
|
@ -142,18 +138,14 @@ class SpringFactoriesLoaderTests {
|
|||
FailureHandler failureHandler = FailureHandler.logging(logger);
|
||||
List<DummyFactory> factories = SpringFactoriesLoader.forDefaultResourceLocation(LimitedClassLoader.multipleArgumentFactories)
|
||||
.load(DummyFactory.class, failureHandler);
|
||||
assertThat(factories).hasSize(2);
|
||||
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
|
||||
assertThat(factories).element(1).isInstanceOf(MyDummyFactory2.class);
|
||||
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class, MyDummyFactory2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void loadFactoriesLoadsFromDefaultLocation() {
|
||||
List<DummyFactory> factories = SpringFactoriesLoader.loadFactories(
|
||||
DummyFactory.class, null);
|
||||
assertThat(factories).hasSize(2);
|
||||
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
|
||||
assertThat(factories).element(1).isInstanceOf(MyDummyFactory2.class);
|
||||
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class, MyDummyFactory2.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -167,8 +159,7 @@ class SpringFactoriesLoaderTests {
|
|||
void loadForResourceLocationLoadsFactories() {
|
||||
List<DummyFactory> factories = SpringFactoriesLoader.forResourceLocation(
|
||||
"META-INF/custom/custom-spring.factories").load(DummyFactory.class);
|
||||
assertThat(factories).hasSize(1);
|
||||
assertThat(factories).element(0).isInstanceOf(MyDummyFactory1.class);
|
||||
assertThat(factories).hasExactlyElementsOfTypes(MyDummyFactory1.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -220,8 +211,7 @@ class SpringFactoriesLoaderTests {
|
|||
RuntimeException cause = new RuntimeException();
|
||||
handler.handleFailure(DummyFactory.class, MyDummyFactory1.class.getName(), cause);
|
||||
assertThat(failures).containsExactly(cause);
|
||||
assertThat(messages).hasSize(1);
|
||||
assertThat(messages).element(0).asString().startsWith("Unable to instantiate factory class");
|
||||
assertThat(messages).singleElement().asString().startsWith("Unable to instantiate factory class");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -513,74 +513,63 @@ class AntPathMatcherTests {
|
|||
paths.add(null);
|
||||
paths.add("/hotels/new");
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/new");
|
||||
assertThat(paths).element(1).isNull();
|
||||
assertThat(paths).containsExactly("/hotels/new", null);
|
||||
paths.clear();
|
||||
|
||||
paths.add("/hotels/new");
|
||||
paths.add(null);
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/new");
|
||||
assertThat(paths).element(1).isNull();
|
||||
assertThat(paths).containsExactly("/hotels/new", null);
|
||||
paths.clear();
|
||||
|
||||
paths.add("/hotels/*");
|
||||
paths.add("/hotels/new");
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/new");
|
||||
assertThat(paths).element(1).isEqualTo("/hotels/*");
|
||||
assertThat(paths).containsExactly("/hotels/new", "/hotels/*");
|
||||
paths.clear();
|
||||
|
||||
paths.add("/hotels/new");
|
||||
paths.add("/hotels/*");
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/new");
|
||||
assertThat(paths).element(1).isEqualTo("/hotels/*");
|
||||
assertThat(paths).containsExactly("/hotels/new", "/hotels/*");
|
||||
paths.clear();
|
||||
|
||||
paths.add("/hotels/**");
|
||||
paths.add("/hotels/*");
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/*");
|
||||
assertThat(paths).element(1).isEqualTo("/hotels/**");
|
||||
assertThat(paths).containsExactly("/hotels/*", "/hotels/**");
|
||||
paths.clear();
|
||||
|
||||
paths.add("/hotels/*");
|
||||
paths.add("/hotels/**");
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/*");
|
||||
assertThat(paths).element(1).isEqualTo("/hotels/**");
|
||||
assertThat(paths).containsExactly("/hotels/*", "/hotels/**");
|
||||
paths.clear();
|
||||
|
||||
paths.add("/hotels/{hotel}");
|
||||
paths.add("/hotels/new");
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/new");
|
||||
assertThat(paths).element(1).isEqualTo("/hotels/{hotel}");
|
||||
assertThat(paths).containsExactly("/hotels/new", "/hotels/{hotel}");
|
||||
paths.clear();
|
||||
|
||||
paths.add("/hotels/new");
|
||||
paths.add("/hotels/{hotel}");
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/new");
|
||||
assertThat(paths).element(1).isEqualTo("/hotels/{hotel}");
|
||||
assertThat(paths).containsExactly("/hotels/new", "/hotels/{hotel}");
|
||||
paths.clear();
|
||||
|
||||
paths.add("/hotels/*");
|
||||
paths.add("/hotels/{hotel}");
|
||||
paths.add("/hotels/new");
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/new");
|
||||
assertThat(paths).element(1).isEqualTo("/hotels/{hotel}");
|
||||
assertThat(paths).element(2).isEqualTo("/hotels/*");
|
||||
assertThat(paths).containsExactly("/hotels/new", "/hotels/{hotel}", "/hotels/*");
|
||||
paths.clear();
|
||||
|
||||
paths.add("/hotels/ne*");
|
||||
paths.add("/hotels/n*");
|
||||
Collections.shuffle(paths);
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/ne*");
|
||||
assertThat(paths).element(1).isEqualTo("/hotels/n*");
|
||||
assertThat(paths).containsExactly("/hotels/ne*", "/hotels/n*");
|
||||
paths.clear();
|
||||
|
||||
comparator = pathMatcher.getPatternComparator("/hotels/new.html");
|
||||
|
|
@ -588,16 +577,14 @@ class AntPathMatcherTests {
|
|||
paths.add("/hotels/{hotel}");
|
||||
Collections.shuffle(paths);
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/hotels/new.*");
|
||||
assertThat(paths).element(1).isEqualTo("/hotels/{hotel}");
|
||||
assertThat(paths).containsExactly("/hotels/new.*", "/hotels/{hotel}");
|
||||
paths.clear();
|
||||
|
||||
comparator = pathMatcher.getPatternComparator("/web/endUser/action/login.html");
|
||||
paths.add("/**/login.*");
|
||||
paths.add("/**/endUser/action/login.*");
|
||||
paths.sort(comparator);
|
||||
assertThat(paths).element(0).isEqualTo("/**/endUser/action/login.*");
|
||||
assertThat(paths).element(1).isEqualTo("/**/login.*");
|
||||
assertThat(paths).containsExactly("/**/endUser/action/login.*", "/**/login.*");
|
||||
paths.clear();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -18,6 +18,7 @@ package org.springframework.util;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.testfixture.io.SerializationTestUtils;
|
||||
|
|
@ -65,7 +66,7 @@ class AutoPopulatingListTests {
|
|||
String helloWorld = "Hello World!";
|
||||
list.add(10, null);
|
||||
list.add(11, helloWorld);
|
||||
assertThat(list).element(11).isEqualTo(helloWorld);
|
||||
assertThat(list).element(11, InstanceOfAssertFactories.STRING).isEqualTo(helloWorld);
|
||||
|
||||
boolean condition3 = list.get(10) instanceof TestObject;
|
||||
assertThat(condition3).isTrue();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -66,9 +66,7 @@ class CollectionUtilsTests {
|
|||
list.add("value3");
|
||||
|
||||
CollectionUtils.mergeArrayIntoCollection(arr, list);
|
||||
assertThat(list).element(0).isEqualTo("value3");
|
||||
assertThat(list).element(1).isEqualTo("value1");
|
||||
assertThat(list).element(2).isEqualTo("value2");
|
||||
assertThat(list).containsExactly("value3", "value1", "value2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -78,9 +76,7 @@ class CollectionUtilsTests {
|
|||
list.add(3);
|
||||
|
||||
CollectionUtils.mergeArrayIntoCollection(arr, list);
|
||||
assertThat(list).element(0).isEqualTo(3);
|
||||
assertThat(list).element(1).isEqualTo(1);
|
||||
assertThat(list).element(2).isEqualTo(2);
|
||||
assertThat(list).containsExactly(3, 1, 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -187,7 +187,7 @@ public abstract class AbstractDataBufferAllocatingTests {
|
|||
}
|
||||
|
||||
@AfterAll
|
||||
public static void closeAllocators() {
|
||||
static void closeAllocators() {
|
||||
netty5OnHeapUnpooled.close();
|
||||
netty5OffHeapUnpooled.close();
|
||||
netty5OnHeapPooled.close();
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ import java.util.Objects;
|
|||
import java.util.Properties;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.MethodParameter;
|
||||
|
|
@ -1374,11 +1375,8 @@ class SpelReproTests extends AbstractExpressionTests {
|
|||
SpelExpressionParser parser = new SpelExpressionParser();
|
||||
Expression expr = parser.parseExpression("new java.util.ArrayList(#root)");
|
||||
Object value = expr.getValue(coll);
|
||||
assertThat(value).isInstanceOf(ArrayList.class);
|
||||
@SuppressWarnings("rawtypes")
|
||||
ArrayList<?> list = (ArrayList) value;
|
||||
assertThat(list).element(0).isEqualTo("one");
|
||||
assertThat(list).element(1).isEqualTo("two");
|
||||
assertThat(value).isInstanceOf(ArrayList.class)
|
||||
.asInstanceOf(InstanceOfAssertFactories.list(String.class)).containsExactly("one", "two");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,8 +17,6 @@
|
|||
package org.springframework.expression.spel.support;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
|
@ -51,12 +49,9 @@ class StandardEvaluationContextTests {
|
|||
assertThat(target.getTypeLocator()).isSameAs(this.evaluationContext.getTypeLocator());
|
||||
assertThat(target.getTypeConverter()).isSameAs(this.evaluationContext.getTypeConverter());
|
||||
assertThat(target.getOperatorOverloader()).isSameAs(this.evaluationContext.getOperatorOverloader());
|
||||
assertThat(target.getPropertyAccessors()).satisfies(hasSameElements(
|
||||
this.evaluationContext.getPropertyAccessors()));
|
||||
assertThat(target.getConstructorResolvers()).satisfies(hasSameElements(
|
||||
this.evaluationContext.getConstructorResolvers()));
|
||||
assertThat(target.getMethodResolvers()).satisfies(hasSameElements(
|
||||
this.evaluationContext.getMethodResolvers()));
|
||||
assertThat(target.getPropertyAccessors()).hasSameElementsAs(this.evaluationContext.getPropertyAccessors());
|
||||
assertThat(target.getConstructorResolvers()).hasSameElementsAs(this.evaluationContext.getConstructorResolvers());
|
||||
assertThat(target.getMethodResolvers()).hasSameElementsAs(this.evaluationContext.getMethodResolvers());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -75,12 +70,9 @@ class StandardEvaluationContextTests {
|
|||
assertThat(target.getTypeLocator()).isSameAs(this.evaluationContext.getTypeLocator());
|
||||
assertThat(target.getTypeConverter()).isSameAs(this.evaluationContext.getTypeConverter());
|
||||
assertThat(target.getOperatorOverloader()).isSameAs(this.evaluationContext.getOperatorOverloader());
|
||||
assertThat(target.getPropertyAccessors()).satisfies(hasSameElements(
|
||||
this.evaluationContext.getPropertyAccessors()));
|
||||
assertThat(target.getConstructorResolvers()).satisfies(hasSameElements(
|
||||
this.evaluationContext.getConstructorResolvers()));
|
||||
assertThat(target.getMethodResolvers()).satisfies(hasSameElements(
|
||||
this.evaluationContext.getMethodResolvers()));
|
||||
assertThat(target.getPropertyAccessors()).hasSameElementsAs(this.evaluationContext.getPropertyAccessors());
|
||||
assertThat(target.getConstructorResolvers()).hasSameElementsAs(this.evaluationContext.getConstructorResolvers());
|
||||
assertThat(target.getMethodResolvers()).hasSameElementsAs(this.evaluationContext.getMethodResolvers());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -110,13 +102,4 @@ class StandardEvaluationContextTests {
|
|||
assertThat(target.getMethodResolvers()).doesNotContain(methodResolver);
|
||||
}
|
||||
|
||||
private Consumer<List<?>> hasSameElements(List<?> candidates) {
|
||||
return actual -> {
|
||||
assertThat(actual.size()).isEqualTo(candidates.size());
|
||||
for (int i = 0; i < candidates.size(); i++) {
|
||||
assertThat(candidates.get(i)).isSameAs(actual.get(i));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ class DestinationPatternsMessageConditionTests {
|
|||
@Test
|
||||
void prependNonEmptyPatternsOnly() {
|
||||
DestinationPatternsMessageCondition c = condition("");
|
||||
assertThat(c.getPatterns()).element(0).asString().isEmpty();
|
||||
assertThat(c.getPatterns()).containsOnly("");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class RSocketClientToServerIntegrationTests {
|
|||
}
|
||||
|
||||
@AfterAll
|
||||
public static void tearDownOnce() {
|
||||
static void tearDownOnce() {
|
||||
requester.rsocketClient().dispose();
|
||||
server.dispose();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -287,11 +287,8 @@ class MessageBrokerConfigurationTests {
|
|||
CompositeMessageConverter compositeConverter = config.brokerMessageConverter();
|
||||
|
||||
List<MessageConverter> converters = compositeConverter.getConverters();
|
||||
assertThat(converters).hasSize(4);
|
||||
assertThat(converters).element(0).isInstanceOf(StringMessageConverter.class);
|
||||
assertThat(converters).element(1).isInstanceOf(ByteArrayMessageConverter.class);
|
||||
assertThat(converters).element(2).isInstanceOf(KotlinSerializationJsonMessageConverter.class);
|
||||
assertThat(converters).element(3).isInstanceOf(MappingJackson2MessageConverter.class);
|
||||
assertThat(converters).hasExactlyElementsOfTypes(StringMessageConverter.class, ByteArrayMessageConverter.class,
|
||||
KotlinSerializationJsonMessageConverter.class, MappingJackson2MessageConverter.class);
|
||||
|
||||
ContentTypeResolver resolver = ((MappingJackson2MessageConverter) converters.get(3)).getContentTypeResolver();
|
||||
assertThat(((DefaultContentTypeResolver) resolver).getDefaultMimeType()).isEqualTo(MimeTypeUtils.APPLICATION_JSON);
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ public abstract class AbstractEntityManagerFactoryIntegrationTests {
|
|||
}
|
||||
|
||||
@AfterAll
|
||||
public static void closeContext() {
|
||||
static void closeContext() {
|
||||
if (applicationContext != null) {
|
||||
applicationContext.close();
|
||||
applicationContext = null;
|
||||
|
|
|
|||
|
|
@ -259,13 +259,11 @@ class MockHttpServletResponseTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void httpHeaderNameCasingIsPreserved() throws Exception {
|
||||
void httpHeaderNameCasingIsPreserved() {
|
||||
final String headerName = "Header1";
|
||||
response.addHeader(headerName, "value1");
|
||||
Collection<String> responseHeaders = response.getHeaderNames();
|
||||
assertThat(responseHeaders).isNotNull();
|
||||
assertThat(responseHeaders).hasSize(1);
|
||||
assertThat(responseHeaders).element(0).as("HTTP header casing not being preserved").isEqualTo(headerName);
|
||||
assertThat(responseHeaders).containsExactly(headerName);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -400,8 +398,8 @@ class MockHttpServletResponseTests {
|
|||
void addDateHeader() {
|
||||
response.addDateHeader(LAST_MODIFIED, 1437472800000L);
|
||||
response.addDateHeader(LAST_MODIFIED, 1437472801000L);
|
||||
assertThat(response.getHeaders(LAST_MODIFIED)).element(0).isEqualTo("Tue, 21 Jul 2015 10:00:00 GMT");
|
||||
assertThat(response.getHeaders(LAST_MODIFIED)).element(1).isEqualTo("Tue, 21 Jul 2015 10:00:01 GMT");
|
||||
assertThat(response.getHeaders(LAST_MODIFIED)).containsExactly(
|
||||
"Tue, 21 Jul 2015 10:00:00 GMT", "Tue, 21 Jul 2015 10:00:01 GMT");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -366,8 +366,7 @@ class MockHttpServletRequestBuilderTests {
|
|||
List<String> contentTypes = Collections.list(request.getHeaders("Content-Type"));
|
||||
|
||||
assertThat(contentType).isEqualTo("text/html");
|
||||
assertThat(contentTypes).hasSize(1);
|
||||
assertThat(contentTypes).element(0).isEqualTo("text/html");
|
||||
assertThat(contentTypes).containsExactly("text/html");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -379,8 +378,7 @@ class MockHttpServletRequestBuilderTests {
|
|||
List<String> contentTypes = Collections.list(request.getHeaders("Content-Type"));
|
||||
|
||||
assertThat(contentType).isEqualTo("text/html");
|
||||
assertThat(contentTypes).hasSize(1);
|
||||
assertThat(contentTypes).element(0).isEqualTo("text/html");
|
||||
assertThat(contentTypes).containsExactly("text/html");
|
||||
}
|
||||
|
||||
@Test // gh-2079
|
||||
|
|
@ -433,9 +431,7 @@ class MockHttpServletRequestBuilderTests {
|
|||
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
|
||||
List<String> headers = Collections.list(request.getHeaders("foo"));
|
||||
|
||||
assertThat(headers).hasSize(2);
|
||||
assertThat(headers).element(0).isEqualTo("bar");
|
||||
assertThat(headers).element(1).isEqualTo("baz");
|
||||
assertThat(headers).containsExactly("bar", "baz");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -448,9 +444,7 @@ class MockHttpServletRequestBuilderTests {
|
|||
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
|
||||
List<String> headers = Collections.list(request.getHeaders("foo"));
|
||||
|
||||
assertThat(headers).hasSize(2);
|
||||
assertThat(headers).element(0).isEqualTo("bar");
|
||||
assertThat(headers).element(1).isEqualTo("baz");
|
||||
assertThat(headers).containsExactly("bar", "baz");
|
||||
assertThat(request.getHeader("Content-Type")).isEqualTo(MediaType.APPLICATION_JSON.toString());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -167,10 +167,9 @@ class PrintingResultHandlerTests {
|
|||
|
||||
// Manually validate cookie values since maxAge changes...
|
||||
List<String> cookieValues = this.response.getHeaders("Set-Cookie");
|
||||
assertThat(cookieValues).hasSize(2);
|
||||
assertThat(cookieValues).element(0).isEqualTo("cookie=cookieValue");
|
||||
assertThat(cookieValues).element(1).asString().as("Actual: " + cookieValues.get(1))
|
||||
.startsWith("enigma=42; Path=/crumbs; Domain=.example.com; Max-Age=1234; Expires=");
|
||||
assertThat(cookieValues).satisfiesExactly(
|
||||
zero -> assertThat(zero).isEqualTo("cookie=cookieValue"),
|
||||
one -> assertThat(one).startsWith("enigma=42; Path=/crumbs; Domain=.example.com; Max-Age=1234; Expires="));
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("header", "headerValue");
|
||||
|
|
|
|||
|
|
@ -103,9 +103,7 @@ class InterceptingClientHttpRequestFactoryTests {
|
|||
@Override
|
||||
protected ClientHttpResponse executeInternal() {
|
||||
List<String> headerValues = getHeaders().get(headerName);
|
||||
assertThat(headerValues).hasSize(2);
|
||||
assertThat(headerValues).element(0).isEqualTo(headerValue);
|
||||
assertThat(headerValues).element(1).isEqualTo(otherValue);
|
||||
assertThat(headerValues).containsExactly(headerValue, otherValue);
|
||||
return responseMock;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -39,13 +39,13 @@ class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests {
|
|||
private static String originalPropertyValue;
|
||||
|
||||
@BeforeAll
|
||||
public static void setProperty() {
|
||||
static void setProperty() {
|
||||
originalPropertyValue = System.getProperty("jdk.httpclient.allowRestrictedHeaders");
|
||||
System.setProperty("jdk.httpclient.allowRestrictedHeaders", "expect");
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
public static void restoreProperty() {
|
||||
static void restoreProperty() {
|
||||
if (originalPropertyValue != null) {
|
||||
System.setProperty("jdk.httpclient.allowRestrictedHeaders", originalPropertyValue);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,10 +47,10 @@ class InterceptingHttpAccessorTests {
|
|||
|
||||
);
|
||||
accessor.setInterceptors(interceptors);
|
||||
|
||||
assertThat(accessor.getInterceptors()).element(0).isInstanceOf(FirstClientHttpRequestInterceptor.class);
|
||||
assertThat(accessor.getInterceptors()).element(1).isInstanceOf(SecondClientHttpRequestInterceptor.class);
|
||||
assertThat(accessor.getInterceptors()).element(2).isInstanceOf(ThirdClientHttpRequestInterceptor.class);
|
||||
assertThat(accessor.getInterceptors()).hasExactlyElementsOfTypes(
|
||||
FirstClientHttpRequestInterceptor.class,
|
||||
SecondClientHttpRequestInterceptor.class,
|
||||
ThirdClientHttpRequestInterceptor.class);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ class CookieIntegrationTests extends AbstractHttpHandlerIntegrationTests {
|
|||
RequestEntity.get(url).header("Cookie", header).build(), Void.class);
|
||||
|
||||
Map<String, List<HttpCookie>> requestCookies = this.cookieHandler.requestCookies;
|
||||
assertThat(requestCookies.size()).isEqualTo(2);
|
||||
assertThat(requestCookies).hasSize(2);
|
||||
assertThat(requestCookies.get("SID")).extracting(HttpCookie::getValue).containsExactly("31d4d96e407aad42");
|
||||
assertThat(requestCookies.get("lang")).extracting(HttpCookie::getValue).containsExactly("en-US", "zh-CN");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,8 +64,7 @@ class ListenerWriteProcessorTests {
|
|||
this.processor.onError(new IllegalStateException());
|
||||
|
||||
assertThat(this.resultSubscriber.getError()).as("Error should flow to result publisher").isNotNull();
|
||||
assertThat(this.processor.getDiscardedBuffers()).hasSize(1);
|
||||
assertThat(this.processor.getDiscardedBuffers()).element(0).isSameAs(buffer);
|
||||
assertThat(this.processor.getDiscardedBuffers()).containsExactly(buffer);
|
||||
}
|
||||
|
||||
@Test // SPR-17410
|
||||
|
|
@ -80,8 +79,7 @@ class ListenerWriteProcessorTests {
|
|||
this.processor.onNext(buffer);
|
||||
|
||||
assertThat(this.resultSubscriber.getError()).as("Error should flow to result publisher").isNotNull();
|
||||
assertThat(this.processor.getDiscardedBuffers()).hasSize(1);
|
||||
assertThat(this.processor.getDiscardedBuffers()).element(0).isSameAs(buffer);
|
||||
assertThat(this.processor.getDiscardedBuffers()).containsExactly(buffer);
|
||||
}
|
||||
|
||||
@Test // SPR-17410
|
||||
|
|
@ -97,9 +95,7 @@ class ListenerWriteProcessorTests {
|
|||
this.processor.onNext(buffer2);
|
||||
|
||||
assertThat(this.resultSubscriber.getError()).as("Error should flow to result publisher").isNotNull();
|
||||
assertThat(this.processor.getDiscardedBuffers()).hasSize(2);
|
||||
assertThat(this.processor.getDiscardedBuffers()).element(0).isSameAs(buffer2);
|
||||
assertThat(this.processor.getDiscardedBuffers()).element(1).isSameAs(buffer1);
|
||||
assertThat(this.processor.getDiscardedBuffers()).containsExactly(buffer2, buffer1);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -68,8 +68,7 @@ class StandardServletAsyncWebRequestTests {
|
|||
MockAsyncContext context = (MockAsyncContext) this.request.getAsyncContext();
|
||||
assertThat(context).isNotNull();
|
||||
assertThat(context.getTimeout()).as("Timeout value not set").isEqualTo((44 * 1000));
|
||||
assertThat(context.getListeners()).hasSize(1);
|
||||
assertThat(context.getListeners()).element(0).isSameAs(this.asyncRequest);
|
||||
assertThat(context.getListeners()).containsExactly(this.asyncRequest);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -146,11 +146,8 @@ class RequestParamMapMethodArgumentResolverTests {
|
|||
assertThat(condition).isTrue();
|
||||
MultiValueMap<String, MultipartFile> resultMap = (MultiValueMap<String, MultipartFile>) result;
|
||||
assertThat(resultMap).hasSize(2);
|
||||
assertThat(resultMap.get("mfilelist")).hasSize(2);
|
||||
assertThat(resultMap.get("mfilelist")).element(0).isEqualTo(expected1);
|
||||
assertThat(resultMap.get("mfilelist")).element(1).isEqualTo(expected2);
|
||||
assertThat(resultMap.get("other")).hasSize(1);
|
||||
assertThat(resultMap.get("other")).element(0).isEqualTo(expected3);
|
||||
assertThat(resultMap.get("mfilelist")).containsExactly(expected1, expected2);
|
||||
assertThat(resultMap.get("other")).containsExactly(expected3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -195,11 +192,8 @@ class RequestParamMapMethodArgumentResolverTests {
|
|||
assertThat(condition).isTrue();
|
||||
MultiValueMap<String, Part> resultMap = (MultiValueMap<String, Part>) result;
|
||||
assertThat(resultMap).hasSize(2);
|
||||
assertThat(resultMap.get("mfilelist")).hasSize(2);
|
||||
assertThat(resultMap.get("mfilelist")).element(0).isEqualTo(expected1);
|
||||
assertThat(resultMap.get("mfilelist")).element(1).isEqualTo(expected2);
|
||||
assertThat(resultMap.get("other")).hasSize(1);
|
||||
assertThat(resultMap.get("other")).element(0).isEqualTo(expected3);
|
||||
assertThat(resultMap.get("mfilelist")).containsExactly(expected1, expected2);
|
||||
assertThat(resultMap.get("other")).containsExactly(expected3);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import java.util.Map;
|
|||
import java.util.Optional;
|
||||
|
||||
import jakarta.servlet.http.Part;
|
||||
import org.assertj.core.api.InstanceOfAssertFactories;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
|
||||
|
|
@ -378,9 +379,8 @@ class RequestParamMethodArgumentResolverTests {
|
|||
.annotNotPresent(RequestParam.class).arg(List.class, MultipartFile.class);
|
||||
|
||||
Object actual = resolver.resolveArgument(param, null, webRequest, null);
|
||||
boolean condition = actual instanceof List;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(((List<?>) actual)).element(0).isEqualTo(expected);
|
||||
assertThat(actual).isInstanceOf(List.class).asInstanceOf(InstanceOfAssertFactories.LIST)
|
||||
.containsExactly(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -138,19 +138,15 @@ class ResourceHandlerRegistryTests {
|
|||
this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);
|
||||
|
||||
ResourceWebHandler handler = getHandler("/resources/**");
|
||||
List<ResourceResolver> resolvers = handler.getResourceResolvers();
|
||||
assertThat(resolvers).hasSize(4);
|
||||
assertThat(resolvers).element(0).isInstanceOf(CachingResourceResolver.class);
|
||||
CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
|
||||
assertThat(cachingResolver.getCache()).isInstanceOf(ConcurrentMapCache.class);
|
||||
assertThat(resolvers).element(1).isEqualTo(mockResolver);
|
||||
assertThat(resolvers).element(2).isInstanceOf(WebJarsResourceResolver.class);
|
||||
assertThat(resolvers).element(3).isInstanceOf(PathResourceResolver.class);
|
||||
|
||||
List<ResourceTransformer> transformers = handler.getResourceTransformers();
|
||||
assertThat(transformers).hasSize(2);
|
||||
assertThat(transformers.get(0)).isInstanceOf(CachingResourceTransformer.class);
|
||||
assertThat(transformers.get(1)).isEqualTo(mockTransformer);
|
||||
assertThat(handler.getResourceResolvers()).satisfiesExactly(
|
||||
zero -> assertThat(zero).isInstanceOfSatisfying(CachingResourceResolver.class,
|
||||
cachingResolver -> assertThat(cachingResolver.getCache()).isInstanceOf(ConcurrentMapCache.class)),
|
||||
one -> assertThat(one).isEqualTo(mockResolver),
|
||||
two -> assertThat(two).isInstanceOf(WebJarsResourceResolver.class),
|
||||
three -> assertThat(three).isInstanceOf(PathResourceResolver.class));
|
||||
assertThat(handler.getResourceTransformers()).satisfiesExactly(
|
||||
zero -> assertThat(zero).isInstanceOf(CachingResourceTransformer.class),
|
||||
one -> assertThat(one).isEqualTo(mockTransformer));
|
||||
Mockito.verify(mockTransformer).setResourceUrlProvider(resourceUrlProvider);
|
||||
}
|
||||
|
||||
|
|
@ -159,13 +155,9 @@ class ResourceHandlerRegistryTests {
|
|||
this.registration.resourceChain(false);
|
||||
|
||||
ResourceWebHandler handler = getHandler("/resources/**");
|
||||
List<ResourceResolver> resolvers = handler.getResourceResolvers();
|
||||
assertThat(resolvers).hasSize(2);
|
||||
assertThat(resolvers).element(0).isInstanceOf(WebJarsResourceResolver.class);
|
||||
assertThat(resolvers).element(1).isInstanceOf(PathResourceResolver.class);
|
||||
|
||||
List<ResourceTransformer> transformers = handler.getResourceTransformers();
|
||||
assertThat(transformers).isEmpty();
|
||||
assertThat(handler.getResourceResolvers()).hasExactlyElementsOfTypes(
|
||||
WebJarsResourceResolver.class, PathResourceResolver.class);
|
||||
assertThat(handler.getResourceTransformers()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -177,17 +169,13 @@ class ResourceHandlerRegistryTests {
|
|||
this.registration.resourceChain(true).addResolver(versionResolver);
|
||||
|
||||
ResourceWebHandler handler = getHandler("/resources/**");
|
||||
List<ResourceResolver> resolvers = handler.getResourceResolvers();
|
||||
assertThat(resolvers).hasSize(4);
|
||||
assertThat(resolvers).element(0).isInstanceOf(CachingResourceResolver.class);
|
||||
assertThat(resolvers).element(1).isSameAs(versionResolver);
|
||||
assertThat(resolvers).element(2).isInstanceOf(WebJarsResourceResolver.class);
|
||||
assertThat(resolvers).element(3).isInstanceOf(PathResourceResolver.class);
|
||||
|
||||
List<ResourceTransformer> transformers = handler.getResourceTransformers();
|
||||
assertThat(transformers).hasSize(2);
|
||||
assertThat(transformers).element(0).isInstanceOf(CachingResourceTransformer.class);
|
||||
assertThat(transformers).element(1).isInstanceOf(CssLinkResourceTransformer.class);
|
||||
assertThat(handler.getResourceResolvers()).satisfiesExactly(
|
||||
zero -> assertThat(zero).isInstanceOf(CachingResourceResolver.class),
|
||||
one -> assertThat(one).isSameAs(versionResolver),
|
||||
two -> assertThat(two).isInstanceOf(WebJarsResourceResolver.class),
|
||||
three -> assertThat(three).isInstanceOf(PathResourceResolver.class));
|
||||
assertThat(handler.getResourceTransformers()).hasExactlyElementsOfTypes(
|
||||
CachingResourceTransformer.class, CssLinkResourceTransformer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -88,8 +88,7 @@ class ViewResolverRegistryTests {
|
|||
View view = new HttpMessageWriterView(new Jackson2JsonEncoder());
|
||||
this.registry.defaultViews(view);
|
||||
|
||||
assertThat(this.registry.getDefaultViews()).hasSize(1);
|
||||
assertThat(this.registry.getDefaultViews()).element(0).isSameAs(view);
|
||||
assertThat(this.registry.getDefaultViews()).containsExactly(view);
|
||||
}
|
||||
|
||||
@Test // SPR-16431
|
||||
|
|
|
|||
|
|
@ -67,7 +67,6 @@ import org.springframework.web.reactive.result.method.annotation.RequestMappingH
|
|||
import org.springframework.web.reactive.result.method.annotation.ResponseBodyResultHandler;
|
||||
import org.springframework.web.reactive.result.method.annotation.ResponseEntityResultHandler;
|
||||
import org.springframework.web.reactive.result.view.HttpMessageWriterView;
|
||||
import org.springframework.web.reactive.result.view.View;
|
||||
import org.springframework.web.reactive.result.view.ViewResolutionResultHandler;
|
||||
import org.springframework.web.reactive.result.view.ViewResolver;
|
||||
import org.springframework.web.reactive.result.view.freemarker.FreeMarkerConfigurer;
|
||||
|
|
@ -259,11 +258,9 @@ class WebFluxConfigurationSupportTests {
|
|||
assertThat(resolvers).hasSize(1);
|
||||
assertThat(resolvers.get(0).getClass()).isEqualTo(FreeMarkerViewResolver.class);
|
||||
|
||||
List<View> views = handler.getDefaultViews();
|
||||
assertThat(views).hasSize(1);
|
||||
|
||||
MimeType type = MimeTypeUtils.parseMimeType("application/json");
|
||||
assertThat(views.get(0).getSupportedMediaTypes()).element(0).isEqualTo(type);
|
||||
assertThat(handler.getDefaultViews()).singleElement().satisfies(view ->
|
||||
assertThat(view.getSupportedMediaTypes()).element(0).isEqualTo(type));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -255,29 +255,22 @@ class MultipartRouterFunctionIntegrationTests extends AbstractRouterFunctionInte
|
|||
.collectList()
|
||||
.flatMap((List<List<PartEvent>> data) -> {
|
||||
assertThat(data).hasSize(2);
|
||||
|
||||
List<PartEvent> fileData = data.get(0);
|
||||
assertThat(fileData).hasSize(2);
|
||||
assertThat(fileData).element(0).isInstanceOf(FilePartEvent.class);
|
||||
FilePartEvent filePartEvent = (FilePartEvent) fileData.get(0);
|
||||
assertThat(filePartEvent.name()).isEqualTo("fooPart");
|
||||
assertThat(filePartEvent.filename()).isEqualTo("foo.txt");
|
||||
DataBufferUtils.release(filePartEvent.content());
|
||||
|
||||
assertThat(fileData).element(1).isInstanceOf(FilePartEvent.class);
|
||||
filePartEvent = (FilePartEvent) fileData.get(1);
|
||||
assertThat(filePartEvent.name()).isEqualTo("fooPart");
|
||||
assertThat(filePartEvent.filename()).isEqualTo("foo.txt");
|
||||
DataBufferUtils.release(filePartEvent.content());
|
||||
|
||||
List<PartEvent> fieldData = data.get(1);
|
||||
assertThat(fieldData).hasSize(1);
|
||||
assertThat(fieldData).element(0).isInstanceOf(FormPartEvent.class);
|
||||
FormPartEvent formPartEvent = (FormPartEvent) fieldData.get(0);
|
||||
assertThat(formPartEvent.name()).isEqualTo("barPart");
|
||||
assertThat(formPartEvent.content().toString(StandardCharsets.UTF_8)).isEqualTo("bar");
|
||||
DataBufferUtils.release(filePartEvent.content());
|
||||
|
||||
assertThat(data.get(0)).satisfiesExactly(
|
||||
zero -> assertThat(zero).isInstanceOfSatisfying(FilePartEvent.class, filePartEvent -> {
|
||||
assertThat(filePartEvent.name()).isEqualTo("fooPart");
|
||||
assertThat(filePartEvent.filename()).isEqualTo("foo.txt");
|
||||
DataBufferUtils.release(filePartEvent.content());
|
||||
}),
|
||||
one -> assertThat(one).isInstanceOfSatisfying(FilePartEvent.class, filePartEvent -> {
|
||||
assertThat(filePartEvent.name()).isEqualTo("fooPart");
|
||||
assertThat(filePartEvent.filename()).isEqualTo("foo.txt");
|
||||
DataBufferUtils.release(filePartEvent.content());
|
||||
}));
|
||||
assertThat(data.get(1)).singleElement().isInstanceOfSatisfying(FormPartEvent.class, formPartEvent -> {
|
||||
assertThat(formPartEvent.name()).isEqualTo("barPart");
|
||||
assertThat(formPartEvent.content().toString(StandardCharsets.UTF_8)).isEqualTo("bar");
|
||||
DataBufferUtils.release(formPartEvent.content());
|
||||
});
|
||||
return ServerResponse.ok().build();
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -113,8 +113,8 @@ class ProtobufIntegrationTests extends AbstractRequestMappingIntegrationTests {
|
|||
.uri("/message-stream")
|
||||
.exchangeToFlux(response -> {
|
||||
assertThat(response.headers().contentType().get().getParameters().get("delimited")).isEqualTo("true");
|
||||
assertThat(response.headers().header("X-Protobuf-Schema")).element(0).isEqualTo("sample.proto");
|
||||
assertThat(response.headers().header("X-Protobuf-Message")).element(0).isEqualTo("Msg");
|
||||
assertThat(response.headers().header("X-Protobuf-Schema")).containsExactly("sample.proto");
|
||||
assertThat(response.headers().header("X-Protobuf-Message")).containsExactly("Msg");
|
||||
return response.bodyToFlux(Msg.class);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class RequestMappingHandlerAdapterTests {
|
|||
|
||||
|
||||
@BeforeAll
|
||||
public static void setupOnce() {
|
||||
static void setupOnce() {
|
||||
RequestMappingHandlerAdapter adapter = new RequestMappingHandlerAdapter();
|
||||
adapter.setApplicationContext(new StaticWebApplicationContext());
|
||||
adapter.afterPropertiesSet();
|
||||
|
|
|
|||
Loading…
Reference in New Issue