|
1 | 1 | /*
|
2 |
| - * Copyright 2018-2022 the original author or authors. |
| 2 | + * Copyright 2018-2023 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.
|
|
15 | 15 | */
|
16 | 16 | package org.springframework.batch.test.context;
|
17 | 17 |
|
| 18 | +import org.junit.jupiter.api.AfterEach; |
18 | 19 | import org.junit.jupiter.api.Test;
|
19 | 20 | import org.mockito.Mockito;
|
20 | 21 |
|
21 | 22 | import org.springframework.context.ConfigurableApplicationContext;
|
22 | 23 | import org.springframework.context.support.GenericApplicationContext;
|
| 24 | +import org.springframework.core.SpringProperties; |
23 | 25 | import org.springframework.test.context.MergedContextConfiguration;
|
24 | 26 |
|
25 | 27 | import static org.hamcrest.CoreMatchers.containsString;
|
26 | 28 | import static org.hamcrest.MatcherAssert.assertThat;
|
| 29 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
27 | 30 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
28 | 31 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
29 | 32 |
|
30 | 33 | /**
|
31 |
| - * @author Mahmoud Ben Hassine |
| 34 | + * @author Mahmoud Ben Hassine, Alexander Arshavskiy |
32 | 35 | */
|
33 | 36 | class BatchTestContextCustomizerTests {
|
34 | 37 |
|
35 | 38 | private final BatchTestContextCustomizer contextCustomizer = new BatchTestContextCustomizer();
|
36 | 39 |
|
| 40 | + @AfterEach |
| 41 | + void removeSystemProperty() { |
| 42 | + SpringProperties.setProperty("spring.aot.enabled", null); |
| 43 | + } |
| 44 | + |
37 | 45 | @Test
|
38 | 46 | void testCustomizeContext() {
|
39 | 47 | // given
|
@@ -64,4 +72,20 @@ void testCustomizeContext_whenBeanFactoryIsNotAnInstanceOfBeanDefinitionRegistry
|
64 | 72 | containsString("The bean factory must be an instance of BeanDefinitionRegistry"));
|
65 | 73 | }
|
66 | 74 |
|
| 75 | + @Test |
| 76 | + void testCustomizeContext_whenUsingAotGeneratedArtifactsBatchTestContextIsNotRegistered() { |
| 77 | + // given |
| 78 | + SpringProperties.setProperty("spring.aot.enabled", "true"); |
| 79 | + ConfigurableApplicationContext context = new GenericApplicationContext(); |
| 80 | + MergedContextConfiguration mergedConfig = Mockito.mock(MergedContextConfiguration.class); |
| 81 | + |
| 82 | + // when |
| 83 | + this.contextCustomizer.customizeContext(context, mergedConfig); |
| 84 | + |
| 85 | + // then |
| 86 | + assertFalse(context.containsBean("jobLauncherTestUtils")); |
| 87 | + assertFalse(context.containsBean("jobRepositoryTestUtils")); |
| 88 | + assertFalse(context.containsBean("batchTestContextBeanPostProcessor")); |
| 89 | + } |
| 90 | + |
67 | 91 | }
|
0 commit comments