Skip to content

Commit

Permalink
Create UserControllerTest.java
Browse files Browse the repository at this point in the history
  • Loading branch information
raffaelbrandao committed Apr 8, 2024
1 parent ff03c8a commit 9be3a67
Showing 1 changed file with 35 additions and 0 deletions.
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);
}
}

0 comments on commit 9be3a67

Please sign in to comment.