Skip to content

Commit

Permalink
Don't use doReturn
Browse files Browse the repository at this point in the history
  • Loading branch information
caiocamatta-stripe committed Feb 28, 2024
1 parent 2048bb2 commit 38206fd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions online/src/test/scala/ai/chronon/online/FetcherBaseTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import scala.concurrent.{Await, ExecutionContext, Future}
import scala.util.{Failure, Success}
import scala.util.Try

class FetcherBaseTest extends MockitoSugar with Matchers with MockitoHelper {
class FetcherBaseTest extends MockitoSugar with Matchers {
val GroupBy = "relevance.short_term_user_features"
val Column = "pdp_view_count_14d"
val GuestKey = "guest"
Expand Down Expand Up @@ -153,7 +153,7 @@ class FetcherBaseTest extends MockitoSugar with Matchers with MockitoHelper {
def test_getServingInfo_ShouldCallUpdateServingInfoIfBatchResponseIsFromKvStore(): Unit = {
val oldServingInfo = mock[GroupByServingInfoParsed]
val updatedServingInfo = mock[GroupByServingInfoParsed]
doReturn(updatedServingInfo).when(fetcherBase).updateServingInfo(any(), any())
when(fetcherBase.updateServingInfo(any(), any())).thenReturn(updatedServingInfo)

val batchTimedValuesSuccess = Success(Seq(TimedValue(Array(1.toByte), 2000L)))
val kvStoreBatchResponses = BatchResponses(batchTimedValuesSuccess)
Expand All @@ -170,16 +170,16 @@ class FetcherBaseTest extends MockitoSugar with Matchers with MockitoHelper {
@Test
def test_getServingInfo_ShouldRefreshServingInfoIfBatchResponseIsCached(): Unit = {
val ttlCache = mock[TTLCache[String, Try[GroupByServingInfoParsed]]]
doReturn(ttlCache).when(fetcherBase).getGroupByServingInfo
when(fetcherBase.getGroupByServingInfo).thenReturn(ttlCache)

val oldServingInfo = mock[GroupByServingInfoParsed]
doReturn(Success(oldServingInfo)).when(ttlCache).refresh(any[String])
when(ttlCache.refresh(any[String])).thenReturn(Success(oldServingInfo))

val metaDataMock = mock[MetaData]
val groupByOpsMock = mock[GroupByOps]
doReturn("test").when(metaDataMock).name
doReturn(metaDataMock).when(groupByOpsMock).metaData
doReturn(groupByOpsMock).when(oldServingInfo).groupByOps
when(metaDataMock.name).thenReturn("test")
when(groupByOpsMock.metaData).thenReturn(metaDataMock)
when(oldServingInfo.groupByOps).thenReturn(groupByOpsMock)

val cachedBatchResponses = BatchResponses(mock[FinalBatchIr])
val result = fetcherBase.getServingInfo(oldServingInfo, cachedBatchResponses)
Expand Down

0 comments on commit 38206fd

Please sign in to comment.