package hello.itemservice.validation;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.validation.BindingResult;
import org.springframework.validation.DefaultMessageCodesResolver;
import org.springframework.validation.MessageCodesResolver;
import org.springframework.validation.ObjectError;
import static org.assertj.core.api.Assertions.assertThat;
public class MessageCodesResolverTest {
MessageCodesResolver codesResolvder = new DefaultMessageCodesResolver();
@Test
void messageCodeResolverObject(){
String[] messageCodes = codesResolvder.resolveMessageCodes("required", "item");
//배열의 모든요소들이 인자와 같은가(순서까지 같아야함)
assertThat(messageCodes).containsExactly("required.item","required");
}
@Test
void messageCodesResolverField(){
String[] messageCodes = codesResolvder.resolveMessageCodes("required", "item", "itemName", String.class);
for (String messageCode : messageCodes) {
System.out.println("messageCode = " + messageCode);
}
//배열의 모든요소들이 인자와 같은가(순서까지 같아야함)
assertThat(messageCodes).containsExactly(
"required.item.itemName",
"required.itemName",
"required.java.lang.String",
"required"
);
}
}
TDD/assertj