Skip to content

Commit 1518821

Browse files
committed
Refactor(test): Parameterize subscriptions
1 parent 30975cb commit 1518821

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed
Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package tv.codely.checkout;
22

33
import org.junit.jupiter.api.BeforeEach;
4-
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.params.ParameterizedTest;
5+
import org.junit.jupiter.params.provider.MethodSource;
6+
7+
import java.util.stream.IntStream;
8+
import java.util.stream.Stream;
59

610
import static org.assertj.core.api.Assertions.assertThat;
711

@@ -14,31 +18,39 @@ void setUp() {
1418
tieredPricing = new TieredPricing();
1519
}
1620

17-
@Test
18-
void returnFirstTierUnitPriceForOneSubscription() {
19-
double totalPrice = tieredPricing.totalPrice(1);
21+
@ParameterizedTest
22+
@MethodSource("rangeFirstTier")
23+
void returnTotalPriceForFirstTier(int subscriptions) {
24+
double totalPrice = tieredPricing.totalPrice(subscriptions);
2025

21-
assertThat(totalPrice).isEqualTo(299.0);
26+
assertThat(totalPrice).isEqualTo(subscriptions * 299.0);
2227
}
2328

24-
@Test
25-
void returnDoubleTheFirstTierUnitPriceForTwoSubscriptions() {
26-
double totalPrice = tieredPricing.totalPrice(2);
29+
@ParameterizedTest
30+
@MethodSource("rangeSecondTier")
31+
void returnTotalPriceForSecondTier(int subscriptions) {
32+
double totalPrice = tieredPricing.totalPrice(subscriptions);
2733

28-
assertThat(totalPrice).isEqualTo(598.0);
34+
assertThat(totalPrice).isEqualTo(subscriptions * 239.0);
2935
}
3036

31-
@Test
32-
void returnTripleTheSecondTierUnitPriceForThreeSubscriptions() {
33-
double totalPrice = tieredPricing.totalPrice(3);
37+
@ParameterizedTest
38+
@MethodSource("rangeThirdTier")
39+
void returnTotalPriceForThirdTier(int subscriptions) {
40+
double totalPrice = tieredPricing.totalPrice(subscriptions);
41+
42+
assertThat(totalPrice).isEqualTo(subscriptions * 219.0);
43+
}
3444

35-
assertThat(totalPrice).isEqualTo(717.0);
45+
private static Stream<Integer> rangeFirstTier() {
46+
return IntStream.rangeClosed(1, 2).boxed();
3647
}
3748

38-
@Test
39-
void returnElevenTimesTheThirdTierUnitPriceForElevenSubscriptions() {
40-
double totalPrice = tieredPricing.totalPrice(11);
49+
private static Stream<Integer> rangeSecondTier() {
50+
return IntStream.rangeClosed(3, 10).boxed();
51+
}
4152

42-
assertThat(totalPrice).isEqualTo(2409.0);
53+
private static Stream<Integer> rangeThirdTier() {
54+
return IntStream.rangeClosed(11, 25).boxed();
4355
}
4456
}

0 commit comments

Comments
 (0)