Tengo el siguiente servicio:
package inventarios.service;
import inventarios.repository.LoginUsersRepository;
import inventarios.to.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class LoginUsersService {
@Autowired
LoginUsersRepository usersRepository;
public List<LoginUser> findAll(){
return usersRepository.findAll();
}
}
Y la siguiente prueba unitaria:
import inventarios.service.LoginUsersService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
@ExtendWith(MockitoExtension.class)
@RunWith(JUnitPlatform.class)
class GUITest {
@Mock
private LoginUsersService usersService;
@InjectMocks
private LoginWindow loginWindow = new LoginWindow();
@Test
void main() {
Mockito.when(usersService.findAll()).thenReturn(Collections.emptyList());
}
}
Sin embargo al correrla obtengo:
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: class inventarios.service.LoginUsersService.
Mockito can only mock non-private & non-final classes. If you're not sure why you're getting this error, please report to the mailing list.
Mi clase es pública y no es final. ¿Qué podría estar mal?