-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrderTest.kt
More file actions
65 lines (51 loc) · 1.75 KB
/
OrderTest.kt
File metadata and controls
65 lines (51 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package pro.adamski.objectMother
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
class OrderTest {
@Test
fun testCustomOrder() {
// Given
val customProduct = ObjectMother.product(name = "Custom Laptop", price = 2000.0)
// When
val customOrder = ObjectMother.order(products = listOf(customProduct))
// Then
assertOrderProduct(customOrder.products.first(), "Custom Laptop", 2000.0)
}
@Test
fun testRandomLargeOrder() {
// When
val largeOrder = ObjectMother.largeOrder()
// Then
assertOrderProducts(largeOrder, 100, 1000.0..5000.0)
}
@Test
fun testCustomOrderJava() {
// Given
val customProduct = ObjectMotherJava.product().withName("Custom Laptop").withPrice(2000.0).build()
// When
val customOrder = ObjectMotherJava.order().withProducts(listOf(customProduct)).build()
// Then
assertOrderProduct(customOrder.products.first(), "Custom Laptop", 2000.0)
}
@Test
fun testRandomLargeOrderJava() {
// When
val largeOrder = ObjectMotherJava.largeOrder()
// Then
assertOrderProducts(largeOrder, 100, 1000.0..5000.0)
}
private fun assertOrderProducts(
largeOrder: Order,
numberOfProducts: Int,
priceRange: ClosedFloatingPointRange<Double>
) {
assertThat(largeOrder.products).hasSize(numberOfProducts)
assertThat(largeOrder.products).allMatch {
it.price in priceRange
}
}
private fun assertOrderProduct(firstProduct: Product, name: String, price: Double) {
assertThat(firstProduct.name).isEqualTo(name)
assertThat(firstProduct.price).isEqualTo(price)
}
}