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

[20210908] @Valid 예외 테스트 #208

Open
JuHyun419 opened this issue Sep 8, 2021 · 0 comments
Open

[20210908] @Valid 예외 테스트 #208

JuHyun419 opened this issue Sep 8, 2021 · 0 comments
Labels

Comments

@JuHyun419
Copy link
Owner

@Valid 어노테이션 예외 테스트

package com.juhyun.kotlintodo.model

import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import javax.validation.Validation
import javax.validation.Validator

class TodoDtoTest {

    private val validator: Validator = Validation.buildDefaultValidatorFactory().validator

    @Test
    fun todoDtoTest() {
        // given
        val todoDto = TodoDto().apply {
            this.title = "테스트"
            this.description = ""
            this.schedule = "2020-10-20 13:00:00"
        }

        // when
        val result = validator.validate(todoDto)

        // then
        assertThat(result.isEmpty()).isEqualTo(true)
    }

    @Test
    fun title_제목이_지정되어야_한다() {
        // given
        val todoDto = TodoDto().apply {
            this.title = ""
            this.description = ""
            this.schedule = "2020-10-20 13:00:00"
        }

        // when
        val result = validator.validate(todoDto)

        // then
        result.forEach {
            assertThat(it.messageTemplate).contains("NotBlank")
            assertThat(it.message).contains("공백")
        }

    }

}

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant