import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
interface UserRepository {
String findRole(String userId, Boolean active);
}
class UserService {
UserRepository repo;
UserService(UserRepository repo) {
this.repo = repo;
}
String getUserRole(String userId, boolean active) {
return repo.findRole(userId, active);
}
}
public class UserServiceTest {
@Test
void testGetUserRoleWithArgumentMatchers() {
UserRepository mockRepo = Mockito.mock(UserRepository.class);
when(mockRepo.findRole(eq("user123"), any(Boolean.class))).thenReturn("admin");
UserService service = new UserService(mockRepo);
String role = service.getUserRole("user123", true);
assertEquals("admin", role);
verify(mockRepo).findRole(eq("user123"), any(Boolean.class));
}
}