Skip to content

Commit fa2e623

Browse files
authored
add tests for equality to product item (#248)
* add tests for equality * test different constructors * remove deprecated constructor from difference check
1 parent c184ff4 commit fa2e623

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/test/groovy/life/qbic/datamodel/dtos/business/ProductItemSpec.groovy

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package life.qbic.datamodel.dtos.business
22

33
import life.qbic.datamodel.dtos.business.facilities.Facility
4+
import life.qbic.datamodel.dtos.business.services.PrimaryAnalysis
45
import life.qbic.datamodel.dtos.business.services.Product
56
import life.qbic.datamodel.dtos.business.services.ProductUnit
67
import life.qbic.datamodel.dtos.business.services.Sequencing
78
import spock.lang.Specification
9+
import spock.lang.Unroll
810

911
/**
1012
* Simple tests for the ProductItem dto class
@@ -25,6 +27,50 @@ class ProductItemSpec extends Specification {
2527
productItem.product == product
2628
}
2729

30+
def "Equal ProductItems shall be equal"() {
31+
32+
given: "two product item contents"
33+
def referenceProduct = new Sequencing("RNA Sequencing", "This package manages the pricing for all RNA sequencings", 1.0, 3.0, ProductUnit.PER_SAMPLE, 1, Facility.QBIC)
34+
Double referenceQuantity = 1.0
35+
Double referenceTotalPrice = 3.0
36+
Double referenceQuantityDiscount = 0.0
37+
38+
when: "two product items are created from the same content"
39+
ProductItem item1 = new ProductItem(referenceQuantity, referenceProduct, referenceTotalPrice, referenceQuantityDiscount)
40+
ProductItem item2 = new ProductItem(referenceQuantity, referenceProduct, referenceTotalPrice, referenceQuantityDiscount)
41+
42+
ProductItem item3 = new ProductItem(referenceQuantity, referenceProduct)
43+
ProductItem item4 = new ProductItem(referenceQuantity, referenceProduct)
44+
45+
then: "the product items are equal"
46+
item1 == item2
47+
item3 == item4
48+
}
49+
50+
@Unroll
51+
def "Different ProductItems shall be different for property #differentProperty"() {
52+
53+
given: "a reference product item and a different product"
54+
def referenceProduct = new Sequencing("RNA Sequencing", "This package manages the pricing for all RNA sequencings", 1.0, 3.0, ProductUnit.PER_SAMPLE, 1, Facility.QBIC)
55+
Double referenceQuantity = 1.0
56+
Double referenceTotalPrice = 3.0
57+
Double referenceQuantityDiscount = 0.0
58+
59+
when: "we create a product item with different information"
60+
ProductItem reference = new ProductItem(referenceQuantity, referenceProduct, referenceTotalPrice, referenceQuantityDiscount)
61+
ProductItem differentItem = new ProductItem(quantity, product, totalPrice, quantityDiscount)
62+
63+
then: "the product items are not equal"
64+
reference != differentItem
65+
66+
where: "for every property"
67+
differentProperty | quantity| product| totalPrice| quantityDiscount
68+
"quantity" | 1.0 +1 | new Sequencing("RNA Sequencing", "This package manages the pricing for all RNA sequencings", 1.0, 3.0, ProductUnit.PER_SAMPLE, 1, Facility.QBIC) | 3.0 | 0.0
69+
"product" | 1.0 | new PrimaryAnalysis("Test", "Different description", 1.0, 3.0, ProductUnit.PER_SAMPLE, 1, Facility.QBIC) | 3.0 | 0.0
70+
"totalPrice" | 1.0 | new Sequencing("RNA Sequencing", "This package manages the pricing for all RNA sequencings", 1.0, 3.0, ProductUnit.PER_SAMPLE, 1, Facility.QBIC) | 3.0 +1 | 0.0
71+
"quantityDiscount" | 1.0 | new Sequencing("RNA Sequencing", "This package manages the pricing for all RNA sequencings", 1.0, 3.0, ProductUnit.PER_SAMPLE, 1, Facility.QBIC) | 3.0 | 0.0 + 1
72+
}
73+
2874
def "Products shall be comparable"(){
2975
when:
3076

0 commit comments

Comments
 (0)