Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polish LruContextCacheTests #31640

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
package org.springframework.test.context.cache;

import java.util.List;
import java.util.Map;

import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.util.ReflectionTestUtils;

import static java.util.Arrays.asList;
import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -158,17 +158,16 @@ private static MergedContextConfiguration config(Class<?> clazz) {
@SuppressWarnings("unchecked")
private static void assertCacheContents(DefaultContextCache cache, String... expectedNames) {

Map<MergedContextConfiguration, ApplicationContext> contextMap =
(Map<MergedContextConfiguration, ApplicationContext>) ReflectionTestUtils.getField(cache, "contextMap");

// @formatter:off
List<String> actualNames = contextMap.keySet().stream()
.map(cfg -> cfg.getClasses()[0])
.map(Class::getSimpleName)
.toList();
// @formatter:on

assertThat(actualNames).isEqualTo(asList(expectedNames));
assertThat(cache).extracting("contextMap", as(InstanceOfAssertFactories.map(MergedContextConfiguration.class, ApplicationContext.class)))
.satisfies((contextMap) -> {
// @formatter:off
List<String> actualNames = contextMap.keySet().stream()
.map(cfg -> cfg.getClasses()[0])
.map(Class::getSimpleName)
.toList();
// @formatter:on
assertThat(actualNames).isEqualTo(asList(expectedNames));
});
}


Expand Down