Merge branch '6.0.x'

# Conflicts:
#	spring-context/src/test/java/org/springframework/jmx/export/MBeanExporterTests.java
This commit is contained in:
Sam Brannen 2023-06-25 15:34:10 +02:00
commit 9127777c32
3 changed files with 25 additions and 22 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2022 the original author or authors. * Copyright 2002-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -19,9 +19,9 @@ package org.springframework.aop.config;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader; import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifiedResource; import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifiedResource;
@ -29,25 +29,28 @@ import static org.springframework.core.testfixture.io.ResourceTestUtils.qualifie
/** /**
* @author Mark Fisher * @author Mark Fisher
* @author Chris Beams * @author Chris Beams
* @author Sam Brannen
*/ */
class AopNamespaceHandlerPointcutErrorTests { class AopNamespaceHandlerPointcutErrorTests {
@Test @Test
void duplicatePointcutConfig() { void duplicatePointcutConfig() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
new XmlBeanDefinitionReader(bf).loadBeanDefinitions( ClassPathResource resource = qualifiedResource(getClass(), "pointcutDuplication.xml");
qualifiedResource(getClass(), "pointcutDuplication.xml")))
.satisfies(ex -> ex.contains(BeanDefinitionParsingException.class)); assertThatExceptionOfType(BeanDefinitionStoreException.class)
.isThrownBy(() -> reader.loadBeanDefinitions(resource));
} }
@Test @Test
void missingPointcutConfig() { void missingPointcutConfig() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
new XmlBeanDefinitionReader(bf).loadBeanDefinitions( ClassPathResource resource = qualifiedResource(getClass(), "pointcutMissing.xml");
qualifiedResource(getClass(), "pointcutMissing.xml")))
.satisfies(ex -> ex.contains(BeanDefinitionParsingException.class)); assertThatExceptionOfType(BeanDefinitionStoreException.class)
.isThrownBy(() -> reader.loadBeanDefinitions(resource));
} }
} }

View File

@ -166,9 +166,9 @@ public class ClassPathXmlApplicationContextTests {
void contextWithInvalidLazyClass() { void contextWithInvalidLazyClass() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(INVALID_CLASS_CONTEXT, getClass()); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(INVALID_CLASS_CONTEXT, getClass());
assertThat(ctx.containsBean("someMessageSource")).isTrue(); assertThat(ctx.containsBean("someMessageSource")).isTrue();
assertThatExceptionOfType(CannotLoadBeanClassException.class).isThrownBy(() -> assertThatExceptionOfType(CannotLoadBeanClassException.class)
ctx.getBean("someMessageSource")) .isThrownBy(() -> ctx.getBean("someMessageSource"))
.satisfies(ex -> assertThat(ex.contains(ClassNotFoundException.class)).isTrue()); .withCauseExactlyInstanceOf(ClassNotFoundException.class);
ctx.close(); ctx.close();
} }
@ -176,8 +176,7 @@ public class ClassPathXmlApplicationContextTests {
void contextWithClassNameThatContainsPlaceholder() { void contextWithClassNameThatContainsPlaceholder() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CLASS_WITH_PLACEHOLDER_CONTEXT, getClass()); ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(CLASS_WITH_PLACEHOLDER_CONTEXT, getClass());
assertThat(ctx.containsBean("someMessageSource")).isTrue(); assertThat(ctx.containsBean("someMessageSource")).isTrue();
boolean condition = ctx.getBean("someMessageSource") instanceof StaticMessageSource; assertThat(ctx.getBean("someMessageSource")).isInstanceOf(StaticMessageSource.class);
assertThat(condition).isTrue();
ctx.close(); ctx.close();
} }

View File

@ -84,8 +84,8 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
listeners.put("*", null); listeners.put("*", null);
MBeanExporter exporter = new MBeanExporter(); MBeanExporter exporter = new MBeanExporter();
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException()
exporter.setNotificationListenerMappings(listeners)); .isThrownBy(() -> exporter.setNotificationListenerMappings(listeners));
} }
@Test @Test
@ -100,9 +100,10 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
exporter.setBeans(getBeanMap()); exporter.setBeans(getBeanMap());
exporter.setServer(server); exporter.setServer(server);
exporter.setNotificationListenerMappings(listeners); exporter.setNotificationListenerMappings(listeners);
assertThatExceptionOfType(MBeanExportException.class).as("NotificationListener on a non-existent MBean").isThrownBy(() -> assertThatExceptionOfType(MBeanExportException.class)
start(exporter)) .as("NotificationListener on a non-existent MBean")
.satisfies(ex -> assertThat(ex.contains(InstanceNotFoundException.class)).isTrue()); .isThrownBy(() -> start(exporter))
.withCauseExactlyInstanceOf(InstanceNotFoundException.class);
} }
@Test @Test
@ -165,8 +166,8 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true")); ObjectInstance instance = server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=true"));
assertThat(instance).isNotNull(); assertThat(instance).isNotNull();
assertThatExceptionOfType(InstanceNotFoundException.class).isThrownBy(() -> assertThatExceptionOfType(InstanceNotFoundException.class)
server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false"))); .isThrownBy(() -> server.getObjectInstance(ObjectNameManager.getInstance("spring:mbean=false")));
} }
} }