-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
muriloalvesdev
committed
Jan 17, 2023
1 parent
3f19257
commit 52fd5a0
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
47 changes: 47 additions & 0 deletions
47
src/test/kotlin/br/com/hexagonal/app/adapter/controller/UserControllerUnitUnitTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package br.com.hexagonal.app.adapter.controller | ||
|
||
import br.com.hexagonal.BaseUnitTest | ||
import br.com.hexagonal.domain.dto.UserDto | ||
import br.com.hexagonal.domain.ports.`interface`.UserServicePort | ||
import br.com.hexagonal.provider.UserDtoProviderTests | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.ArgumentsSource | ||
import org.mockito.Mockito.doNothing | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.times | ||
import org.mockito.Mockito.verify | ||
import org.springframework.http.HttpStatus | ||
import org.springframework.mock.web.MockHttpServletRequest | ||
import org.springframework.web.context.request.RequestContextHolder | ||
import org.springframework.web.context.request.ServletRequestAttributes | ||
|
||
class UserControllerUnitUnitTest : BaseUnitTest() { | ||
private val userServicePort: UserServicePort = mock(UserServicePort::class.java) | ||
private val controller: UserController = UserController(this.userServicePort) | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
val request = MockHttpServletRequest() | ||
RequestContextHolder.setRequestAttributes(ServletRequestAttributes(request)) | ||
} | ||
|
||
@ParameterizedTest | ||
@ArgumentsSource(UserDtoProviderTests::class) | ||
fun shouldSave(userDto: UserDto) { | ||
//GIVEN | ||
doNothing().`when`(this.userServicePort).save(userDto) | ||
|
||
//WHEN | ||
val response = this.controller.save(userDto) | ||
|
||
//THEN | ||
assertThat(HttpStatus.CREATED).isEqualTo(response.statusCode) | ||
assertThat(response.headers.location).isNotNull | ||
assertThat("http://localhost/users/muriloalvesdev") | ||
.isEqualTo(response.headers.location.toString()) | ||
|
||
verify(this.userServicePort, times(1)) | ||
} | ||
} |