Skip to content
This repository was archived by the owner on Dec 5, 2023. It is now read-only.

Commit 68864d2

Browse files
author
Phil Winder
committed
Initial unit tests.
1 parent 4fee5af commit 68864d2

File tree

7 files changed

+99
-6
lines changed

7 files changed

+99
-6
lines changed

src/main/java/works/weave/socks/orders/entities/Address.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public String getId() {
6262
return id;
6363
}
6464

65+
public void setId(String id) {
66+
this.id = id;
67+
}
68+
6569
public String getNumber() {
6670
return number;
6771
}

src/main/java/works/weave/socks/orders/entities/Card.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public String getId() {
5555
return id;
5656
}
5757

58+
public void setId(String id) {
59+
this.id = id;
60+
}
61+
5862
public String getLongNum() {
5963
return longNum;
6064
}

src/main/java/works/weave/socks/orders/entities/Cart.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@Document
1212
public class Cart {
1313
@NotNull
14-
public String customerId; // Public instead of getters/setters.
14+
private String customerId;
1515
@Id
1616
private String id;
1717
@DBRef
@@ -39,6 +39,30 @@ public Cart remove(Item item) {
3939
return this;
4040
}
4141

42+
public String getCustomerId() {
43+
return customerId;
44+
}
45+
46+
public void setCustomerId(String customerId) {
47+
this.customerId = customerId;
48+
}
49+
50+
public String getId() {
51+
return id;
52+
}
53+
54+
public void setId(String id) {
55+
this.id = id;
56+
}
57+
58+
public List<Item> getItems() {
59+
return items;
60+
}
61+
62+
public void setItems(List<Item> items) {
63+
this.items = items;
64+
}
65+
4266
@Override
4367
public String toString() {
4468
return "Cart{" +

src/main/java/works/weave/socks/orders/entities/Customer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ public String getId() {
7676
return id;
7777
}
7878

79+
public void setId(String id) {
80+
this.id = id;
81+
}
82+
7983
public String getFirstName() {
8084
return firstName;
8185
}

src/main/java/works/weave/socks/orders/entities/CustomerOrder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public String getId() {
7373
return id;
7474
}
7575

76+
public void setId(String id) {
77+
this.id = id;
78+
}
79+
7680
public String getCustomerId() {
7781
return this.customerId;
7882
}
@@ -109,6 +113,10 @@ public Collection<Item> getItems() {
109113
return items;
110114
}
111115

116+
public void setItems(Collection<Item> items) {
117+
this.items = items;
118+
}
119+
112120
public void setItems(List<Item> items) {
113121
this.items = items;
114122
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package works.weave.socks.orders.entities;
2+
3+
import com.openpojo.reflection.PojoClass;
4+
import com.openpojo.reflection.PojoClassFilter;
5+
import com.openpojo.reflection.filters.FilterClassName;
6+
import com.openpojo.reflection.impl.PojoClassFactory;
7+
import com.openpojo.validation.Validator;
8+
import com.openpojo.validation.ValidatorBuilder;
9+
import com.openpojo.validation.affirm.Affirm;
10+
import com.openpojo.validation.rule.impl.*;
11+
import com.openpojo.validation.test.impl.GetterTester;
12+
import com.openpojo.validation.test.impl.SetterTester;
13+
import org.junit.Test;
14+
15+
import java.util.List;
16+
17+
public class UnitPojo {
18+
// Configured for expectation, so we know when a class gets added or removed.
19+
private static final int EXPECTED_CLASS_COUNT = 7;
20+
21+
// The package to test
22+
private static final String POJO_PACKAGE = "works.weave.socks.orders.entities";
23+
24+
private final PojoClassFilter filter = new FilterClassName("^((?!Unit).)*$");
25+
26+
@Test
27+
public void ensureExpectedPojoCount() {
28+
List<PojoClass> pojoClasses = PojoClassFactory.getPojoClasses(POJO_PACKAGE, filter);
29+
Affirm.affirmEquals("Classes added / removed?", EXPECTED_CLASS_COUNT, pojoClasses.size());
30+
}
31+
32+
@Test
33+
public void testPojoStructureAndBehavior() {
34+
Validator validator = ValidatorBuilder.create()
35+
// Add Rules to validate structure for POJO_PACKAGE
36+
// See com.openpojo.validation.rule.impl for more ...
37+
.with(new GetterMustExistRule())
38+
.with(new SetterMustExistRule())
39+
// Add Testers to validate behaviour for POJO_PACKAGE
40+
// See com.openpojo.validation.test.impl for more ...
41+
.with(new SetterTester())
42+
.with(new GetterTester())
43+
// Static fields must be final
44+
.with(new NoStaticExceptFinalRule())
45+
// Don't shadow parent's field names.
46+
.with(new NoFieldShadowingRule())
47+
// What about public fields, use one of the following rules
48+
// allow them only if they are static and final.
49+
.with(new NoPublicFieldsExceptStaticFinalRule())
50+
.build();
51+
52+
validator.validate(POJO_PACKAGE, filter);
53+
}
54+
}

test/coveralls.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ def test_maven(self):
2424
'verify',
2525
'jacoco:report',
2626
'coveralls:report']
27-
print("Coveralls command: ",
28-
'-DserviceJobId=' + os.getenv('TRAVIS_JOB_ID'),
29-
'-Dbranch=' + os.getenv('TRAVIS_BRANCH'),
30-
'-DpullRequest=' + os.getenv('TRAVIS_PULL_REQUEST'),
31-
'-DserviceName=' + 'TRAVIS')
3227
print(Docker().execute(command))
3328

3429

0 commit comments

Comments
 (0)