30
30
import org .springframework .core .testfixture .aot .generate .TestGenerationContext ;
31
31
32
32
import static org .assertj .core .api .Assertions .assertThat ;
33
+ import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
33
34
34
35
/**
35
36
* Tests for {@link GeneratedClassHandler}.
@@ -50,23 +51,40 @@ public GeneratedClassHandlerTests() {
50
51
}
51
52
52
53
@ Test
53
- void handlerGenerateRuntimeHints () {
54
- String className = "com.example.Test$$Proxy$$1 " ;
54
+ void handlerGenerateRuntimeHintsForProxy () {
55
+ String className = "com.example.Test$$SpringCGLIB$$0 " ;
55
56
this .handler .accept (className , TEST_CONTENT );
56
57
assertThat (RuntimeHintsPredicates .reflection ().onType (TypeReference .of (className ))
57
58
.withMemberCategories (MemberCategory .INVOKE_DECLARED_CONSTRUCTORS ,
58
59
MemberCategory .INVOKE_DECLARED_METHODS , MemberCategory .DECLARED_FIELDS ))
59
60
.accepts (this .generationContext .getRuntimeHints ());
60
61
}
61
62
63
+ @ Test
64
+ void handlerGenerateRuntimeHintsForTargetType () {
65
+ String className = "com.example.Test$$SpringCGLIB$$0" ;
66
+ this .handler .accept (className , TEST_CONTENT );
67
+ assertThat (RuntimeHintsPredicates .reflection ().onType (TypeReference .of ("com.example.Test" ))
68
+ .withMemberCategories (MemberCategory .INTROSPECT_DECLARED_CONSTRUCTORS ,
69
+ MemberCategory .INVOKE_DECLARED_METHODS ))
70
+ .accepts (this .generationContext .getRuntimeHints ());
71
+ }
72
+
73
+ @ Test
74
+ void handlerFailsWithInvalidProxyClassName () {
75
+ String className = "com.example.Test$$AnotherProxy$$0" ;
76
+ assertThatIllegalArgumentException ().isThrownBy (() -> this .handler .accept (className , TEST_CONTENT ))
77
+ .withMessageContaining ("Failed to extract target type" );
78
+ }
79
+
62
80
@ Test
63
81
void handlerRegisterGeneratedClass () throws IOException {
64
- String className = "com.example.Test$$Proxy$$1 " ;
82
+ String className = "com.example.Test$$SpringCGLIB$$0 " ;
65
83
this .handler .accept (className , TEST_CONTENT );
66
84
InMemoryGeneratedFiles generatedFiles = this .generationContext .getGeneratedFiles ();
67
85
assertThat (generatedFiles .getGeneratedFiles (Kind .SOURCE )).isEmpty ();
68
86
assertThat (generatedFiles .getGeneratedFiles (Kind .RESOURCE )).isEmpty ();
69
- String expectedPath = "com/example/Test$$Proxy$$1 .class" ;
87
+ String expectedPath = "com/example/Test$$SpringCGLIB$$0 .class" ;
70
88
assertThat (generatedFiles .getGeneratedFiles (Kind .CLASS )).containsOnlyKeys (expectedPath );
71
89
assertContent (generatedFiles .getGeneratedFiles (Kind .CLASS ).get (expectedPath ), TEST_CONTENT );
72
90
}
0 commit comments