Skip to content

Commit 0d9d999

Browse files
committed
fix: explicit default subscription tiers in tests
1 parent 81dbc37 commit 0d9d999

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

exercises/tiered_pricing/solutions/adrianliz/java/src/main/java/tv/codely/checkout/TieredPricing.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@ public TieredPricing(final List<SubscriptionTier> subscriptionTiers) {
1010
this.subscriptionTiers = subscriptionTiers;
1111
}
1212

13-
public TieredPricing() {
14-
this(List.of(
15-
new SubscriptionTier(
16-
new SubscriptionTierRange(1, 2),
17-
new SubscriptionTierPrice(299)),
18-
new SubscriptionTier(
19-
new SubscriptionTierRange(3, 10),
20-
new SubscriptionTierPrice(239)),
21-
new SubscriptionTier(
22-
new SubscriptionTierRange(11, 25),
23-
new SubscriptionTierPrice(219)),
24-
new SubscriptionTier(
25-
new SubscriptionTierRange(26, 50),
26-
new SubscriptionTierPrice(199)),
27-
new SubscriptionTier(
28-
new SubscriptionTierRange(51, 100),
29-
new SubscriptionTierPrice(149))));
30-
}
31-
3213
public double getTotalPrice(int subscriptions) {
3314
return subscriptionTiers.stream()
3415
.filter(subscriptionTier -> subscriptionTier.isInRange(subscriptions))

exercises/tiered_pricing/solutions/adrianliz/java/src/test/java/tv/codely/checkout/TieredPricingShould.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,32 @@
33
import static org.junit.jupiter.api.Assertions.assertEquals;
44
import static org.junit.jupiter.api.Assertions.assertTrue;
55

6+
import java.util.List;
67
import org.junit.jupiter.api.Test;
78
import tv.codely.checkout.mother.IntegerMother;
89
import tv.codely.checkout.mother.SubscriptionTierMother;
910

1011
public class TieredPricingShould {
1112

13+
private static List<SubscriptionTier> defaultSubscriptionTiers() {
14+
return List.of(
15+
new SubscriptionTier(
16+
new SubscriptionTierRange(1, 2),
17+
new SubscriptionTierPrice(299)),
18+
new SubscriptionTier(
19+
new SubscriptionTierRange(3, 10),
20+
new SubscriptionTierPrice(239)),
21+
new SubscriptionTier(
22+
new SubscriptionTierRange(11, 25),
23+
new SubscriptionTierPrice(219)),
24+
new SubscriptionTier(
25+
new SubscriptionTierRange(26, 50),
26+
new SubscriptionTierPrice(199)),
27+
new SubscriptionTier(
28+
new SubscriptionTierRange(51, 100),
29+
new SubscriptionTierPrice(149)));
30+
}
31+
1232
@Test
1333
void unit_test_example() {
1434
assertTrue(true);
@@ -29,7 +49,7 @@ void return_total_price_based_on_number_of_subscriptions() {
2949

3050
@Test
3151
void return_total_price_for_1_subscription() {
32-
final var tieredPricing = new TieredPricing();
52+
final var tieredPricing = new TieredPricing(defaultSubscriptionTiers());
3353
final var expectedPrice = 299;
3454

3555
final var totalPrice = tieredPricing.getTotalPrice(1);
@@ -38,7 +58,7 @@ void return_total_price_for_1_subscription() {
3858

3959
@Test
4060
void return_total_price_for_3_subscriptions() {
41-
final var tieredPricing = new TieredPricing();
61+
final var tieredPricing = new TieredPricing(defaultSubscriptionTiers());
4262
final var expectedPrice = 239 * 3;
4363

4464
final var totalPrice = tieredPricing.getTotalPrice(3);
@@ -47,7 +67,7 @@ void return_total_price_for_3_subscriptions() {
4767

4868
@Test
4969
void return_total_price_for_11_subscriptions() {
50-
final var tieredPricing = new TieredPricing();
70+
final var tieredPricing = new TieredPricing(defaultSubscriptionTiers());
5171
final var expectedPrice = 219 * 11;
5272

5373
final var totalPrice = tieredPricing.getTotalPrice(11);
@@ -56,7 +76,7 @@ void return_total_price_for_11_subscriptions() {
5676

5777
@Test
5878
void return_total_price_for_26_subscriptions() {
59-
final var tieredPricing = new TieredPricing();
79+
final var tieredPricing = new TieredPricing(defaultSubscriptionTiers());
6080
final var expectedPrice = 199 * 26;
6181

6282
final var totalPrice = tieredPricing.getTotalPrice(26);
@@ -65,7 +85,7 @@ void return_total_price_for_26_subscriptions() {
6585

6686
@Test
6787
void return_total_price_for_51_subscriptions() {
68-
final var tieredPricing = new TieredPricing();
88+
final var tieredPricing = new TieredPricing(defaultSubscriptionTiers());
6989
final var expectedPrice = 149 * 51;
7090

7191
final var totalPrice = tieredPricing.getTotalPrice(51);

exercises/tiered_pricing/solutions/adrianliz/java/src/test/java/tv/codely/checkout/mother/SubscriptionTierMother.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ public static SubscriptionTier create(
1818
public static List<SubscriptionTier> randoms() {
1919
final var subscriptionTierRanges = SubscriptionTierRangeMother.randoms();
2020
final var previousSubscriptionTierPrice = new AtomicReference<>(299D);
21-
21+
2222
return subscriptionTierRanges.stream()
2323
.map(range -> {
2424
final var subscriptionTierPrice =
2525
DoubleMother.randomBetween(
2626
previousSubscriptionTierPrice.get().intValue() - 60,
2727
previousSubscriptionTierPrice.get().intValue() - 20);
2828
previousSubscriptionTierPrice.set(subscriptionTierPrice);
29-
return create(range, new SubscriptionTierPrice(subscriptionTierPrice));
29+
return create(range, SubscriptionTierPriceMother.create(subscriptionTierPrice));
3030
})
3131
.toList();
3232
}

exercises/tiered_pricing/solutions/adrianliz/java/src/test/java/tv/codely/checkout/mother/SubscriptionTierPriceMother.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,4 @@ public final class SubscriptionTierPriceMother {
77
public static SubscriptionTierPrice create(final double value) {
88
return new SubscriptionTierPrice(value);
99
}
10-
11-
public static SubscriptionTierPrice randomBetween(final int min, final int max) {
12-
return create(DoubleMother.randomBetween(min, max));
13-
}
1410
}

0 commit comments

Comments
 (0)