Java writing Spring Boot Unit Tests
Solution 1:
I am sorry that you are in the wrong path.
If FileService
is just an interface, you do not need to test it.
If FileService
is an implementation, you should create an actual instance to test it but not a mock.
The mock is only useful for the direct dependencies of the class that you are testing (i.e FileSerivice
) such that you can easily stub the result when calling methods on these dependencies and verify if the class you are testing interacts with them correctly. (i.e. call the correct methods with the correct parameters etc.)
As I cannot see FileSerivice
's source codes , but if UserPrincipal
and User
are not its dependencies , it does not make sense to mock them.
Also as mentioned by other in the comment, as you are not doing the integration testing with some Spring framework stuff, you should simply rewrite your test as a plain Mockito test which is simpler and run faster :
@ExtendWith(MockitoExtension.class)
public class FileServiceImplTest {
}