Reformat (#2177)
This commit is contained in:
parent
d66d02ce4f
commit
df782e425b
|
@ -4,12 +4,10 @@ public class Fare {
|
||||||
|
|
||||||
private Long nightSurcharge;
|
private Long nightSurcharge;
|
||||||
private Long rideFare;
|
private Long rideFare;
|
||||||
private Long totalFare;
|
|
||||||
|
|
||||||
public Fare() {
|
public Fare() {
|
||||||
nightSurcharge = 0L;
|
nightSurcharge = 0L;
|
||||||
rideFare = 0L;
|
rideFare = 0L;
|
||||||
totalFare = 0L;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getNightSurcharge() {
|
public Long getNightSurcharge() {
|
||||||
|
@ -31,9 +29,4 @@ public class Fare {
|
||||||
public Long getTotalFare() {
|
public Long getTotalFare() {
|
||||||
return nightSurcharge + rideFare;
|
return nightSurcharge + rideFare;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTotalFare(Long totalFare) {
|
|
||||||
this.totalFare = totalFare;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class TaxiFareConfiguration {
|
public class TaxiFareConfiguration {
|
||||||
|
|
||||||
public static final String drlFile = "TAXI_FARE_RULE.drl";
|
private static final String drlFile = "TAXI_FARE_RULE.drl";
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public KieContainer kieContainer() {
|
public KieContainer kieContainer() {
|
||||||
|
@ -25,14 +25,11 @@ public class TaxiFareConfiguration {
|
||||||
kieBuilder.buildAll();
|
kieBuilder.buildAll();
|
||||||
KieModule kieModule = kieBuilder.getKieModule();
|
KieModule kieModule = kieBuilder.getKieModule();
|
||||||
|
|
||||||
KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId());
|
return kieServices.newKieContainer(kieModule.getReleaseId());
|
||||||
|
|
||||||
return kContainer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public TaxiFareCalculatorService taxiFareCalculatorService() {
|
public TaxiFareCalculatorService taxiFareCalculatorService() {
|
||||||
TaxiFareCalculatorService taxiFareCalculatorService = new TaxiFareCalculatorService();
|
return new TaxiFareCalculatorService();
|
||||||
return taxiFareCalculatorService;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,23 @@
|
||||||
package com.baeldung.spring.drools.service;
|
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.Assert;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
|
||||||
|
|
||||||
import com.baeldung.spring.drools.model.TaxiRide;
|
import static org.junit.Assert.assertEquals;
|
||||||
import com.baeldung.spring.drools.model.Fare;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = TaxiFareConfiguration.class)
|
@ContextConfiguration(classes = TaxiFareConfiguration.class)
|
||||||
public class TaxiFareCalculatorServiceTest {
|
public class TaxiFareCalculatorServiceTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
TaxiFareCalculatorService taxiFareCalculatorService;
|
private TaxiFareCalculatorService taxiFareCalculatorService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCalculateFareScenario1() {
|
public void testCalculateFareScenario1() {
|
||||||
|
@ -28,8 +26,9 @@ public class TaxiFareCalculatorServiceTest {
|
||||||
taxiRide.setDistanceInMile(9L);
|
taxiRide.setDistanceInMile(9L);
|
||||||
Fare rideFare = new Fare();
|
Fare rideFare = new Fare();
|
||||||
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
||||||
Assert.assertNotNull(totalCharge);
|
|
||||||
Assert.assertEquals(Long.valueOf(70), totalCharge);
|
assertNotNull(totalCharge);
|
||||||
|
assertEquals(Long.valueOf(70), totalCharge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -39,8 +38,9 @@ public class TaxiFareCalculatorServiceTest {
|
||||||
taxiRide.setDistanceInMile(5L);
|
taxiRide.setDistanceInMile(5L);
|
||||||
Fare rideFare = new Fare();
|
Fare rideFare = new Fare();
|
||||||
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
||||||
Assert.assertNotNull(totalCharge);
|
|
||||||
Assert.assertEquals(Long.valueOf(100), totalCharge);
|
assertNotNull(totalCharge);
|
||||||
|
assertEquals(Long.valueOf(100), totalCharge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -50,8 +50,9 @@ public class TaxiFareCalculatorServiceTest {
|
||||||
taxiRide.setDistanceInMile(50L);
|
taxiRide.setDistanceInMile(50L);
|
||||||
Fare rideFare = new Fare();
|
Fare rideFare = new Fare();
|
||||||
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
||||||
Assert.assertNotNull(totalCharge);
|
|
||||||
Assert.assertEquals(Long.valueOf(170), totalCharge);
|
assertNotNull(totalCharge);
|
||||||
|
assertEquals(Long.valueOf(170), totalCharge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -61,8 +62,9 @@ public class TaxiFareCalculatorServiceTest {
|
||||||
taxiRide.setDistanceInMile(50L);
|
taxiRide.setDistanceInMile(50L);
|
||||||
Fare rideFare = new Fare();
|
Fare rideFare = new Fare();
|
||||||
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
||||||
Assert.assertNotNull(totalCharge);
|
|
||||||
Assert.assertEquals(Long.valueOf(250), totalCharge);
|
assertNotNull(totalCharge);
|
||||||
|
assertEquals(Long.valueOf(250), totalCharge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -72,8 +74,9 @@ public class TaxiFareCalculatorServiceTest {
|
||||||
taxiRide.setDistanceInMile(100L);
|
taxiRide.setDistanceInMile(100L);
|
||||||
Fare rideFare = new Fare();
|
Fare rideFare = new Fare();
|
||||||
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
||||||
Assert.assertNotNull(totalCharge);
|
|
||||||
Assert.assertEquals(Long.valueOf(220), totalCharge);
|
assertNotNull(totalCharge);
|
||||||
|
assertEquals(Long.valueOf(220), totalCharge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -83,8 +86,9 @@ public class TaxiFareCalculatorServiceTest {
|
||||||
taxiRide.setDistanceInMile(100L);
|
taxiRide.setDistanceInMile(100L);
|
||||||
Fare rideFare = new Fare();
|
Fare rideFare = new Fare();
|
||||||
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
Long totalCharge = taxiFareCalculatorService.calculateFare(taxiRide, rideFare);
|
||||||
Assert.assertNotNull(totalCharge);
|
|
||||||
Assert.assertEquals(Long.valueOf(350), totalCharge);
|
assertNotNull(totalCharge);
|
||||||
|
assertEquals(Long.valueOf(350), totalCharge);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue