|
1 | 1 | package com.baeldung.spring.drools.service; |
2 | 2 |
|
3 | | -import com.baeldung.spring.drools.model.Fare; |
4 | | -import com.baeldung.spring.drools.model.TaxiRide; |
5 | | -import org.junit.Assert; |
| 3 | +import static org.junit.Assert.assertEquals; |
| 4 | +import static org.junit.Assert.assertNotNull; |
| 5 | + |
6 | 6 | import org.junit.Test; |
7 | 7 | import org.junit.runner.RunWith; |
8 | 8 | import org.springframework.beans.factory.annotation.Autowired; |
9 | 9 | import org.springframework.test.context.ContextConfiguration; |
10 | 10 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; |
11 | 11 |
|
12 | | -import static org.junit.Assert.assertEquals; |
13 | | -import static org.junit.Assert.assertNotNull; |
| 12 | +import com.baeldung.spring.drools.model.Fare; |
| 13 | +import com.baeldung.spring.drools.model.TaxiRide; |
| 14 | + |
14 | 15 |
|
15 | 16 | @RunWith(SpringJUnit4ClassRunner.class) |
16 | 17 | @ContextConfiguration(classes = TaxiFareConfiguration.class) |
17 | 18 | public class TaxiFareCalculatorServiceIntegrationTest { |
18 | 19 |
|
19 | 20 | @Autowired |
20 | | - private TaxiFareCalculatorService taxiFareCalculatorService; |
| 21 | + TaxiFareCalculatorService taxiFareCalculatorService; |
21 | 22 |
|
22 | 23 | @Test |
23 | | - public void testCalculateFareScenario1() { |
| 24 | + public void whenNightSurchargeFalseAndDistanceLessThan10_thenFixFareWithoutNightSurcharge() { |
24 | 25 | TaxiRide taxiRide = new TaxiRide(); |
25 | | - taxiRide.setbNightSurcharge(false); |
| 26 | + taxiRide.setIsNightSurcharge(false); |
26 | 27 | taxiRide.setDistanceInMile(9L); |
27 | 28 | Fare rideFare = new Fare(); |
28 | 29 | Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); |
29 | | - |
30 | 30 | assertNotNull(totalCharge); |
31 | 31 | assertEquals(Long.valueOf(70), totalCharge); |
32 | 32 | } |
33 | | - |
| 33 | + |
34 | 34 | @Test |
35 | | - public void testCalculateFareScenario2() { |
| 35 | + public void whenNightSurchargeTrueAndDistanceLessThan10_thenFixFareWithNightSurcharge() { |
36 | 36 | TaxiRide taxiRide = new TaxiRide(); |
37 | | - taxiRide.setbNightSurcharge(true); |
| 37 | + taxiRide.setIsNightSurcharge(true); |
38 | 38 | taxiRide.setDistanceInMile(5L); |
39 | 39 | Fare rideFare = new Fare(); |
40 | 40 | Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); |
41 | | - |
42 | 41 | assertNotNull(totalCharge); |
43 | 42 | assertEquals(Long.valueOf(100), totalCharge); |
44 | 43 | } |
45 | 44 |
|
46 | 45 | @Test |
47 | | - public void testCalculateFareScenario3() { |
| 46 | + public void whenNightSurchargeFalseAndDistanceLessThan100_thenDoubleFareWithoutNightSurcharge() { |
48 | 47 | TaxiRide taxiRide = new TaxiRide(); |
49 | | - taxiRide.setbNightSurcharge(false); |
| 48 | + taxiRide.setIsNightSurcharge(false); |
50 | 49 | taxiRide.setDistanceInMile(50L); |
51 | 50 | Fare rideFare = new Fare(); |
52 | 51 | Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); |
53 | | - |
54 | 52 | assertNotNull(totalCharge); |
55 | 53 | assertEquals(Long.valueOf(170), totalCharge); |
56 | 54 | } |
57 | | - |
| 55 | + |
58 | 56 | @Test |
59 | | - public void testCalculateFareScenario4() { |
| 57 | + public void whenNightSurchargeTrueAndDistanceLessThan100_thenDoubleFareWithNightSurcharge() { |
60 | 58 | TaxiRide taxiRide = new TaxiRide(); |
61 | | - taxiRide.setbNightSurcharge(true); |
| 59 | + taxiRide.setIsNightSurcharge(true); |
62 | 60 | taxiRide.setDistanceInMile(50L); |
63 | 61 | Fare rideFare = new Fare(); |
64 | 62 | Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); |
65 | | - |
66 | 63 | assertNotNull(totalCharge); |
67 | 64 | assertEquals(Long.valueOf(250), totalCharge); |
68 | 65 | } |
69 | | - |
| 66 | + |
70 | 67 | @Test |
71 | | - public void testCalculateFareScenario5() { |
| 68 | + public void whenNightSurchargeFalseAndDistanceGreaterThan100_thenExtraPercentFareWithoutNightSurcharge() { |
72 | 69 | TaxiRide taxiRide = new TaxiRide(); |
73 | | - taxiRide.setbNightSurcharge(false); |
| 70 | + taxiRide.setIsNightSurcharge(false); |
74 | 71 | taxiRide.setDistanceInMile(100L); |
75 | 72 | Fare rideFare = new Fare(); |
76 | 73 | Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); |
77 | | - |
78 | 74 | assertNotNull(totalCharge); |
79 | 75 | assertEquals(Long.valueOf(220), totalCharge); |
80 | 76 | } |
81 | | - |
| 77 | + |
82 | 78 | @Test |
83 | | - public void testCalculateFareScenario6() { |
| 79 | + public void whenNightSurchargeTrueAndDistanceGreaterThan100_thenExtraPercentFareWithNightSurcharge() { |
84 | 80 | TaxiRide taxiRide = new TaxiRide(); |
85 | | - taxiRide.setbNightSurcharge(true); |
| 81 | + taxiRide.setIsNightSurcharge(true); |
86 | 82 | taxiRide.setDistanceInMile(100L); |
87 | 83 | Fare rideFare = new Fare(); |
88 | 84 | Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare); |
89 | | - |
90 | 85 | assertNotNull(totalCharge); |
91 | 86 | assertEquals(Long.valueOf(350), totalCharge); |
92 | 87 | } |
|
0 commit comments