@@ -14,9 +14,9 @@ class CellarTest {
1414        // Etant donné que
1515        val  cellar =  Cellar (5 )
1616
17-         val  bottleMock =  // TODO 
17+         val  bottleMock =  mockk< Bottle >() 
1818
19-         // TODO Mocker l'appel de Bottle .description pour retourner  Bottle à chaque fois 
19+         every { bottleMock .description() } returns  " Bottle" 
2020
2121        cellar.addBottle(bottleMock)
2222        cellar.addBottle(bottleMock)
@@ -32,10 +32,17 @@ class CellarTest {
3232    @Test
3333    fun  `Should compute cellar value`  () {
3434        // Etant donné que
35-         val  wineStoreMock =  // TODO
36-         val  cellar =  Cellar (5 )
37- 
38-         // TODO Mocker l'appel de WineStoreMock.bottlePrice en capturant le paramètre
35+         val  wineStoreMock =  mockk<WineStore >()
36+         val  cellar =  Cellar (5 , wineStoreMock)
37+ 
38+         val  captureSlot =  slot<Bottle >()
39+         every { wineStoreMock.bottlePrice(capture(captureSlot)) } answers {
40+             if  (captureSlot.captured.color ==  WineColor .WHITE ) {
41+                 10 
42+             } else  {
43+                 20 
44+             }
45+         }
3946
4047        cellar.addBottle(Bottle (" Haut-Brion"  , 1997 , WineColor .RED ))
4148        cellar.addBottle(Bottle (" Margaux"  , 2012 , WineColor .WHITE ))
@@ -46,6 +53,6 @@ class CellarTest {
4653
4754        // Alors
4855        assertEquals(50 , value)
49-         // TODO Vérifier que le prix a été calculé trois fois (1 fois par bouteille) 
56+         verify(exactly  =   3 ) { wineStoreMock.bottlePrice(any()) } 
5057    }
5158}
0 commit comments