-
Notifications
You must be signed in to change notification settings - Fork 14
/
AbstractFactoryTest.kt
50 lines (46 loc) · 1.93 KB
/
AbstractFactoryTest.kt
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
package org.vld.sdp.creational
import org.assertj.core.api.Assertions.* // ktlint-disable no-wildcard-imports
import org.junit.jupiter.api.DisplayName
import org.junit.jupiter.api.TestInstance
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.Arguments
import org.junit.jupiter.params.provider.MethodSource
import java.util.stream.Stream
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class AbstractFactoryTest {
@DisplayName("Given an abstract factory. When create a family of products. Then return the products from a given family")
@ParameterizedTest(name = "{1}, {2}")
@MethodSource("abstractFactoryProvider")
fun givenAbstractFactory_whenCreateFamilyOfProducts_thenReturnProductsFromAGivenFamily(
abstractFactory: DocumentCreator,
letterName: String,
resumeName: String,
expectedLetter: Letter,
expectedResume: Resume
) {
// Given & When
// client works only with the DocumentCreator abstract factory interface
// and the Letter and Resume family product interfaces
val letter: Letter = abstractFactory.createLetter(letterName)
val resume: Resume = abstractFactory.createResume(resumeName)
// Then
assertThat(letter).isEqualTo(expectedLetter)
assertThat(resume).isEqualTo(expectedResume)
}
fun abstractFactoryProvider(): Stream<Arguments> = Stream.of(
Arguments.of(
ModernDocumentCreator,
"Modern Letter",
"Modern Resume",
ModernLetter("Modern Letter"),
ModernResume("Modern Resume")
),
Arguments.of(
FancyDocumentCreator,
"Fancy Letter",
"Fancy Resume",
FancyLetter("Fancy Letter"),
FancyResume("Fancy Resume")
)
)
}