-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can we make class Redis not final #25
Comments
Sure, that's feasible. Out of curiosity, could you explain why you would need to mock it? |
Int most of the time, in our unit tests, we don't want to actually talk to the actual Redis server. Instead, we talk to the mocked scredis.Redis object which is prepared by mocking libraries like Mockito. For example, val mockRedisServer = mock[Redis] when(mockRedisServer.keys("bat:queue:*")).thenReturn(Future.successful(Set[String]("bat:queue:abc", "bat:queue:jkl"))) when(mockRedisServer.lLen("bat:queue:abc")).thenReturn(Future.successful(3l)) when(mockRedisServer.lLen("bat:queue:jkl")).thenReturn(Future.successful(2l)) when(mockRedisServer.lRange[String]("bat:queue:abc", 0, 2)).thenReturn(Future.successful(List[String]( """["user1", "http://diary/1", "diary_meal", 28, "http://partner1_callback"]""", """["user1", "http://diary/2", "diary_meal", 28, "http://partner1_callback"]""", """["user1", "http://diary/3", "diary_meal", 28, "http://partner1_callback"]""" ))) when(mockRedisServer.lRange[String]("bat:queue:jkl", 0, 1)).thenReturn(Future.successful(List[String]( """["user1", "http://diary/1", "diary_meal", 29, "http://partner2_callback"]""", """["user1", "http://diary/2", "diary_meal", 29, "http://partner2_callback"]""" ))) when(mockRedisServer.rPopLPush[String](org.mockito.Matchers.eq("agg:queue"), any[String])(any[scredis.serialization.Reader[String]])) .thenReturn(Future.successful(None)) then in the unit test, I use this mocked object instead of the real one. Does that make sense? Thanks! |
Makes sense. I'm going to remove the final modifier for all relevant classes in the next minor release. |
Wow, that's quick. Now I can get rid of my local overrides 👍 |
I love the library, great work guys.
Just want see if it's possible to get rid of the final of Redis class. Otherwise, it's impossible to mock it in unit test.
Thanks
The text was updated successfully, but these errors were encountered: