@@ -6,19 +6,22 @@ import org.mockito.Mockito
6
6
import org.mockito.Mockito.mock
7
7
import travelator.Id
8
8
import travelator.destinations.FeaturedDestination
9
- import travelator.destinations.FeaturedDestinations
10
9
import travelator.domain.DistanceCalculator
11
10
import travelator.domain.Location
12
- import java.util.Set
13
11
14
12
class RecommendationsTests {
15
13
private val distanceCalculator = mock(DistanceCalculator ::class .java)
16
- private val featuredDestinations = mock(FeaturedDestinations ::class .java)
17
14
18
- private val recommendations = Recommendations (
19
- featuredDestinations::findCloseTo,
20
- distanceCalculator::distanceInMetersBetween
21
- )
15
+ private val featuredDestinations =
16
+ mutableMapOf<Location , List <FeaturedDestination >>()
17
+ .withDefault { emptyList() }
18
+
19
+ private val recommendations =
20
+ Recommendations (
21
+ featuredDestinations::getValue,
22
+ distanceCalculator::distanceInMetersBetween
23
+ )
24
+
22
25
private val paris = location(" Paris" )
23
26
private val louvre = featured(" Louvre" , " Rue de Rivoli" )
24
27
private val eiffelTower = featured(" Eiffel Tower" , " Champ de Mars" )
@@ -40,35 +43,35 @@ class RecommendationsTests {
40
43
givenFeaturedDestinationsFor(paris, emptyList())
41
44
Assertions .assertEquals(
42
45
emptyList<Any >(),
43
- recommendations.recommendationsFor(Set .of (paris))
46
+ recommendations.recommendationsFor(setOf (paris))
44
47
)
45
48
}
46
49
47
50
@Test
48
51
fun returns_recommendations_for_single_location () {
49
52
givenFeaturedDestinationsFor(
50
53
paris,
51
- java.util. List .of (
54
+ listOf (
52
55
eiffelTower,
53
56
louvre
54
57
)
55
58
)
56
59
givenADistanceBetween(paris, eiffelTower, 5000 )
57
60
givenADistanceBetween(paris, louvre, 1000 )
58
61
Assertions .assertEquals(
59
- java.util. List .of (
62
+ listOf (
60
63
FeaturedDestinationSuggestion (paris, louvre, 1000 ),
61
64
FeaturedDestinationSuggestion (paris, eiffelTower, 5000 )
62
65
),
63
- recommendations.recommendationsFor(Set .of (paris))
66
+ recommendations.recommendationsFor(setOf (paris))
64
67
)
65
68
}
66
69
67
70
@Test
68
71
fun returns_recommendations_for_multi_location () {
69
72
givenFeaturedDestinationsFor(
70
73
paris,
71
- java.util. List .of (
74
+ listOf (
72
75
eiffelTower,
73
76
louvre
74
77
)
@@ -77,29 +80,29 @@ class RecommendationsTests {
77
80
givenADistanceBetween(paris, louvre, 1000 )
78
81
givenFeaturedDestinationsFor(
79
82
alton,
80
- java.util. List .of (
83
+ listOf (
81
84
flowerFarm,
82
85
watercressLine
83
86
)
84
87
)
85
88
givenADistanceBetween(alton, flowerFarm, 5300 )
86
89
givenADistanceBetween(alton, watercressLine, 320 )
87
90
Assertions .assertEquals(
88
- java.util. List .of (
91
+ listOf (
89
92
FeaturedDestinationSuggestion (alton, watercressLine, 320 ),
90
93
FeaturedDestinationSuggestion (paris, louvre, 1000 ),
91
94
FeaturedDestinationSuggestion (paris, eiffelTower, 5000 ),
92
95
FeaturedDestinationSuggestion (alton, flowerFarm, 5300 )
93
96
),
94
- recommendations.recommendationsFor(Set .of (paris, alton))
97
+ recommendations.recommendationsFor(setOf (paris, alton))
95
98
)
96
99
}
97
100
98
101
@Test
99
102
fun deduplicates_using_smallest_distance () {
100
103
givenFeaturedDestinationsFor(
101
104
alton,
102
- java.util. List .of (
105
+ listOf (
103
106
flowerFarm,
104
107
watercressLine
105
108
)
@@ -108,19 +111,19 @@ class RecommendationsTests {
108
111
givenADistanceBetween(alton, watercressLine, 320 )
109
112
givenFeaturedDestinationsFor(
110
113
froyle,
111
- java.util. List .of (
114
+ listOf (
112
115
flowerFarm,
113
116
watercressLine
114
117
)
115
118
)
116
119
givenADistanceBetween(froyle, flowerFarm, 0 )
117
120
givenADistanceBetween(froyle, watercressLine, 6300 )
118
121
Assertions .assertEquals(
119
- java.util. List .of (
122
+ listOf (
120
123
FeaturedDestinationSuggestion (froyle, flowerFarm, 0 ),
121
124
FeaturedDestinationSuggestion (alton, watercressLine, 320 )
122
125
),
123
- recommendations.recommendationsFor(Set .of (alton, froyle))
126
+ recommendations.recommendationsFor(setOf (alton, froyle))
124
127
)
125
128
}
126
129
@@ -138,10 +141,9 @@ class RecommendationsTests {
138
141
139
142
private fun givenFeaturedDestinationsFor (
140
143
location : Location ,
141
- result : List <FeaturedDestination >
144
+ destinations : List <FeaturedDestination >
142
145
) {
143
- Mockito .`when `(featuredDestinations.findCloseTo(location))
144
- .thenReturn(result)
146
+ featuredDestinations[location] = destinations.toList()
145
147
}
146
148
147
149
private fun givenADistanceBetween (
0 commit comments