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

View File

@ -4,12 +4,10 @@ public class Fare {
private Long nightSurcharge;
private Long rideFare;
private Long totalFare;
public Fare() {
nightSurcharge = 0L;
rideFare = 0L;
totalFare = 0L;
}
public Long getNightSurcharge() {
@ -31,9 +29,4 @@ public class Fare {
public Long getTotalFare() {
return nightSurcharge + rideFare;
}
public void setTotalFare(Long totalFare) {
this.totalFare = totalFare;
}
}

View File

@ -13,7 +13,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class TaxiFareConfiguration {
public static final String drlFile = "TAXI_FARE_RULE.drl";
private static final String drlFile = "TAXI_FARE_RULE.drl";
@Bean
public KieContainer kieContainer() {
@ -25,14 +25,11 @@ public class TaxiFareConfiguration {
kieBuilder.buildAll();
KieModule kieModule = kieBuilder.getKieModule();
KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId());
return kContainer;
return kieServices.newKieContainer(kieModule.getReleaseId());
}
@Bean
public TaxiFareCalculatorService taxiFareCalculatorService() {
TaxiFareCalculatorService taxiFareCalculatorService = new TaxiFareCalculatorService();
return taxiFareCalculatorService;
return new TaxiFareCalculatorService();
}
}

View File

@ -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);
}
}