Skip to content
This repository was archived by the owner on Jul 2, 2024. It is now read-only.

Commit fd0b47f

Browse files
committed
bean tests
1 parent 7c5468c commit fd0b47f

21 files changed

+208
-50
lines changed

build.gradle

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ dependencies {
2626
testImplementation 'org.spockframework:spock-core:1.0-groovy-2.4'
2727
testImplementation 'junit:junit:4.12'
2828
testImplementation 'com.anotherchrisberry:spock-retry:0.6.3'
29+
testImplementation 'org.meanbean:meanbean:2.0.3'
30+
testImplementation 'nl.jqno.equalsverifier:equalsverifier:2.4.6'
2931
}
3032

3133

Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
package cash.ird.walletd.model.body;
22

33
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
import lombok.NonNull;
46

57
@Data
8+
@NoArgsConstructor
69
public class Balance {
710

8-
private long lockedAmount;
11+
@NonNull
12+
private Long lockedAmount;
913

10-
private long availableBalance;
14+
@NonNull
15+
private Long availableBalance;
1116

1217
}

src/main/java/cash/ird/walletd/model/body/EstimatedFusion.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
@Data
66
public class EstimatedFusion {
77

8-
private long totalOutputCount;
8+
private Long totalOutputCount;
99

10-
private long fusionReadyCount;
10+
private Long fusionReadyCount;
1111

1212
}

src/main/java/cash/ird/walletd/model/body/Status.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
@Data
66
public class Status {
77

8-
private long peerCount;
8+
private Long peerCount;
99

10-
private long blockCount;
10+
private Long blockCount;
1111

1212
private String lastBlockHash;
1313

14-
private long knownBlockCount;
14+
private Long knownBlockCount;
1515

1616
}

src/main/java/cash/ird/walletd/model/body/Transaction.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cash.ird.walletd.model.body;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.sun.org.apache.xpath.internal.operations.Bool;
45
import lombok.Data;
56

67
import java.util.List;
@@ -10,21 +11,21 @@ public class Transaction {
1011

1112
private String transactionHash;
1213

13-
private long blockIndex;
14+
private Long blockIndex;
1415

15-
private long timestamp;
16+
private Long timestamp;
1617

1718
@JsonProperty("isBase")
18-
private boolean isBase;
19+
private Boolean isBase;
1920

20-
private long unlockTime;
21+
private Long unlockTime;
2122

22-
private long amount;
23+
private Long amount;
2324

2425
// TODO: 13.05.18 what is this? It's not in the docs :(
25-
private long state;
26+
private Long state;
2627

27-
private long fee;
28+
private Long fee;
2829

2930
private String extra;
3031

src/main/java/cash/ird/walletd/model/body/Transfer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
public class Transfer {
1212

1313
@NonNull
14-
private long amount;
14+
private Long amount;
1515

16-
private int type;
16+
private Integer type;
1717

1818
@NonNull
1919
private String address;
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
package cash.ird.walletd.model.request;
22

33
import lombok.EqualsAndHashCode;
4+
import lombok.Getter;
5+
import lombok.Setter;
46
import lombok.ToString;
57

6-
@EqualsAndHashCode(callSuper = true)
8+
@EqualsAndHashCode(callSuper = false)
79
@ToString
810
public class BlockHashRange extends BlockRange<String> {
911

12+
@Getter
13+
@Setter
14+
private String start;
15+
16+
@Getter
17+
@Setter
18+
private long count;
19+
20+
@Getter
21+
private final Type type = Type.HASH;
22+
1023
private BlockHashRange(){
1124
super();
12-
this.setType(Type.HASH);
1325
}
1426

1527
public static BlockHashRange of(String start, long count) {
@@ -19,13 +31,6 @@ public static BlockHashRange of(String start, long count) {
1931
return blockHashRange;
2032
}
2133

22-
@Override
23-
public String getStart() {
24-
return this.start;
25-
}
2634

27-
@Override
28-
public void setStart(String start) {
29-
this.start = start;
30-
}
35+
3136
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
package cash.ird.walletd.model.request;
22

3-
import lombok.Data;
4-
import lombok.EqualsAndHashCode;
3+
import lombok.*;
4+
55

6-
@Data
76
@EqualsAndHashCode(callSuper = true)
7+
@ToString
88
public class BlockIndexRange extends BlockRange<Long> {
99

10+
@Getter
11+
@Setter
12+
private Long start;
13+
14+
@Getter
15+
@Setter
16+
private long count;
17+
18+
@Getter
19+
private final Type type = Type.INDEX;
20+
1021
private BlockIndexRange(){
1122
super();
12-
this.setType(Type.INDEX);
1323
}
1424

1525
public static BlockIndexRange of(long start, long count) {
@@ -18,14 +28,4 @@ public static BlockIndexRange of(long start, long count) {
1828
blockIndexRange.setCount(count);
1929
return blockIndexRange;
2030
}
21-
22-
@Override
23-
public Long getStart() {
24-
return this.start;
25-
}
26-
27-
@Override
28-
public void setStart(Long start) {
29-
this.start = start;
30-
}
3131
}

src/main/java/cash/ird/walletd/model/request/BlockRange.java

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
11
package cash.ird.walletd.model.request;
22

3+
import lombok.EqualsAndHashCode;
34
import lombok.Getter;
45
import lombok.Setter;
56

7+
@EqualsAndHashCode
68
public abstract class BlockRange<T> {
79

8-
protected T start;
10+
public abstract T getStart();
911

10-
@Getter
11-
@Setter
12-
protected long count;
12+
public abstract void setStart(T start);
1313

14-
@Getter
15-
@Setter
16-
protected Type type;
14+
public abstract long getCount();
1715

16+
public abstract void setCount(long count);
1817

19-
public abstract T getStart();
20-
21-
public abstract void setStart(T start);
18+
public abstract Type getType();
2219

2320
public enum Type {
2421
HASH("blockHash"),

src/main/java/cash/ird/walletd/model/request/Key.java

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package cash.ird.walletd.model.request;
22

33
import lombok.Data;
4+
import lombok.EqualsAndHashCode;
45

56
@Data
7+
@EqualsAndHashCode
68
public abstract class Key {
79

810
protected String value;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package cash.ird.walletd
2+
3+
import nl.jqno.equalsverifier.EqualsVerifier
4+
import nl.jqno.equalsverifier.Warning
5+
import org.meanbean.test.BeanTester
6+
import spock.lang.Specification
7+
8+
import java.lang.reflect.ParameterizedType
9+
10+
abstract class BeanSpec<T> extends Specification {
11+
12+
Class<T> getBeanClass() {
13+
return (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0]
14+
}
15+
16+
def "Check Bean Spec"() {
17+
expect:
18+
new BeanTester().testBean(getBeanClass())
19+
}
20+
21+
def "equalsContract"() {
22+
given:
23+
def equalsVerifier = EqualsVerifier
24+
.forClass(getBeanClass())
25+
.suppress(Warning.STRICT_INHERITANCE)
26+
.suppress(Warning.NONFINAL_FIELDS)
27+
28+
customizeEqualsVerifier(equalsVerifier)
29+
30+
expect:
31+
equalsVerifier.verify()
32+
}
33+
34+
@SuppressWarnings("GrMethodMayBeStatic")
35+
protected <T> EqualsVerifier<T> customizeEqualsVerifier(EqualsVerifier<T> equalsVerifier){
36+
return equalsVerifier
37+
}
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package cash.ird.walletd.model.body
2+
3+
import cash.ird.walletd.BeanSpec
4+
5+
class BalanceTest extends BeanSpec<Balance> {
6+
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package cash.ird.walletd.model.body
2+
3+
import cash.ird.walletd.BeanSpec
4+
5+
class EstimatedFusionTest extends BeanSpec<EstimatedFusion> {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package cash.ird.walletd.model.body
2+
3+
import cash.ird.walletd.BeanSpec
4+
5+
class SpendKeyPairTest extends BeanSpec<SpendKeyPair> {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package cash.ird.walletd.model.body
2+
3+
import cash.ird.walletd.BeanSpec
4+
5+
class StatusTest extends BeanSpec<Status> {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package cash.ird.walletd.model.body
2+
3+
import cash.ird.walletd.BeanSpec
4+
5+
class TransactionHashBagTest extends BeanSpec<TransactionHashBag> {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package cash.ird.walletd.model.body
2+
3+
import cash.ird.walletd.BeanSpec
4+
5+
class TransactionItemBagTest extends BeanSpec<TransactionItemBag> {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package cash.ird.walletd.model.body
2+
3+
import cash.ird.walletd.BeanSpec
4+
5+
class TransactionTest extends BeanSpec<Transaction> {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cash.ird.walletd.model.body
2+
3+
import cash.ird.walletd.BeanSpec
4+
5+
class TransferTest extends BeanSpec<Transfer> {
6+
7+
def "reqArgsConstructor"() {
8+
def address = "ir3abc..."
9+
when:
10+
def sut = Transfer.of(1000, address)
11+
then:
12+
sut.getAmount() == 1000
13+
sut.getAddress() == address
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package cash.ird.walletd.model.request
2+
3+
import cash.ird.walletd.BeanSpec
4+
import nl.jqno.equalsverifier.EqualsVerifier
5+
6+
class BlockHashRangeTest extends BeanSpec<BlockHashRange> {
7+
8+
def "static constructor"() {
9+
when:
10+
def a = BlockHashRange.of("a", 1)
11+
then:
12+
a.getStart() == "a"
13+
a.getCount() == 1
14+
a.getType() == BlockRange.Type.HASH
15+
}
16+
17+
@Override
18+
protected <T> EqualsVerifier<T> customizeEqualsVerifier(EqualsVerifier<T> equalsVerifier) {
19+
equalsVerifier
20+
.withRedefinedSuperclass()
21+
22+
return super.customizeEqualsVerifier(equalsVerifier)
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package cash.ird.walletd.model.request
2+
3+
import cash.ird.walletd.BeanSpec
4+
import nl.jqno.equalsverifier.EqualsVerifier
5+
6+
class BlockIndexRangeTest extends BeanSpec<BlockIndexRange> {
7+
8+
def "static constructor"() {
9+
when:
10+
def a = BlockIndexRange.of(0, 1)
11+
then:
12+
a.getStart() == 0
13+
a.getCount() == 1
14+
a.getType() == BlockRange.Type.INDEX
15+
}
16+
17+
@Override
18+
protected <T> EqualsVerifier<T> customizeEqualsVerifier(EqualsVerifier<T> equalsVerifier) {
19+
equalsVerifier
20+
.withRedefinedSuperclass()
21+
22+
return super.customizeEqualsVerifier(equalsVerifier)
23+
}
24+
25+
}

0 commit comments

Comments
 (0)