@@ -2,8 +2,10 @@ package com.guizmaii.distances
2
2
3
3
import cats .effect .internals .IOContextShift
4
4
import cats .effect .{Concurrent , ContextShift , IO }
5
+ import com .guizmaii .distances .Cache .CachingF
6
+ import com .guizmaii .distances .DistanceProvider .DistanceF
5
7
import com .guizmaii .distances .Types .TravelMode .{Bicycling , Driving }
6
- import com .guizmaii .distances .Types .{ Distance , LatLong , PostalCode , _ }
8
+ import com .guizmaii .distances .Types ._
7
9
import com .guizmaii .distances .caches .CaffeineCache
8
10
import com .guizmaii .distances .providers .google .{GoogleDistanceProvider , GoogleGeoApiContext , GoogleGeoProvider }
9
11
import monix .eval .Task
@@ -29,9 +31,11 @@ class DistanceApiSpec extends WordSpec with Matchers with ScalaFutures with Befo
29
31
" #distance" should {
30
32
" if origin == destination" should {
31
33
" not call the provider and return immmediatly Distance.zero" in {
32
- val distanceApi : DistanceApi [IO ] = DistanceApi [IO ](distanceProviderStub[IO ], CaffeineCache (Some (1 days)))
33
- val latLong = LatLong (0.0 , 0.0 )
34
- val expectedResult = Map ((Driving , Distance .zero), (Bicycling , Distance .zero))
34
+ val cachingF : CachingF [IO , Distance ] = CaffeineCache [IO ](Some (1 days)).cachingF[Distance ]
35
+ val distanceF : DistanceF [IO ] = distanceProviderStub[IO ].distance
36
+ val distanceApi : DistanceApi [IO ] = DistanceApi [IO ](distanceF, cachingF)
37
+ val latLong = LatLong (0.0 , 0.0 )
38
+ val expectedResult = Map ((Driving , Distance .zero), (Bicycling , Distance .zero))
35
39
distanceApi.distance(latLong, latLong, Driving :: Bicycling :: Nil ).unsafeRunSync() shouldBe expectedResult
36
40
}
37
41
}
@@ -40,9 +44,11 @@ class DistanceApiSpec extends WordSpec with Matchers with ScalaFutures with Befo
40
44
" #distanceFromPostalCodes" should {
41
45
" if origin == destination" should {
42
46
" not call the provider and return immmediatly Distance.zero" in {
43
- val distanceApi : DistanceApi [IO ] = DistanceApi [IO ](distanceProviderStub[IO ], CaffeineCache (Some (1 days)))
44
- val postalCode = PostalCode (" 59000" )
45
- val expectedResult = Map ((Driving , Distance .zero), (Bicycling , Distance .zero))
47
+ val cachingF : CachingF [IO , Distance ] = CaffeineCache [IO ](Some (1 days)).cachingF[Distance ]
48
+ val distanceF : DistanceF [IO ] = distanceProviderStub[IO ].distance
49
+ val distanceApi : DistanceApi [IO ] = DistanceApi [IO ](distanceF, cachingF)
50
+ val postalCode = PostalCode (" 59000" )
51
+ val expectedResult = Map ((Driving , Distance .zero), (Bicycling , Distance .zero))
46
52
distanceApi
47
53
.distanceFromPostalCodes(geocoderStub)(postalCode, postalCode, Driving :: Bicycling :: Nil )
48
54
.unsafeRunSync() shouldBe expectedResult
@@ -53,8 +59,11 @@ class DistanceApiSpec extends WordSpec with Matchers with ScalaFutures with Befo
53
59
" #distances" should {
54
60
" pass the same test suite than GoogleDistanceProvider" should {
55
61
def passTests [F [+ _]: Concurrent : Par ](runSync : F [Any ] => Any ): Unit = {
56
- val geocoder : GeoProvider [F ] = GoogleGeoProvider [F ](geoContext)
57
- val distanceApi : DistanceApi [F ] = DistanceApi [F ](GoogleDistanceProvider [F ](geoContext), CaffeineCache (Some (1 days)))
62
+ val geocoder : GeoProvider [F ] = GoogleGeoProvider [F ](geoContext)
63
+ val cachingF : CachingF [F , Distance ] = CaffeineCache [F ](Some (1 days)).cachingF[Distance ]
64
+ val distanceF : DistanceF [F ] = GoogleDistanceProvider [F ](geoContext).distance
65
+ val distanceApi : DistanceApi [F ] = DistanceApi [F ](distanceF, cachingF)
66
+
58
67
" says that Paris 02 is nearest to Paris 01 than Paris 18" in {
59
68
val paris01 = runSync(geocoder.geocode(PostalCode (" 75001" ))).asInstanceOf [LatLong ]
60
69
val paris02 = runSync(geocoder.geocode(PostalCode (" 75002" ))).asInstanceOf [LatLong ]
0 commit comments