1
1
package fmt.kotlin.fundamentals
2
2
3
+ import fmt.kotlin.fundamentals.WineColor.RED
4
+ import fmt.kotlin.fundamentals.WineColor.WHITE
3
5
import org.junit.jupiter.api.Assertions.*
4
6
import org.junit.jupiter.api.Nested
5
7
import strikt.api.expectThat
@@ -14,38 +16,56 @@ class BottleTest {
14
16
inner class Equality {
15
17
@Test
16
18
fun `should be equals if name and year are equals` () {
17
- val isEqual = Bottle (" Coucheroy" , 2005 ).isEqualTo(Bottle (" Coucheroy" , 2005 ))
19
+ val isEqual = Bottle (" Coucheroy" , 2005 , RED ).isEqualTo(Bottle (" Coucheroy" , 2005 , RED ))
18
20
19
21
expectThat(isEqual).isTrue()
20
22
}
21
23
22
24
@Test
23
25
fun `should not be equals if year is different` () {
24
- val isEqual = Bottle (" Coucheroy" , 2005 ).isEqualTo(Bottle (" Coucheroy" , 2009 ))
26
+ val isEqual = Bottle (" Coucheroy" , 2005 , RED ).isEqualTo(Bottle (" Coucheroy" , 2009 , RED ))
25
27
26
28
expectThat(isEqual).isFalse()
27
29
}
28
30
29
31
@Test
30
32
fun `should not be equals if name is different` () {
31
- val isEqual = Bottle (" Coucheroy" , 2005 ).isEqualTo(Bottle (" Pedesclaux" , 2009 ))
33
+ val isEqual = Bottle (" Coucheroy" , 2005 , RED ).isEqualTo(Bottle (" Pedesclaux" , 2009 , RED ))
32
34
33
35
expectThat(isEqual).isFalse()
34
36
}
35
37
36
38
@Test
37
39
fun `should not be same instance even if name and year are equals` () {
38
- val isEqual = Bottle (" Coucheroy" , 2005 ).isSameInstance(Bottle (" Coucheroy" , 2005 ))
40
+ val isEqual = Bottle (" Coucheroy" , 2005 , RED ).isSameInstance(Bottle (" Coucheroy" , 2005 , RED ))
39
41
40
42
expectThat(isEqual).isFalse()
41
43
}
42
44
43
45
@Test
44
46
fun `should be same instance` () {
45
- val bottle = Bottle (" Coucheroy" , 2005 )
47
+ val bottle = Bottle (" Coucheroy" , 2005 , RED )
46
48
val isEqual = bottle.isSameInstance(bottle)
47
49
48
50
expectThat(isEqual).isTrue()
49
51
}
50
52
}
53
+
54
+ @Nested
55
+ inner class ToString {
56
+
57
+ @Test
58
+ fun `should describe the bottle of red` () {
59
+ val s = Bottle (" Coucheroy" , 2005 , RED ).toString()
60
+
61
+ expectThat(s).isEqualTo(" Bouteille de Coucheroy rouge de 2005" )
62
+ }
63
+
64
+ @Test
65
+ fun `should describe the bottle of white` () {
66
+ val s = Bottle (" Yquem" , 2006 , WHITE ).toString()
67
+
68
+ expectThat(s).isEqualTo(" Bouteille de Yquem blanc de 2006" )
69
+ }
70
+ }
51
71
}
0 commit comments