Skip to content

Commit 8c2352a

Browse files
author
Luis Sanchez
committed
[FAB-6494] Add unit tests for ChaincodeStubImpl
Change-Id: Iff57242e666a17ea6faefc50951bfac423b85f7a Signed-off-by: Luis Sanchez <sanchezl@us.ibm.com>
1 parent b58bcc2 commit 8c2352a

File tree

4 files changed

+337
-25
lines changed

4 files changed

+337
-25
lines changed

shim/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ dependencies {
6060
// runtime 'io.netty:netty-tcnative-boringssl-static:1.1.33.Fork21:' + tcnative_classifier
6161
testCompile 'junit:junit:4.12'
6262
testCompile 'org.hamcrest:hamcrest-library:1.3'
63+
testCompile "org.mockito:mockito-core:2.+"
6364
}
6465

6566
archivesBaseName = 'shim-client'

shim/src/main/java/org/hyperledger/fabric/shim/impl/KeyModificationImpl.java

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,54 +36,59 @@ public class KeyModificationImpl implements KeyModification {
3636
this.deleted = km.getIsDelete();
3737
}
3838

39-
/*
40-
* (non-Javadoc)
41-
*
42-
* @see org.hyperledger.fabric.shim.impl.KeyModification#getTxId()
43-
*/
4439
@Override
4540
public String getTxId() {
4641
return txId;
4742
}
4843

49-
/*
50-
* (non-Javadoc)
51-
*
52-
* @see org.hyperledger.fabric.shim.impl.KeyModification#getValue()
53-
*/
5444
@Override
5545
public byte[] getValue() {
5646
return value.toByteArray();
5747
}
5848

59-
/*
60-
* (non-Javadoc)
61-
*
62-
* @see org.hyperledger.fabric.shim.impl.KeyModification#getStringValue()
63-
*/
6449
@Override
6550
public String getStringValue() {
6651
return value.toStringUtf8();
6752
}
6853

69-
/*
70-
* (non-Javadoc)
71-
*
72-
* @see org.hyperledger.fabric.shim.impl.KeyModification#getTimestamp()
73-
*/
7454
@Override
7555
public java.time.Instant getTimestamp() {
7656
return timestamp;
7757
}
7858

79-
/*
80-
* (non-Javadoc)
81-
*
82-
* @see org.hyperledger.fabric.shim.impl.KeyModification#isDeleted()
83-
*/
8459
@Override
8560
public boolean isDeleted() {
8661
return deleted;
8762
}
8863

64+
@Override
65+
public int hashCode() {
66+
final int prime = 31;
67+
int result = 1;
68+
result = prime * result + (deleted ? 1231 : 1237);
69+
result = prime * result + ((timestamp == null) ? 0 : timestamp.hashCode());
70+
result = prime * result + ((txId == null) ? 0 : txId.hashCode());
71+
result = prime * result + ((value == null) ? 0 : value.hashCode());
72+
return result;
73+
}
74+
75+
@Override
76+
public boolean equals(Object obj) {
77+
if (this == obj) return true;
78+
if (obj == null) return false;
79+
if (getClass() != obj.getClass()) return false;
80+
KeyModificationImpl other = (KeyModificationImpl) obj;
81+
if (deleted != other.deleted) return false;
82+
if (timestamp == null) {
83+
if (other.timestamp != null) return false;
84+
} else if (!timestamp.equals(other.timestamp)) return false;
85+
if (txId == null) {
86+
if (other.txId != null) return false;
87+
} else if (!txId.equals(other.txId)) return false;
88+
if (value == null) {
89+
if (other.value != null) return false;
90+
} else if (!value.equals(other.value)) return false;
91+
return true;
92+
}
93+
8994
}

shim/src/main/java/org/hyperledger/fabric/shim/impl/KeyValueImpl.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,28 @@ public String getStringValue() {
4545
return value.toStringUtf8();
4646
}
4747

48+
@Override
49+
public int hashCode() {
50+
final int prime = 31;
51+
int result = 1;
52+
result = prime * result + ((key == null) ? 0 : key.hashCode());
53+
result = prime * result + ((value == null) ? 0 : value.hashCode());
54+
return result;
55+
}
56+
57+
@Override
58+
public boolean equals(Object obj) {
59+
if (this == obj) return true;
60+
if (obj == null) return false;
61+
if (getClass() != obj.getClass()) return false;
62+
KeyValueImpl other = (KeyValueImpl) obj;
63+
if (key == null) {
64+
if (other.key != null) return false;
65+
} else if (!key.equals(other.key)) return false;
66+
if (value == null) {
67+
if (other.value != null) return false;
68+
} else if (!value.equals(other.value)) return false;
69+
return true;
70+
}
71+
4872
}

0 commit comments

Comments
 (0)