This commit is contained in:
Grzegorz Piwowarek
2017-06-30 06:35:55 +02:00
committed by GitHub
parent d66d02ce4f
commit df782e425b
3 changed files with 31 additions and 37 deletions
@@ -1,25 +1,23 @@
package com.baeldung.spring.drools.service;
import com.baeldung.spring.drools.model.Fare;
import com.baeldung.spring.drools.model.TaxiRide;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.spring.drools.model.TaxiRide;
import com.baeldung.spring.drools.model.Fare;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TaxiFareConfiguration.class)
public class TaxiFareCalculatorServiceTest {
@Autowired
TaxiFareCalculatorService taxiFareCalculatorService;
private TaxiFareCalculatorService taxiFareCalculatorService;
@Test
public void testCalculateFareScenario1() {
@@ -28,10 +26,11 @@ public class TaxiFareCalculatorServiceTest {
taxiRide.setDistanceInMile(9L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(70), totalCharge);
assertNotNull(totalCharge);
assertEquals(Long.valueOf(70), totalCharge);
}
@Test
public void testCalculateFareScenario2() {
TaxiRide taxiRide = new TaxiRide();
@@ -39,8 +38,9 @@ public class TaxiFareCalculatorServiceTest {
taxiRide.setDistanceInMile(5L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(100), totalCharge);
assertNotNull(totalCharge);
assertEquals(Long.valueOf(100), totalCharge);
}
@Test
@@ -50,10 +50,11 @@ public class TaxiFareCalculatorServiceTest {
taxiRide.setDistanceInMile(50L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(170), totalCharge);
assertNotNull(totalCharge);
assertEquals(Long.valueOf(170), totalCharge);
}
@Test
public void testCalculateFareScenario4() {
TaxiRide taxiRide = new TaxiRide();
@@ -61,10 +62,11 @@ public class TaxiFareCalculatorServiceTest {
taxiRide.setDistanceInMile(50L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(250), totalCharge);
assertNotNull(totalCharge);
assertEquals(Long.valueOf(250), totalCharge);
}
@Test
public void testCalculateFareScenario5() {
TaxiRide taxiRide = new TaxiRide();
@@ -72,10 +74,11 @@ public class TaxiFareCalculatorServiceTest {
taxiRide.setDistanceInMile(100L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(220), totalCharge);
assertNotNull(totalCharge);
assertEquals(Long.valueOf(220), totalCharge);
}
@Test
public void testCalculateFareScenario6() {
TaxiRide taxiRide = new TaxiRide();
@@ -83,8 +86,9 @@ public class TaxiFareCalculatorServiceTest {
taxiRide.setDistanceInMile(100L);
Fare rideFare = new Fare();
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
Assert.assertNotNull(totalCharge);
Assert.assertEquals(Long.valueOf(350), totalCharge);
assertNotNull(totalCharge);
assertEquals(Long.valueOf(350), totalCharge);
}
}