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

Commit 70ae23e

Browse files
committed
Add default test so tests and coveralls don't fail.
1 parent 5a0ebd8 commit 70ae23e

File tree

4 files changed

+117
-6
lines changed

4 files changed

+117
-6
lines changed

src/main/java/works/weave/socks/shipping/entities/Shipment.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,48 @@
11
package works.weave.socks.shipping.entities;
22

3+
import java.util.UUID;
4+
35
public class Shipment {
46
private String id;
57
private String name;
68

9+
public Shipment() {
10+
this("");
11+
}
12+
13+
public Shipment(String name) {
14+
this(UUID.randomUUID().toString(), name);
15+
}
16+
17+
public Shipment(String id, String name) {
18+
this.id = id;
19+
this.name = name;
20+
}
21+
22+
@Override
23+
public String toString() {
24+
return "Shipment{" +
25+
"id='" + id + '\'' +
26+
", name='" + name + '\'' +
27+
'}';
28+
}
29+
30+
@Override
31+
public boolean equals(Object o) {
32+
if (this == o) return true;
33+
if (o == null || getClass() != o.getClass()) return false;
34+
35+
Shipment shipment = (Shipment) o;
36+
37+
return getId() != null ? getId().equals(shipment.getId()) : shipment.getId() == null;
38+
39+
}
40+
41+
@Override
42+
public int hashCode() {
43+
return getId() != null ? getId().hashCode() : 0;
44+
}
45+
746
public String getId() {
847
return id;
948
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package works.weave.socks.shipping.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+
import static org.hamcrest.CoreMatchers.*;
18+
import static org.junit.Assert.assertThat;
19+
20+
public class UnitPojo {
21+
// Configured for expectation, so we know when a class gets added or removed.
22+
private static final int EXPECTED_CLASS_COUNT = 1;
23+
24+
// The package to test
25+
private static final String POJO_PACKAGE = "works.weave.socks.shipping.entities";
26+
27+
private final PojoClassFilter filter = new FilterClassName("^((?!Unit).)*$");
28+
29+
@Test
30+
public void ensureExpectedPojoCount() {
31+
List<PojoClass> pojoClasses = PojoClassFactory.getPojoClasses(POJO_PACKAGE, filter);
32+
Affirm.affirmEquals("Classes added / removed?", EXPECTED_CLASS_COUNT, pojoClasses.size());
33+
}
34+
35+
@Test
36+
public void testPojoStructureAndBehavior() {
37+
Validator validator = ValidatorBuilder.create()
38+
// Add Rules to validate structure for POJO_PACKAGE
39+
// See com.openpojo.validation.rule.impl for more ...
40+
.with(new GetterMustExistRule())
41+
.with(new SetterMustExistRule())
42+
// Add Testers to validate behaviour for POJO_PACKAGE
43+
// See com.openpojo.validation.test.impl for more ...
44+
.with(new SetterTester())
45+
.with(new GetterTester())
46+
// Static fields must be final
47+
.with(new NoStaticExceptFinalRule())
48+
// Don't shadow parent's field names.
49+
.with(new NoFieldShadowingRule())
50+
// What about public fields, use one of the following rules
51+
// allow them only if they are static and final.
52+
.with(new NoPublicFieldsExceptStaticFinalRule())
53+
.build();
54+
55+
validator.validate(POJO_PACKAGE, filter);
56+
}
57+
58+
@Test
59+
public void testEquals() throws Exception {
60+
assertThat(new Shipment("id", "name"), is(equalTo(new Shipment("id", "name"))));
61+
assertThat(new Shipment("id", "name"), is(equalTo(new Shipment("id", "another"))));
62+
assertThat(new Shipment("id", "name"), is(not(equalTo(new Shipment("another", "name")))));
63+
}
64+
65+
@Test
66+
public void testHashcode() throws Exception {
67+
assertThat(new Shipment("id", "name").hashCode(), is(equalTo(new Shipment("id", "name").hashCode())));
68+
assertThat(new Shipment("id", "name").hashCode(), is(equalTo(new Shipment("id", "another").hashCode())));
69+
assertThat(new Shipment("id", "name").hashCode(), is(not(equalTo(new Shipment("aa", "name").hashCode()))));
70+
}
71+
72+
@Test
73+
public void testString() throws Exception {
74+
assertThat(new Shipment("id").toString(), is(notNullValue()));
75+
76+
}
77+
}

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

test/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
set -ev
3+
set -e
44

55
SCRIPT_DIR=`dirname "$0"`
66
SCRIPT_NAME=`basename "$0"`

0 commit comments

Comments
 (0)