Polish
This commit is contained in:
parent
56d820a8d4
commit
f0693989f1
|
|
@ -64,7 +64,7 @@ public class SessionsEndpointAutoConfigurationTests {
|
|||
static class SessionConfiguration {
|
||||
|
||||
@Bean
|
||||
public FindByIndexNameSessionRepository sessionRepository() {
|
||||
public FindByIndexNameSessionRepository<?> sessionRepository() {
|
||||
return mock(FindByIndexNameSessionRepository.class);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ public class SessionsEndpoint {
|
|||
|
||||
public SessionsReport(Map<String, ? extends Session> sessions) {
|
||||
this.sessions = sessions.entrySet().stream()
|
||||
.map(s -> new SessionDescriptor(s.getValue()))
|
||||
.map((s) -> new SessionDescriptor(s.getValue()))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -40,10 +40,10 @@ public class SessionsEndpointTests {
|
|||
|
||||
private static final Session session = new MapSession();
|
||||
|
||||
private final FindByIndexNameSessionRepository repository = mock(
|
||||
@SuppressWarnings("unchecked")
|
||||
private final FindByIndexNameSessionRepository<Session> repository = mock(
|
||||
FindByIndexNameSessionRepository.class);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private final SessionsEndpoint endpoint = new SessionsEndpoint(this.repository);
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -44,7 +44,8 @@ public class SessionsEndpointWebIntegrationTests {
|
|||
|
||||
private static final Session session = new MapSession();
|
||||
|
||||
private static final FindByIndexNameSessionRepository repository = mock(
|
||||
@SuppressWarnings("unchecked")
|
||||
private static final FindByIndexNameSessionRepository<Session> repository = mock(
|
||||
FindByIndexNameSessionRepository.class);
|
||||
|
||||
private static WebTestClient client;
|
||||
|
|
@ -59,7 +60,7 @@ public class SessionsEndpointWebIntegrationTests {
|
|||
public void sessionsForUsernameNoResults() throws Exception {
|
||||
given(repository.findByIndexNameAndIndexValue(
|
||||
FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME, "user"))
|
||||
.willReturn(Collections.emptyMap());
|
||||
.willReturn(Collections.emptyMap());
|
||||
client.get()
|
||||
.uri((builder) -> builder.path("/application/sessions")
|
||||
.queryParam("username", "user").build())
|
||||
|
|
@ -83,7 +84,6 @@ public class SessionsEndpointWebIntegrationTests {
|
|||
protected static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
@SuppressWarnings("unchecked")
|
||||
public SessionsEndpoint sessionsEndpoint() {
|
||||
return new SessionsEndpoint(repository);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,12 +67,12 @@ class JsonbHttpMessageConvertersConfiguration {
|
|||
|
||||
}
|
||||
|
||||
@ConditionalOnMissingBean({ MappingJackson2HttpMessageConverter.class, GsonHttpMessageConverter.class })
|
||||
@ConditionalOnMissingBean({ MappingJackson2HttpMessageConverter.class,
|
||||
GsonHttpMessageConverter.class })
|
||||
static class JacksonAndGsonMissing {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,15 +61,17 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
public class HttpMessageConvertersAutoConfigurationTests {
|
||||
|
||||
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(
|
||||
HttpMessageConvertersAutoConfiguration.class));
|
||||
.withConfiguration(
|
||||
AutoConfigurations.of(HttpMessageConvertersAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
public void jacksonNotAvailable() {
|
||||
this.contextRunner.run((context) -> {
|
||||
assertThat(context).doesNotHaveBean(ObjectMapper.class);
|
||||
assertThat(context).doesNotHaveBean(MappingJackson2HttpMessageConverter.class);
|
||||
assertThat(context).doesNotHaveBean(MappingJackson2XmlHttpMessageConverter.class);
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(MappingJackson2HttpMessageConverter.class);
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(MappingJackson2XmlHttpMessageConverter.class);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -96,10 +98,11 @@ public class HttpMessageConvertersAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void jacksonCustomConverter() {
|
||||
this.contextRunner.withUserConfiguration(JacksonObjectMapperConfig.class,
|
||||
JacksonConverterConfig.class
|
||||
).run(assertConverter(MappingJackson2HttpMessageConverter.class,
|
||||
"customJacksonMessageConverter"));
|
||||
this.contextRunner
|
||||
.withUserConfiguration(JacksonObjectMapperConfig.class,
|
||||
JacksonConverterConfig.class)
|
||||
.run(assertConverter(MappingJackson2HttpMessageConverter.class,
|
||||
"customJacksonMessageConverter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -112,10 +115,10 @@ public class HttpMessageConvertersAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void gsonDefaultConverter() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(
|
||||
GsonAutoConfiguration.class)
|
||||
).run(assertConverter(GsonHttpMessageConverter.class,
|
||||
"gsonHttpMessageConverter"));
|
||||
this.contextRunner
|
||||
.withConfiguration(AutoConfigurations.of(GsonAutoConfiguration.class))
|
||||
.run(assertConverter(GsonHttpMessageConverter.class,
|
||||
"gsonHttpMessageConverter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -128,15 +131,17 @@ public class HttpMessageConvertersAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void gsonCanBePreferred() {
|
||||
allOptionsRunner().withPropertyValues(
|
||||
"spring.http.converters.preferred-json-mapper:gson").run((context) -> {
|
||||
assertConverterBeanExists(context, GsonHttpMessageConverter.class,
|
||||
"gsonHttpMessageConverter");
|
||||
assertConverterBeanRegisteredWithHttpMessageConverters(context,
|
||||
GsonHttpMessageConverter.class);
|
||||
assertThat(context).doesNotHaveBean(JsonbHttpMessageConverter.class);
|
||||
assertThat(context).doesNotHaveBean(MappingJackson2HttpMessageConverter.class);
|
||||
});
|
||||
allOptionsRunner()
|
||||
.withPropertyValues("spring.http.converters.preferred-json-mapper:gson")
|
||||
.run((context) -> {
|
||||
assertConverterBeanExists(context, GsonHttpMessageConverter.class,
|
||||
"gsonHttpMessageConverter");
|
||||
assertConverterBeanRegisteredWithHttpMessageConverters(context,
|
||||
GsonHttpMessageConverter.class);
|
||||
assertThat(context).doesNotHaveBean(JsonbHttpMessageConverter.class);
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(MappingJackson2HttpMessageConverter.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -149,10 +154,10 @@ public class HttpMessageConvertersAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void jsonbDefaultConverter() {
|
||||
this.contextRunner.withConfiguration(AutoConfigurations.of(
|
||||
JsonbAutoConfiguration.class)
|
||||
).run(assertConverter(JsonbHttpMessageConverter.class,
|
||||
"jsonbHttpMessageConverter"));
|
||||
this.contextRunner
|
||||
.withConfiguration(AutoConfigurations.of(JsonbAutoConfiguration.class))
|
||||
.run(assertConverter(JsonbHttpMessageConverter.class,
|
||||
"jsonbHttpMessageConverter"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -165,15 +170,17 @@ public class HttpMessageConvertersAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void jsonbCanBePreferred() {
|
||||
allOptionsRunner().withPropertyValues(
|
||||
"spring.http.converters.preferred-json-mapper:jsonb").run((context) -> {
|
||||
assertConverterBeanExists(context, JsonbHttpMessageConverter.class,
|
||||
"jsonbHttpMessageConverter");
|
||||
assertConverterBeanRegisteredWithHttpMessageConverters(context,
|
||||
JsonbHttpMessageConverter.class);
|
||||
assertThat(context).doesNotHaveBean(GsonHttpMessageConverter.class);
|
||||
assertThat(context).doesNotHaveBean(MappingJackson2HttpMessageConverter.class);
|
||||
});
|
||||
allOptionsRunner()
|
||||
.withPropertyValues("spring.http.converters.preferred-json-mapper:jsonb")
|
||||
.run((context) -> {
|
||||
assertConverterBeanExists(context, JsonbHttpMessageConverter.class,
|
||||
"jsonbHttpMessageConverter");
|
||||
assertConverterBeanRegisteredWithHttpMessageConverters(context,
|
||||
JsonbHttpMessageConverter.class);
|
||||
assertThat(context).doesNotHaveBean(GsonHttpMessageConverter.class);
|
||||
assertThat(context)
|
||||
.doesNotHaveBean(MappingJackson2HttpMessageConverter.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -193,22 +200,26 @@ public class HttpMessageConvertersAutoConfigurationTests {
|
|||
public void typeConstrainedConverterDoesNotPreventAutoConfigurationOfJacksonConverter() {
|
||||
this.contextRunner.withUserConfiguration(JacksonObjectMapperBuilderConfig.class,
|
||||
TypeConstrainedConverterConfiguration.class).run((context) -> {
|
||||
BeanDefinition beanDefinition = ((GenericApplicationContext) context.getSourceApplicationContext())
|
||||
.getBeanDefinition("mappingJackson2HttpMessageConverter");
|
||||
assertThat(beanDefinition.getFactoryBeanName()).isEqualTo(
|
||||
MappingJackson2HttpMessageConverterConfiguration.class.getName());
|
||||
});
|
||||
BeanDefinition beanDefinition = ((GenericApplicationContext) context
|
||||
.getSourceApplicationContext()).getBeanDefinition(
|
||||
"mappingJackson2HttpMessageConverter");
|
||||
assertThat(beanDefinition.getFactoryBeanName()).isEqualTo(
|
||||
MappingJackson2HttpMessageConverterConfiguration.class
|
||||
.getName());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typeConstrainedConverterFromSpringDataDoesNotPreventAutoConfigurationOfJacksonConverter() {
|
||||
this.contextRunner.withUserConfiguration(JacksonObjectMapperBuilderConfig.class,
|
||||
RepositoryRestMvcConfiguration.class).run((context) -> {
|
||||
BeanDefinition beanDefinition = ((GenericApplicationContext) context.getSourceApplicationContext())
|
||||
.getBeanDefinition("mappingJackson2HttpMessageConverter");
|
||||
assertThat(beanDefinition.getFactoryBeanName()).isEqualTo(
|
||||
MappingJackson2HttpMessageConverterConfiguration.class.getName());
|
||||
});
|
||||
BeanDefinition beanDefinition = ((GenericApplicationContext) context
|
||||
.getSourceApplicationContext()).getBeanDefinition(
|
||||
"mappingJackson2HttpMessageConverter");
|
||||
assertThat(beanDefinition.getFactoryBeanName()).isEqualTo(
|
||||
MappingJackson2HttpMessageConverterConfiguration.class
|
||||
.getName());
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -225,13 +236,13 @@ public class HttpMessageConvertersAutoConfigurationTests {
|
|||
|
||||
@Test
|
||||
public void gsonIsPreferredIfJacksonIsNotAvailable() {
|
||||
allOptionsRunner()
|
||||
.withClassLoader(new HidePackagesClassLoader(
|
||||
ObjectMapper.class.getPackage().getName())).run((context) -> {
|
||||
assertConverterBeanExists(context, GsonHttpMessageConverter.class,
|
||||
"gsonHttpMessageConverter");
|
||||
assertThat(context).doesNotHaveBean(JsonbHttpMessageConverter.class);
|
||||
});
|
||||
allOptionsRunner().withClassLoader(
|
||||
new HidePackagesClassLoader(ObjectMapper.class.getPackage().getName()))
|
||||
.run((context) -> {
|
||||
assertConverterBeanExists(context, GsonHttpMessageConverter.class,
|
||||
"gsonHttpMessageConverter");
|
||||
assertThat(context).doesNotHaveBean(JsonbHttpMessageConverter.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -245,17 +256,17 @@ public class HttpMessageConvertersAutoConfigurationTests {
|
|||
}
|
||||
|
||||
private ApplicationContextRunner allOptionsRunner() {
|
||||
return this.contextRunner.withConfiguration(AutoConfigurations.of(
|
||||
GsonAutoConfiguration.class, JacksonAutoConfiguration.class,
|
||||
JsonbAutoConfiguration.class));
|
||||
return this.contextRunner
|
||||
.withConfiguration(AutoConfigurations.of(GsonAutoConfiguration.class,
|
||||
JacksonAutoConfiguration.class, JsonbAutoConfiguration.class));
|
||||
}
|
||||
|
||||
|
||||
private ContextConsumer<AssertableApplicationContext> assertConverter(
|
||||
Class<? extends HttpMessageConverter> converterType, String beanName) {
|
||||
return context -> {
|
||||
Class<? extends HttpMessageConverter<?>> converterType, String beanName) {
|
||||
return (context) -> {
|
||||
assertConverterBeanExists(context, converterType, beanName);
|
||||
assertConverterBeanRegisteredWithHttpMessageConverters(context, converterType);
|
||||
assertConverterBeanRegisteredWithHttpMessageConverters(context,
|
||||
converterType);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -266,8 +277,9 @@ public class HttpMessageConvertersAutoConfigurationTests {
|
|||
}
|
||||
|
||||
private void assertConverterBeanRegisteredWithHttpMessageConverters(
|
||||
AssertableApplicationContext context, Class<? extends HttpMessageConverter> type) {
|
||||
HttpMessageConverter converter = context.getBean(type);
|
||||
AssertableApplicationContext context,
|
||||
Class<? extends HttpMessageConverter<?>> type) {
|
||||
HttpMessageConverter<?> converter = context.getBean(type);
|
||||
HttpMessageConverters converters = context.getBean(HttpMessageConverters.class);
|
||||
assertThat(converters.getConverters()).contains(converter);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ import org.springframework.test.context.BootstrapWith;
|
|||
* <p>
|
||||
* By default, tests annotated with {@code JsonTest} will also initialize
|
||||
* {@link JacksonTester}, {@link JsonbTester} and {@link GsonTester} fields. More
|
||||
* fine-grained control can be provided via the {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters}
|
||||
* annotation.
|
||||
* fine-grained control can be provided via the
|
||||
* {@link AutoConfigureJsonTesters @AutoConfigureJsonTesters} annotation.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @see AutoConfigureJson
|
||||
|
|
|
|||
|
|
@ -370,7 +370,7 @@ public class ApplicationContextAssert<C extends ApplicationContext>
|
|||
|
||||
private ContextFailedToStart<C> contextFailedToStartWhenExpecting(
|
||||
String expectationFormat, Object... arguments) {
|
||||
return new ContextFailedToStart<C>(getApplicationContext(), this.startupFailure,
|
||||
return new ContextFailedToStart<>(getApplicationContext(), this.startupFailure,
|
||||
expectationFormat, arguments);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,12 +39,13 @@ class CollectionBinder extends IndexedElementsBinder<Collection<Object>> {
|
|||
protected Object bind(ConfigurationPropertyName name, Bindable<?> target,
|
||||
AggregateElementBinder elementBinder, Class<?> type) {
|
||||
Class<?> collectionType = (type != null ? type
|
||||
: ResolvableType.forClassWithGenerics(List.class, Object.class).resolve());
|
||||
: ResolvableType.forClassWithGenerics(List.class, Object.class)
|
||||
.resolve());
|
||||
IndexedCollectionSupplier collection = new IndexedCollectionSupplier(
|
||||
() -> CollectionFactory.createCollection(collectionType, 0));
|
||||
ResolvableType elementType = target.getType().asCollection().getGeneric();
|
||||
bindIndexed(name, target, elementBinder, collection, ResolvableType.forClass(collectionType),
|
||||
elementType);
|
||||
bindIndexed(name, target, elementBinder, collection,
|
||||
ResolvableType.forClass(collectionType), elementType);
|
||||
if (collection.wasSupplied()) {
|
||||
return collection.get();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,9 @@ class MapBinder extends AggregateBinder<Map<Object, Object>> {
|
|||
protected Object bind(ConfigurationPropertyName name, Bindable<?> target,
|
||||
AggregateElementBinder elementBinder, Class<?> type) {
|
||||
Class<?> mapType = (type != null ? type
|
||||
: ResolvableType.forClassWithGenerics(Map.class, Object.class, Object.class).resolve());
|
||||
: ResolvableType
|
||||
.forClassWithGenerics(Map.class, Object.class, Object.class)
|
||||
.resolve());
|
||||
Map<Object, Object> map = CollectionFactory.createMap(mapType, 0);
|
||||
Bindable<?> resolvedTarget = resolveTarget(target);
|
||||
for (ConfigurationPropertySource source : getContext().getSources()) {
|
||||
|
|
|
|||
|
|
@ -58,11 +58,11 @@ public final class DataSourceBuilder<T extends DataSource> {
|
|||
private Map<String, String> properties = new HashMap<>();
|
||||
|
||||
public static DataSourceBuilder<?> create() {
|
||||
return new DataSourceBuilder<DataSource>(null);
|
||||
return new DataSourceBuilder<>(null);
|
||||
}
|
||||
|
||||
public static DataSourceBuilder<?> create(ClassLoader classLoader) {
|
||||
return new DataSourceBuilder<DataSource>(classLoader);
|
||||
return new DataSourceBuilder<>(classLoader);
|
||||
}
|
||||
|
||||
private DataSourceBuilder(ClassLoader classLoader) {
|
||||
|
|
|
|||
|
|
@ -199,13 +199,15 @@ public class BinderTests {
|
|||
@Test
|
||||
public void bindWhenHasMalformedDateShouldThrowException() throws Exception {
|
||||
this.thrown.expectCause(instanceOf(ConversionFailedException.class));
|
||||
this.sources.add(new MockConfigurationPropertySource("foo", "2014-04-01T01:30:00.000-05:00"));
|
||||
this.sources.add(new MockConfigurationPropertySource("foo",
|
||||
"2014-04-01T01:30:00.000-05:00"));
|
||||
this.binder.bind("foo", Bindable.of(LocalDate.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bindWhenHasAnnotationsShouldChangeConvertedValue() throws Exception {
|
||||
this.sources.add(new MockConfigurationPropertySource("foo", "2014-04-01T01:30:00.000-05:00"));
|
||||
this.sources.add(new MockConfigurationPropertySource("foo",
|
||||
"2014-04-01T01:30:00.000-05:00"));
|
||||
DateTimeFormat annotation = AnnotationUtils.synthesizeAnnotation(
|
||||
Collections.singletonMap("iso", DateTimeFormat.ISO.DATE_TIME),
|
||||
DateTimeFormat.class, null);
|
||||
|
|
|
|||
|
|
@ -322,8 +322,7 @@ public class CollectionBinderTests {
|
|||
MockConfigurationPropertySource source = new MockConfigurationPropertySource();
|
||||
source.put("foo.items", "a,b,c,c");
|
||||
this.sources.add(source);
|
||||
ExampleCustomBean result = this.binder
|
||||
.bind("foo", ExampleCustomBean.class).get();
|
||||
ExampleCustomBean result = this.binder.bind("foo", ExampleCustomBean.class).get();
|
||||
assertThat(result.getItems()).hasSize(4);
|
||||
assertThat(result.getItems()).containsExactly("a", "b", "c", "c");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,8 +73,8 @@ public class DataSourceBuilderTests {
|
|||
|
||||
@Test
|
||||
public void specificTypeOfDataSource() {
|
||||
HikariDataSource hikariDataSource = DataSourceBuilder.create().type(HikariDataSource.class)
|
||||
.build();
|
||||
HikariDataSource hikariDataSource = DataSourceBuilder.create()
|
||||
.type(HikariDataSource.class).build();
|
||||
assertThat(hikariDataSource).isInstanceOf(HikariDataSource.class);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue