Add support to @ClassPathExclusions for excluding packages
Closes gh-36120
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2021 the original author or authors.
|
||||
* Copyright 2012-2023 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.
|
||||
@@ -19,6 +19,8 @@ package org.springframework.boot.testsupport.classpath;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.isA;
|
||||
|
||||
@@ -26,22 +28,34 @@ import static org.hamcrest.Matchers.isA;
|
||||
* Tests for {@link ModifiedClassPathExtension} excluding entries from the class path.
|
||||
*
|
||||
* @author Christoph Dreis
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@ClassPathExclusions("hibernate-validator-*.jar")
|
||||
@ClassPathExclusions(files = "hibernate-validator-*.jar", packages = "java.net.http")
|
||||
class ModifiedClassPathExtensionExclusionsTests {
|
||||
|
||||
private static final String EXCLUDED_RESOURCE = "META-INF/services/jakarta.validation.spi.ValidationProvider";
|
||||
|
||||
@Test
|
||||
void entriesAreFilteredFromTestClassClassLoader() {
|
||||
void fileExclusionsAreFilteredFromTestClassClassLoader() {
|
||||
assertThat(getClass().getClassLoader().getResource(EXCLUDED_RESOURCE)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void entriesAreFilteredFromThreadContextClassLoader() {
|
||||
void fileExclusionsAreFilteredFromThreadContextClassLoader() {
|
||||
assertThat(Thread.currentThread().getContextClassLoader().getResource(EXCLUDED_RESOURCE)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void packageExclusionsAreFilteredFromTestClassClassLoader() {
|
||||
assertThat(ClassUtils.isPresent("java.net.http.HttpClient", getClass().getClassLoader())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void packageExclusionsAreFilteredFromThreadContextClassLoader() {
|
||||
assertThat(ClassUtils.isPresent("java.net.http.HttpClient", Thread.currentThread().getContextClassLoader()))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testsThatUseHamcrestWorkCorrectly() {
|
||||
Matcher<IllegalStateException> matcher = isA(IllegalStateException.class);
|
||||
|
||||
Reference in New Issue
Block a user