Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.

Commit 905fbba

Browse files
committed
Introduce unit tests for AotMergedContextConfiguration
See gh-1262
1 parent d9d03db commit 905fbba

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2019-2021 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.aot.test;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.mockito.Mockito.mock;
21+
22+
import java.util.Map;
23+
import java.util.Set;
24+
25+
import org.junit.jupiter.api.Test;
26+
27+
import org.springframework.context.ApplicationContextInitializer;
28+
import org.springframework.context.support.GenericApplicationContext;
29+
import org.springframework.test.context.MergedContextConfiguration;
30+
import org.springframework.test.context.cache.ContextCache;
31+
import org.springframework.test.context.support.DelegatingSmartContextLoader;
32+
33+
/**
34+
* Unit tests for {@link AotMergedContextConfiguration}.
35+
*
36+
* @author Sam Brannen
37+
*/
38+
class AotMergedContextConfigurationTests {
39+
40+
private final AotCacheAwareContextLoaderDelegate delegate = new AotCacheAwareContextLoaderDelegate(
41+
new AotTestMappings(Map.of(), Map.of()), mock(ContextCache.class));
42+
43+
private final MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(), null, null,
44+
Set.of(DemoApplicationContextInitializer.class), null, new DelegatingSmartContextLoader());
45+
46+
private final AotMergedContextConfiguration aotMergedConfig1 = new AotMergedContextConfiguration(getClass(),
47+
DemoApplicationContextInitializer.class, mergedConfig, delegate, null);
48+
49+
private final AotMergedContextConfiguration aotMergedConfig2 = new AotMergedContextConfiguration(getClass(),
50+
DemoApplicationContextInitializer.class, mergedConfig, delegate, null);
51+
52+
private final AotMergedContextConfiguration aotMergedConfig3 = new AotMergedContextConfiguration(getClass(),
53+
DemoApplicationContextInitializer.class, mergedConfig, delegate, aotMergedConfig1);
54+
55+
@Test
56+
void testEquals() throws Exception {
57+
assertThat(aotMergedConfig1).isEqualTo(aotMergedConfig1);
58+
assertThat(aotMergedConfig1).isEqualTo(aotMergedConfig2);
59+
60+
assertThat(mergedConfig).isNotEqualTo(aotMergedConfig1);
61+
assertThat(aotMergedConfig1).isNotEqualTo(mergedConfig);
62+
assertThat(aotMergedConfig1).isNotEqualTo(aotMergedConfig3);
63+
}
64+
65+
@Test
66+
void testHashCode() throws Exception {
67+
assertThat(aotMergedConfig1).hasSameHashCodeAs(aotMergedConfig2);
68+
69+
assertThat(aotMergedConfig1).doesNotHaveSameHashCodeAs(mergedConfig);
70+
assertThat(aotMergedConfig1).doesNotHaveSameHashCodeAs(aotMergedConfig3);
71+
}
72+
73+
74+
static class DemoApplicationContextInitializer implements ApplicationContextInitializer<GenericApplicationContext> {
75+
@Override
76+
public void initialize(GenericApplicationContext applicationContext) {
77+
}
78+
}
79+
80+
}

0 commit comments

Comments
 (0)