Declare interfaces as @FunctionalInterface where feasible

This commit declares each of the following public interfaces as a
@FunctionalInterface.

- org.springframework.context.ApplicationContextInitializer
- org.springframework.test.web.servlet.DispatcherServletCustomizer
- org.springframework.validation.MessageCodeFormatter
- org.springframework.util.IdGenerator
- org.springframework.beans.factory.config.YamlProcessor.MatchCallback
- org.springframework.beans.factory.config.YamlProcessor.DocumentMatcher

Closes gh-25580
This commit is contained in:
Sam Brannen
2020-08-11 17:01:03 +02:00
parent 596936f18c
commit c558391e2c
8 changed files with 82 additions and 104 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,22 +28,20 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Phillip Webb
*/
public class DefaultMessageCodesResolverTests {
class DefaultMessageCodesResolverTests {
private final DefaultMessageCodesResolver resolver = new DefaultMessageCodesResolver();
private DefaultMessageCodesResolver resolver = new DefaultMessageCodesResolver();
@Test
public void shouldResolveMessageCode() throws Exception {
void shouldResolveMessageCode() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName");
assertThat(codes).containsExactly(
"errorCode.objectName",
"errorCode");
assertThat(codes).containsExactly("errorCode.objectName", "errorCode");
}
@Test
public void shouldResolveFieldMessageCode() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
TestBean.class);
void shouldResolveFieldMessageCode() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field", TestBean.class);
assertThat(codes).containsExactly(
"errorCode.objectName.field",
"errorCode.field",
@@ -52,9 +50,8 @@ public class DefaultMessageCodesResolverTests {
}
@Test
public void shouldResolveIndexedFieldMessageCode() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "a.b[3].c[5].d",
TestBean.class);
void shouldResolveIndexedFieldMessageCode() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "a.b[3].c[5].d", TestBean.class);
assertThat(codes).containsExactly(
"errorCode.objectName.a.b[3].c[5].d",
"errorCode.objectName.a.b[3].c.d",
@@ -68,19 +65,16 @@ public class DefaultMessageCodesResolverTests {
}
@Test
public void shouldResolveMessageCodeWithPrefix() throws Exception {
void shouldResolveMessageCodeWithPrefix() throws Exception {
resolver.setPrefix("prefix.");
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName");
assertThat(codes).containsExactly(
"prefix.errorCode.objectName",
"prefix.errorCode");
assertThat(codes).containsExactly("prefix.errorCode.objectName", "prefix.errorCode");
}
@Test
public void shouldResolveFieldMessageCodeWithPrefix() throws Exception {
void shouldResolveFieldMessageCodeWithPrefix() throws Exception {
resolver.setPrefix("prefix.");
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
TestBean.class);
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field", TestBean.class);
assertThat(codes).containsExactly(
"prefix.errorCode.objectName.field",
"prefix.errorCode.field",
@@ -89,10 +83,9 @@ public class DefaultMessageCodesResolverTests {
}
@Test
public void shouldSupportNullPrefix() throws Exception {
void shouldSupportNullPrefix() throws Exception {
resolver.setPrefix(null);
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
TestBean.class);
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field", TestBean.class);
assertThat(codes).containsExactly(
"errorCode.objectName.field",
"errorCode.field",
@@ -101,9 +94,8 @@ public class DefaultMessageCodesResolverTests {
}
@Test
public void shouldSupportMalformedIndexField() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field[",
TestBean.class);
void shouldSupportMalformedIndexField() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field[", TestBean.class);
assertThat(codes).containsExactly(
"errorCode.objectName.field[",
"errorCode.field[",
@@ -112,9 +104,8 @@ public class DefaultMessageCodesResolverTests {
}
@Test
public void shouldSupportNullFieldType() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
null);
void shouldSupportNullFieldType() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field", null);
assertThat(codes).containsExactly(
"errorCode.objectName.field",
"errorCode.field",
@@ -122,19 +113,16 @@ public class DefaultMessageCodesResolverTests {
}
@Test
public void shouldSupportPostfixFormat() throws Exception {
void shouldSupportPostfixFormat() throws Exception {
resolver.setMessageCodeFormatter(Format.POSTFIX_ERROR_CODE);
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName");
assertThat(codes).containsExactly(
"objectName.errorCode",
"errorCode");
assertThat(codes).containsExactly("objectName.errorCode", "errorCode");
}
@Test
public void shouldSupportFieldPostfixFormat() throws Exception {
void shouldSupportFieldPostfixFormat() throws Exception {
resolver.setMessageCodeFormatter(Format.POSTFIX_ERROR_CODE);
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
TestBean.class);
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field", TestBean.class);
assertThat(codes).containsExactly(
"objectName.field.errorCode",
"field.errorCode",
@@ -143,18 +131,11 @@ public class DefaultMessageCodesResolverTests {
}
@Test
public void shouldSupportCustomFormat() throws Exception {
resolver.setMessageCodeFormatter(new MessageCodeFormatter() {
@Override
public String format(String errorCode, String objectName, String field) {
return DefaultMessageCodesResolver.Format.toDelimitedString(
"CUSTOM-" + errorCode, objectName, field);
}
});
void shouldSupportCustomFormat() throws Exception {
resolver.setMessageCodeFormatter((errorCode, objectName, field) ->
DefaultMessageCodesResolver.Format.toDelimitedString("CUSTOM-" + errorCode, objectName, field));
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName");
assertThat(codes).containsExactly(
"CUSTOM-errorCode.objectName",
"CUSTOM-errorCode");
assertThat(codes).containsExactly("CUSTOM-errorCode.objectName", "CUSTOM-errorCode");
}
}