Skip to content

Commit 1a1e020

Browse files
committed
BroadleafCommerce#1108 - Updated tests to better utilize groovy syntax and practices
1 parent 1273380 commit 1a1e020

File tree

5 files changed

+87
-80
lines changed

5 files changed

+87
-80
lines changed

core/broadleaf-framework/src/test/groovy/org/broadleafcommerce/core/spec/pricing/service/workflow/BasePricingActivitySpec.groovy

+11-7
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
* limitations under the License.
1818
* #L%
1919
*/
20+
/**
21+
* @author Austin Rooke (austinrooke)
22+
*/
2023
package org.broadleafcommerce.core.spec.pricing.service.workflow
2124

2225
import org.broadleafcommerce.core.order.domain.Order
2326
import org.broadleafcommerce.core.order.domain.OrderImpl
2427
import org.broadleafcommerce.core.workflow.BaseActivity
2528
import org.broadleafcommerce.core.workflow.DefaultProcessContextImpl
2629
import org.broadleafcommerce.core.workflow.ProcessContext
27-
import org.broadleafcommerce.profile.core.domain.Customer
2830
import org.broadleafcommerce.profile.core.domain.CustomerImpl
2931

3032
import spock.lang.Specification
@@ -36,13 +38,15 @@ class BasePricingActivitySpec extends Specification {
3638

3739
def setup() {
3840

39-
Customer customer = new CustomerImpl()
40-
customer.id = 1
41-
Order order = new OrderImpl()
42-
order.id = 1
43-
order.customer = customer
4441
context = new DefaultProcessContextImpl<Order>().with() {
45-
seedData = order
42+
seedData = new OrderImpl().with() {
43+
id = 1
44+
customer = new CustomerImpl().with() {
45+
id = 1
46+
it
47+
}
48+
it
49+
}
4650
it
4751
}
4852
}

core/broadleaf-framework/src/test/groovy/org/broadleafcommerce/core/spec/pricing/service/workflow/ConsolidateFulfillmentFeesActivitySpec.groovy

+38-25
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,66 @@
1717
* limitations under the License.
1818
* #L%
1919
*/
20+
/**
21+
* @author Austin Rooke (austinrooke)
22+
*/
2023
package org.broadleafcommerce.core.spec.pricing.service.workflow
2124

2225
import org.broadleafcommerce.common.money.Money
23-
import org.broadleafcommerce.core.catalog.domain.Sku
24-
import org.broadleafcommerce.core.catalog.domain.SkuFee
2526
import org.broadleafcommerce.core.catalog.domain.SkuFeeImpl
2627
import org.broadleafcommerce.core.catalog.domain.SkuImpl
2728
import org.broadleafcommerce.core.catalog.service.type.SkuFeeType
28-
import org.broadleafcommerce.core.order.domain.BundleOrderItem
2929
import org.broadleafcommerce.core.order.domain.BundleOrderItemImpl
30-
import org.broadleafcommerce.core.order.domain.FulfillmentGroup
3130
import org.broadleafcommerce.core.order.domain.FulfillmentGroupFeeImpl
3231
import org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl
33-
import org.broadleafcommerce.core.order.domain.FulfillmentGroupItem
3432
import org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl
3533
import org.broadleafcommerce.core.order.domain.Order
3634
import org.broadleafcommerce.core.order.service.FulfillmentGroupService
3735
import org.broadleafcommerce.core.pricing.service.workflow.ConsolidateFulfillmentFeesActivity
3836

3937
class ConsolidateFulfillmentFeesActivitySpec extends BasePricingActivitySpec {
4038

39+
/*
40+
* The code coverage on this spec is only 69.4% due to not knowing what the format of
41+
* SkuFee expression statements are for the method shouldApplyFeeToFulfillmentGroup
42+
* to be further tested.
43+
*
44+
* If someone, whom knows this information, would like to write a test to up the code
45+
* coverage, please do so.
46+
*/
4147
FulfillmentGroupService mockFulfillmentGroupService
4248
Order order
4349
def setup() {
4450
//Setup a valid FulfillmentGroup with a FulfillmentItem inside
4551
// and place it inside the context.seedData order object
46-
FulfillmentGroup fulfillmentGroup = new FulfillmentGroupImpl()
47-
FulfillmentGroupItem fulfillmentGroupItem = new FulfillmentGroupItemImpl()
48-
SkuFee skuFee = new SkuFeeImpl()
49-
skuFee.feeType = SkuFeeType.FULFILLMENT
50-
skuFee.name = "Test"
51-
skuFee.taxable = true
52-
skuFee.amount = new Money(1.00)
53-
BundleOrderItem bundleOrderItem = new BundleOrderItemImpl()
54-
Sku sku = new SkuImpl()
55-
sku.id = 1
56-
sku.retailPrice = new Money(1.00)
57-
sku.fees = new ArrayList()
58-
sku.fees.add(skuFee)
59-
bundleOrderItem.sku = sku
60-
fulfillmentGroupItem.orderItem = bundleOrderItem
61-
List<FulfillmentGroupItem> fulfillmentGroupItems = new ArrayList()
62-
fulfillmentGroupItems.add(fulfillmentGroupItem)
63-
fulfillmentGroup.fulfillmentGroupItems = fulfillmentGroupItems
64-
context.seedData.fulfillmentGroups = new ArrayList<FulfillmentGroup>()
65-
context.seedData.fulfillmentGroups.add(fulfillmentGroup)
6652
order = context.seedData
53+
context.seedData.fulfillmentGroups = [
54+
new FulfillmentGroupImpl().with() {
55+
fulfillmentGroupItems = [
56+
new FulfillmentGroupItemImpl().with() {
57+
orderItem = new BundleOrderItemImpl().with() {
58+
sku = new SkuImpl().with() {
59+
id = 1
60+
retailPrice = new Money('1.00')
61+
fees = [
62+
new SkuFeeImpl().with() {
63+
feeType = SkuFeeType.FULFILLMENT
64+
name = 'Test'
65+
taxable = true
66+
amount = new Money('1.00')
67+
it
68+
}
69+
] as List
70+
it
71+
}
72+
it
73+
}
74+
it
75+
}
76+
]
77+
it
78+
}
79+
]
6780
}
6881

6982
def "Test a valid run with valid data"() {

core/broadleaf-framework/src/test/groovy/org/broadleafcommerce/core/spec/pricing/service/workflow/FulfillmentGroupMerchandiseTotalActivitySpec.groovy

+23-30
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
package org.broadleafcommerce.core.spec.pricing.service.workflow
2424

2525
import org.broadleafcommerce.common.money.Money
26-
import org.broadleafcommerce.core.order.domain.FulfillmentGroup
2726
import org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl
28-
import org.broadleafcommerce.core.order.domain.FulfillmentGroupItem
2927
import org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl
3028
import org.broadleafcommerce.core.order.domain.OrderItem
3129
import org.broadleafcommerce.core.order.domain.OrderItemImpl
@@ -56,35 +54,30 @@ class FulfillmentGroupMerchandiseTotalActivitySpec extends BasePricingActivitySp
5654
order = context.seedData
5755
it
5856
}
59-
FulfillmentGroupItem fulfillmentGroupItem1 = new FulfillmentGroupItemImpl().with() {
60-
orderItem = orderItem1
61-
quantity = 1
62-
it
63-
}
64-
FulfillmentGroupItem fulfillmentGroupItem2 = new FulfillmentGroupItemImpl().with() {
65-
orderItem = orderItem2
66-
quantity = 2
67-
it
68-
}
69-
FulfillmentGroupItem fulfillmentGroupItem3 = new FulfillmentGroupItemImpl().with() {
70-
orderItem = orderItem2
71-
quantity = 3
72-
it
73-
}
74-
FulfillmentGroup fulfillmentGroup1 = new FulfillmentGroupImpl().with() {
75-
fulfillmentGroupItems << fulfillmentGroupItem1
76-
fulfillmentGroupItems << fulfillmentGroupItem2
77-
order = context.seedData
78-
it
79-
}
80-
FulfillmentGroup fulfillmentGroup2 = new FulfillmentGroupImpl().with() {
81-
fulfillmentGroupItems << fulfillmentGroupItem3
82-
order = context.seedData
83-
it
84-
}
8557
context.seedData.fulfillmentGroups = [
86-
fulfillmentGroup1,
87-
fulfillmentGroup2
58+
new FulfillmentGroupImpl().with() {
59+
fulfillmentGroupItems << new FulfillmentGroupItemImpl().with() {
60+
orderItem = orderItem1
61+
quantity = 1
62+
it
63+
}
64+
fulfillmentGroupItems << new FulfillmentGroupItemImpl().with() {
65+
orderItem = orderItem2
66+
quantity = 2
67+
it
68+
}
69+
order = context.seedData
70+
it
71+
},
72+
new FulfillmentGroupImpl().with() {
73+
fulfillmentGroupItems << new FulfillmentGroupItemImpl().with() {
74+
orderItem = orderItem2
75+
quantity = 3
76+
it
77+
}
78+
order = context.seedData
79+
it
80+
}
8881
]
8982
}
9083

core/broadleaf-framework/src/test/groovy/org/broadleafcommerce/core/spec/pricing/service/workflow/FulfillmentGroupPricingActivitySpec.groovy

+11-13
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,19 @@ class FulfillmentGroupPricingActivitySpec extends BasePricingActivitySpec {
4444
*/
4545
FulfillmentPricingService mockFulfillmentPricingService
4646
def setup() {
47-
FulfillmentGroup fulfillmentGroup1 = new FulfillmentGroupImpl().with {
48-
shippingOverride = false
49-
order = context.seedData
50-
it
51-
}
52-
FulfillmentGroup fulfillmentGroup2 = new FulfillmentGroupImpl().with {
53-
shippingOverride = true
54-
fulfillmentPrice = new Money('1.00')
55-
order = context.seedData
56-
it
57-
}
5847
context.seedData.fulfillmentGroups = [
5948
null,
60-
fulfillmentGroup1,
61-
fulfillmentGroup2
49+
new FulfillmentGroupImpl().with {
50+
shippingOverride = false
51+
order = context.seedData
52+
it
53+
},
54+
new FulfillmentGroupImpl().with {
55+
shippingOverride = true
56+
fulfillmentPrice = new Money('1.00')
57+
order = context.seedData
58+
it
59+
}
6260
]
6361
mockFulfillmentPricingService = Mock()
6462
}

core/broadleaf-framework/src/test/groovy/org/broadleafcommerce/core/spec/pricing/service/workflow/OfferActivitySpec.groovy

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
* limitations under the License.
1818
* #L%
1919
*/
20+
/**
21+
* @author Austin Rooke (austinrooke)
22+
*/
2023
package org.broadleafcommerce.core.spec.pricing.service.workflow
2124

22-
import org.broadleafcommerce.core.offer.domain.OfferCode
2325
import org.broadleafcommerce.core.offer.domain.OfferCodeImpl
2426
import org.broadleafcommerce.core.offer.service.OfferService
2527
import org.broadleafcommerce.core.order.service.OrderService
@@ -36,9 +38,6 @@ class OfferActivitySpec extends BasePricingActivitySpec {
3638
}
3739

3840
def"Test a valid run with valid data"() {
39-
setup: "Prepare a List of OfferCode's"
40-
List<OfferCode> offerCodes = new ArrayList<OfferCode>()
41-
offerCodes.add(new OfferCodeImpl())
4241

4342
activity = new OfferActivity().with {
4443
offerService = mockOfferService
@@ -50,7 +49,7 @@ class OfferActivitySpec extends BasePricingActivitySpec {
5049
context = activity.execute(context)
5150

5251
then: "orderService's addOfferCodes should have run and offerService's buildOfferListForOrder as well as applyAndSaveOffersToOrder should have run"
53-
1 * mockOfferService.buildOfferCodeListForCustomer(_) >> offerCodes
52+
1 * mockOfferService.buildOfferCodeListForCustomer(_) >> [new OfferCodeImpl()]
5453
1 * mockOfferService.applyAndSaveOffersToOrder(_, _) >> context.seedData
5554
1 * mockOrderService.addOfferCodes(_, _, _) >> context.seedData
5655
context.seedData != null

0 commit comments

Comments
 (0)