Java, Unit Testing, Legacy Code, Programming, Technology.
this.userRepository = userRepository; } public User getUserById(String userId) { return userRepository.findById(userId); } } Create a test using a mock UserRepository: public class UserServiceTest { @Test public void testGetUserById() { UserRepository mockRepository = mock(UserRepository.class);