1
1
/*
2
- * Copyright 2002-2024 the original author or authors.
2
+ * Copyright 2002-2025 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -45,8 +45,9 @@ class ContextAotProcessorTests {
45
45
void processGeneratesAssets (@ TempDir Path directory ) {
46
46
GenericApplicationContext context = new AnnotationConfigApplicationContext ();
47
47
context .registerBean (SampleApplication .class );
48
- ContextAotProcessor processor = new DemoContextAotProcessor (SampleApplication .class , directory );
48
+ DemoContextAotProcessor processor = new DemoContextAotProcessor (SampleApplication .class , directory );
49
49
ClassName className = processor .process ();
50
+ assertThat (processor .context .isClosed ()).isTrue ();
50
51
assertThat (className ).isEqualTo (ClassName .get (SampleApplication .class .getPackageName (),
51
52
"ContextAotProcessorTests_SampleApplication__ApplicationContextInitializer" ));
52
53
assertThat (directory ).satisfies (hasGeneratedAssetsForSampleApplication ());
@@ -61,9 +62,10 @@ void processingDeletesExistingOutput(@TempDir Path directory) throws IOException
61
62
Path existingSourceOutput = createExisting (sourceOutput );
62
63
Path existingResourceOutput = createExisting (resourceOutput );
63
64
Path existingClassOutput = createExisting (classOutput );
64
- ContextAotProcessor processor = new DemoContextAotProcessor (SampleApplication .class ,
65
+ DemoContextAotProcessor processor = new DemoContextAotProcessor (SampleApplication .class ,
65
66
sourceOutput , resourceOutput , classOutput );
66
67
processor .process ();
68
+ assertThat (processor .context .isClosed ()).isTrue ();
67
69
assertThat (existingSourceOutput ).doesNotExist ();
68
70
assertThat (existingResourceOutput ).doesNotExist ();
69
71
assertThat (existingClassOutput ).doesNotExist ();
@@ -73,13 +75,14 @@ void processingDeletesExistingOutput(@TempDir Path directory) throws IOException
73
75
void processWithEmptyNativeImageArgumentsDoesNotCreateNativeImageProperties (@ TempDir Path directory ) {
74
76
GenericApplicationContext context = new AnnotationConfigApplicationContext ();
75
77
context .registerBean (SampleApplication .class );
76
- ContextAotProcessor processor = new DemoContextAotProcessor (SampleApplication .class , directory ) {
78
+ DemoContextAotProcessor processor = new DemoContextAotProcessor (SampleApplication .class , directory ) {
77
79
@ Override
78
80
protected List <String > getDefaultNativeImageArguments (String application ) {
79
81
return Collections .emptyList ();
80
82
}
81
83
};
82
84
processor .process ();
85
+ assertThat (processor .context .isClosed ()).isTrue ();
83
86
assertThat (directory .resolve ("resource/META-INF/native-image/com.example/example/native-image.properties" ))
84
87
.doesNotExist ();
85
88
context .close ();
@@ -118,6 +121,8 @@ private Consumer<Path> hasGeneratedAssetsForSampleApplication() {
118
121
119
122
private static class DemoContextAotProcessor extends ContextAotProcessor {
120
123
124
+ AnnotationConfigApplicationContext context ;
125
+
121
126
DemoContextAotProcessor (Class <?> application , Path rootPath ) {
122
127
this (application , rootPath .resolve ("source" ), rootPath .resolve ("resource" ), rootPath .resolve ("class" ));
123
128
}
@@ -141,19 +146,19 @@ private static Settings createSettings(Path sourceOutput, Path resourceOutput,
141
146
protected GenericApplicationContext prepareApplicationContext (Class <?> application ) {
142
147
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext ();
143
148
context .register (application );
149
+ this .context = context ;
144
150
return context ;
145
151
}
146
-
147
152
}
148
153
154
+
149
155
@ Configuration (proxyBeanMethods = false )
150
156
static class SampleApplication {
151
157
152
158
@ Bean
153
159
public String testBean () {
154
160
return "Hello" ;
155
161
}
156
-
157
162
}
158
163
159
164
}
0 commit comments