-
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
1 parent
ff03c8a
commit 9be3a67
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/test/java/com/raffaelbrandao/demo/controllers/UserControllerTest.java
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,35 @@ | ||
package com.raffaelbrandao.demo.controllers; | ||
|
||
import com.raffaelbrandao.demo.models.UserEntity; | ||
import com.raffaelbrandao.demo.services.UserService; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class UserControllerTest { | ||
@InjectMocks | ||
private UserController userController; | ||
@Mock | ||
private UserService userService; | ||
|
||
@Test | ||
public void whenFindAllUsers_thenReturnAllUsers() { | ||
//given | ||
List<UserEntity> allUsersExpected = new ArrayList<>(); | ||
allUsersExpected.add(new UserEntity(null, "joaosilva", "João Silva", null, null)); | ||
allUsersExpected.add(new UserEntity(null, "mariasantos", "Maria Santos", null, null)); | ||
Mockito.when(userService.findAll()).thenReturn(allUsersExpected); | ||
//when | ||
List<UserEntity> allUsers = userController.findAllUsers(); | ||
//then | ||
Assertions.assertEquals(allUsersExpected, allUsers); | ||
} | ||
} |