Skip to content

Commit 467a30c

Browse files
Merge pull request diffblue#522 from diffblue/feature/di-return-applicationContext
Add ApplicationContextBean to return synthetic application context [SEC-587]
2 parents 6aa36b9 + a8fd2c9 commit 467a30c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

env-model-generator/src/model.ts

+37
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,43 @@ export class UndefinedBean implements IBean {
213213
public readonly exceptions: string[] = [];
214214
}
215215

216+
export class ApplicationContextBean implements IBean {
217+
private static readonly typeName = "org.springframework.context.ApplicationContext";
218+
private static readonly id = "fakedDiApplicationContext";
219+
public readonly name = ApplicationContextBean.id;
220+
public readonly IsAnonymous = true;
221+
222+
private constructor() {
223+
Repository.registerBean(this);
224+
Repository.registerIdForClass(ApplicationContextBean.typeName, ApplicationContextBean.id);
225+
}
226+
227+
public static register() {
228+
const bean = Repository.tryGet(ApplicationContextBean.id);
229+
if (bean !== undefined)
230+
return bean;
231+
return new ApplicationContextBean();
232+
}
233+
234+
public get getter(): string {
235+
return `get${upperInitialChar(ApplicationContextBean.id)}`;
236+
}
237+
238+
public get javaMembers(): Member[] {
239+
return [
240+
new Method(
241+
`public static ${ApplicationContextBean.typeName} ${this.getter}()`,
242+
[
243+
new Return(new Symbol("this")),
244+
],
245+
[]),
246+
new BlankLine(),
247+
];
248+
}
249+
250+
public readonly exceptions: string[] = [];
251+
}
252+
216253
export namespace Repository {
217254
const beans = new NameMap<IBean>();
218255

env-model-generator/src/parserDriver.ts

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as jsonParser from "./parseJson";
44
import * as xmlParser from "./parseSpringXml";
55

66
export default async function parseSpringConfigFiles(filePaths: string[]) {
7+
model.ApplicationContextBean.register();
78
await collectBeansFromConfigFiles(filePaths);
89
model.Repository.checkAliases(xmlParser.beanWithIdExists);
910
xmlParser.parseAllBeans();

0 commit comments

Comments
 (0)