@ -18,7 +18,6 @@ package org.springframework.aot.hint.predicate;
import java.util.function.Predicate ;
import java.util.function.Predicate ;
import org.junit.jupiter.api.BeforeEach ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.api.Test ;
import org.springframework.aot.hint.RuntimeHints ;
import org.springframework.aot.hint.RuntimeHints ;
@ -30,40 +29,54 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for { @link ReflectionHintsPredicates } .
* Tests for { @link ReflectionHintsPredicates } .
*
*
* @author Brian Clozel
* @author Brian Clozel
* @author Sam Brannen
* /
* /
class ResourceHintsPredicatesTests {
class ResourceHintsPredicatesTests {
private final ResourceHintsPredicates resources = new ResourceHintsPredicates ( ) ;
private final ResourceHintsPredicates resources = new ResourceHintsPredicates ( ) ;
private RuntimeHints runtimeHints ;
private final RuntimeHints runtimeHints = new RuntimeHints ( ) ;
@BeforeEach
void setup ( ) {
this . runtimeHints = new RuntimeHints ( ) ;
}
@Test
@Test
void resourcePatternMatchesResourceName ( ) {
void resourcePatternMatchesResourceName ( ) {
this . runtimeHints . resources ( ) . registerPattern ( "/ test/*" ) ;
this . runtimeHints . resources ( ) . registerPattern ( "test/*" ) ;
assertPredicateMatches ( resources . forResource ( "/test/spring.properties" ) ) ;
assertPredicateMatches ( resources . forResource ( "/test/spring.properties" ) ) ;
}
}
@Test
@Test
void resourcePatternDoesNotMatchResourceName ( ) {
void resourcePatternDoesNotMatchResourceName ( ) {
this . runtimeHints . resources ( ) . registerPattern ( "/ test/spring.*" ) ;
this . runtimeHints . resources ( ) . registerPattern ( "test/spring.*" ) ;
assertPredicateDoesNotMatch ( resources . forResource ( "/test/other.properties" ) ) ;
assertPredicateDoesNotMatch ( resources . forResource ( "/test/other.properties" ) ) ;
}
}
@Test
@Test
void resourcePatternMatchesTypeAndResourceName ( ) {
void resourcePatternMatchesTypeAndResourceName ( ) {
this . runtimeHints . resources ( ) . registerPattern ( "/ org/springframework/aot/hint/predicate/spring.*" ) ;
this . runtimeHints . resources ( ) . registerPattern ( "org/springframework/aot/hint/predicate/spring.*" ) ;
assertPredicateMatches ( resources . forResource ( TypeReference . of ( getClass ( ) ) , "spring.properties" ) ) ;
assertPredicateMatches ( resources . forResource ( TypeReference . of ( getClass ( ) ) , "spring.properties" ) ) ;
}
}
@Test
void resourcePatternMatchesTypeAndAbsoluteResourceName ( ) {
this . runtimeHints . resources ( ) . registerPattern ( "spring.*" ) ;
assertPredicateMatches ( resources . forResource ( TypeReference . of ( getClass ( ) ) , "/spring.properties" ) ) ;
}
@Test
void resourcePatternMatchesTypeInDefaultPackageAndResourceName ( ) {
this . runtimeHints . resources ( ) . registerPattern ( "spring.*" ) ;
assertPredicateMatches ( resources . forResource ( TypeReference . of ( "DummyClass" ) , "spring.properties" ) ) ;
}
@Test
void resourcePatternMatchesTypeInDefaultPackageAndAbsoluteResourceName ( ) {
this . runtimeHints . resources ( ) . registerPattern ( "spring.*" ) ;
assertPredicateMatches ( resources . forResource ( TypeReference . of ( "DummyClass" ) , "/spring.properties" ) ) ;
}
@Test
@Test
void resourcePatternDoesNotMatchTypeAndResourceName ( ) {
void resourcePatternDoesNotMatchTypeAndResourceName ( ) {
this . runtimeHints . resources ( ) . registerPattern ( "/spring.*" ) ;
this . runtimeHints . resources ( ) . registerPattern ( "spring.*" ) ;
assertPredicateDoesNotMatch ( resources . forResource ( TypeReference . of ( getClass ( ) ) , "spring.properties" ) ) ;
assertPredicateDoesNotMatch ( resources . forResource ( TypeReference . of ( getClass ( ) ) , "spring.properties" ) ) ;
}
}
@ -81,11 +94,11 @@ class ResourceHintsPredicatesTests {
private void assertPredicateMatches ( Predicate < RuntimeHints > predicate ) {
private void assertPredicateMatches ( Predicate < RuntimeHints > predicate ) {
assertThat ( predicate . test ( this . runtimeHints ) ) . isTrue ( ) ;
assertThat ( predicate ) . accepts ( this . runtimeHints ) ;
}
}
private void assertPredicateDoesNotMatch ( Predicate < RuntimeHints > predicate ) {
private void assertPredicateDoesNotMatch ( Predicate < RuntimeHints > predicate ) {
assertThat ( predicate . test ( this . runtimeHints ) ) . isFalse ( ) ;
assertThat ( predicate ) . rejects ( this . runtimeHints ) ;
}
}
}
}