Skip to content

Commit 63facc5

Browse files
AlexandrouRiikirilov
authored andcommitted
Updated Junit and mockito refactored the tests. (LFDT-web3j#1084)
* Updated Junit and mockito refactored the tests. * removed hamcrest as dependency replaced assertThat with assertEquals from JUnit * fix conflict * added messages back to assertTrue and assertFalse * added benchmark option annotation to FastRawTransactionManagerIT * refactored the code such that in the assertThrows only the line that causes the exception is declared. * Reversed the argument order in assertEquals that was assertThat previously * . * spotless
1 parent aaebd8e commit 63facc5

File tree

112 files changed

+1891
-1989
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+1891
-1989
lines changed

abi/src/test/java/org/web3j/abi/DefaultFunctionEncoderTest.java

+48-54
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import java.util.Arrays;
1717
import java.util.Collections;
1818

19-
import org.junit.Test;
19+
import org.junit.jupiter.api.Test;
2020

2121
import org.web3j.abi.datatypes.Bool;
2222
import org.web3j.abi.datatypes.DynamicArray;
@@ -27,56 +27,53 @@
2727
import org.web3j.abi.datatypes.generated.Bytes10;
2828
import org.web3j.abi.datatypes.generated.Uint32;
2929

30-
import static org.hamcrest.CoreMatchers.is;
31-
import static org.junit.Assert.assertThat;
30+
import static org.junit.jupiter.api.Assertions.assertEquals;
3231

3332
public class DefaultFunctionEncoderTest {
3433

3534
@Test
3635
public void testBuildMethodId() {
37-
assertThat(DefaultFunctionEncoder.buildMethodId("baz(uint32,bool)"), is("0xcdcd77c0"));
36+
assertEquals("0xcdcd77c0", DefaultFunctionEncoder.buildMethodId("baz(uint32,bool)"));
3837
}
3938

4039
@Test
4140
public void testBuildMessageSignature() {
42-
assertThat(
41+
assertEquals(
42+
"baz(uint32,bool)",
4343
DefaultFunctionEncoder.buildMethodSignature(
44-
"baz", Arrays.asList(new Uint32(BigInteger.valueOf(69)), new Bool(true))),
45-
is("baz(uint32,bool)"));
44+
"baz", Arrays.asList(new Uint32(BigInteger.valueOf(69)), new Bool(true))));
4645
}
4746

4847
@Test
4948
public void testBuildEmptyMethodSignature() {
50-
assertThat(
51-
DefaultFunctionEncoder.buildMethodSignature("empty", Collections.emptyList()),
52-
is("empty()"));
49+
assertEquals(
50+
"empty()",
51+
DefaultFunctionEncoder.buildMethodSignature("empty", Collections.emptyList()));
5352
}
5453

5554
@Test
5655
public void testEncodeConstructorEmpty() {
57-
assertThat(FunctionEncoder.encodeConstructor(Collections.emptyList()), is(""));
56+
assertEquals("", FunctionEncoder.encodeConstructor(Collections.emptyList()));
5857
}
5958

6059
@Test
6160
public void testEncodeConstructorString() {
62-
assertThat(
61+
assertEquals(
62+
"0000000000000000000000000000000000000000000000000000000000000020"
63+
+ "000000000000000000000000000000000000000000000000000000000000000a"
64+
+ "4772656574696e67732100000000000000000000000000000000000000000000",
6365
FunctionEncoder.encodeConstructor(
64-
Collections.singletonList(new Utf8String("Greetings!"))),
65-
is(
66-
"0000000000000000000000000000000000000000000000000000000000000020"
67-
+ "000000000000000000000000000000000000000000000000000000000000000a"
68-
+ "4772656574696e67732100000000000000000000000000000000000000000000"));
66+
Collections.singletonList(new Utf8String("Greetings!"))));
6967
}
7068

7169
@Test
7270
public void testEncodeConstructorUint() {
73-
assertThat(
71+
assertEquals(
72+
"0000000000000000000000000000000000000000000000000000000000000001"
73+
+ "0000000000000000000000000000000000000000000000000000000000000020",
7474
FunctionEncoder.encodeConstructor(
7575
Arrays.asList(
76-
new Uint(BigInteger.ONE), new Uint(BigInteger.valueOf(0x20)))),
77-
is(
78-
"0000000000000000000000000000000000000000000000000000000000000001"
79-
+ "0000000000000000000000000000000000000000000000000000000000000020"));
76+
new Uint(BigInteger.ONE), new Uint(BigInteger.valueOf(0x20)))));
8077
}
8178

8279
@Test
@@ -87,12 +84,11 @@ public void testFunctionSimpleEncode() {
8784
Arrays.asList(new Uint32(BigInteger.valueOf(69)), new Bool(true)),
8885
Collections.emptyList());
8986

90-
assertThat(
91-
FunctionEncoder.encode(function),
92-
is(
93-
"0xcdcd77c0"
94-
+ "0000000000000000000000000000000000000000000000000000000000000045"
95-
+ "0000000000000000000000000000000000000000000000000000000000000001"));
87+
assertEquals(
88+
"0xcdcd77c0"
89+
+ "0000000000000000000000000000000000000000000000000000000000000045"
90+
+ "0000000000000000000000000000000000000000000000000000000000000001",
91+
FunctionEncoder.encode(function));
9692
}
9793

9894
@Test
@@ -109,19 +105,18 @@ public void testFunctionMDynamicArrayEncode1() {
109105
new Uint(BigInteger.valueOf(3)))),
110106
Collections.emptyList());
111107

112-
assertThat(
113-
FunctionEncoder.encode(function),
114-
is(
115-
"0xa5643bf2"
116-
+ "0000000000000000000000000000000000000000000000000000000000000060"
117-
+ "0000000000000000000000000000000000000000000000000000000000000001"
118-
+ "00000000000000000000000000000000000000000000000000000000000000a0"
119-
+ "0000000000000000000000000000000000000000000000000000000000000004"
120-
+ "6461766500000000000000000000000000000000000000000000000000000000"
121-
+ "0000000000000000000000000000000000000000000000000000000000000003"
122-
+ "0000000000000000000000000000000000000000000000000000000000000001"
123-
+ "0000000000000000000000000000000000000000000000000000000000000002"
124-
+ "0000000000000000000000000000000000000000000000000000000000000003"));
108+
assertEquals(
109+
"0xa5643bf2"
110+
+ "0000000000000000000000000000000000000000000000000000000000000060"
111+
+ "0000000000000000000000000000000000000000000000000000000000000001"
112+
+ "00000000000000000000000000000000000000000000000000000000000000a0"
113+
+ "0000000000000000000000000000000000000000000000000000000000000004"
114+
+ "6461766500000000000000000000000000000000000000000000000000000000"
115+
+ "0000000000000000000000000000000000000000000000000000000000000003"
116+
+ "0000000000000000000000000000000000000000000000000000000000000001"
117+
+ "0000000000000000000000000000000000000000000000000000000000000002"
118+
+ "0000000000000000000000000000000000000000000000000000000000000003",
119+
FunctionEncoder.encode(function));
125120
}
126121

127122
@Test
@@ -138,18 +133,17 @@ public void testFunctionMDynamicArrayEncode2() {
138133
new DynamicBytes("Hello, world!".getBytes())),
139134
Collections.emptyList());
140135

141-
assertThat(
142-
FunctionEncoder.encode(function),
143-
is(
144-
"0x8be65246"
145-
+ "0000000000000000000000000000000000000000000000000000000000000123"
146-
+ "0000000000000000000000000000000000000000000000000000000000000080"
147-
+ "3132333435363738393000000000000000000000000000000000000000000000"
148-
+ "00000000000000000000000000000000000000000000000000000000000000e0"
149-
+ "0000000000000000000000000000000000000000000000000000000000000002"
150-
+ "0000000000000000000000000000000000000000000000000000000000000456"
151-
+ "0000000000000000000000000000000000000000000000000000000000000789"
152-
+ "000000000000000000000000000000000000000000000000000000000000000d"
153-
+ "48656c6c6f2c20776f726c642100000000000000000000000000000000000000"));
136+
assertEquals(
137+
"0x8be65246"
138+
+ "0000000000000000000000000000000000000000000000000000000000000123"
139+
+ "0000000000000000000000000000000000000000000000000000000000000080"
140+
+ "3132333435363738393000000000000000000000000000000000000000000000"
141+
+ "00000000000000000000000000000000000000000000000000000000000000e0"
142+
+ "0000000000000000000000000000000000000000000000000000000000000002"
143+
+ "0000000000000000000000000000000000000000000000000000000000000456"
144+
+ "0000000000000000000000000000000000000000000000000000000000000789"
145+
+ "000000000000000000000000000000000000000000000000000000000000000d"
146+
+ "48656c6c6f2c20776f726c642100000000000000000000000000000000000000",
147+
FunctionEncoder.encode(function));
154148
}
155149
}

abi/src/test/java/org/web3j/abi/EventEncoderTest.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@
1212
*/
1313
package org.web3j.abi;
1414

15-
import org.junit.Test;
15+
import org.junit.jupiter.api.Test;
1616

17-
import static org.hamcrest.CoreMatchers.is;
18-
import static org.hamcrest.MatcherAssert.assertThat;
17+
import static org.junit.jupiter.api.Assertions.assertEquals;
1918

2019
public class EventEncoderTest {
2120

2221
@Test
2322
public void testBuildEventSignature() {
24-
assertThat(
23+
assertEquals(
2524
EventEncoder.buildEventSignature("Deposit(address,hash256,uint256)"),
26-
is("0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20"));
25+
("0x50cb9fe53daa9737b786ab3646f04d0150dc50ef4e75f59509d83667ad5adb20"));
2726

28-
assertThat(
27+
assertEquals(
2928
EventEncoder.buildEventSignature("Notify(uint256,uint256)"),
30-
is("0x71e71a8458267085d5ab16980fd5f114d2d37f232479c245d523ce8d23ca40ed"));
29+
("0x71e71a8458267085d5ab16980fd5f114d2d37f232479c245d523ce8d23ca40ed"));
3130
}
3231
}

abi/src/test/java/org/web3j/abi/FunctionReturnDecoderTest.java

+29-35
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.Collections;
1919
import java.util.List;
2020

21-
import org.junit.Test;
21+
import org.junit.jupiter.api.Test;
2222

2323
import org.web3j.abi.datatypes.DynamicArray;
2424
import org.web3j.abi.datatypes.DynamicBytes;
@@ -34,9 +34,7 @@
3434
import org.web3j.crypto.Hash;
3535
import org.web3j.utils.Numeric;
3636

37-
import static org.hamcrest.CoreMatchers.is;
38-
import static org.hamcrest.core.IsEqual.equalTo;
39-
import static org.junit.Assert.assertThat;
37+
import static org.junit.jupiter.api.Assertions.assertEquals;
4038

4139
public class FunctionReturnDecoderTest {
4240

@@ -48,11 +46,11 @@ public void testSimpleFunctionDecode() {
4846
Collections.<Type>emptyList(),
4947
Collections.singletonList(new TypeReference<Uint>() {}));
5048

51-
assertThat(
49+
assertEquals(
5250
FunctionReturnDecoder.decode(
5351
"0x0000000000000000000000000000000000000000000000000000000000000037",
5452
function.getOutputParameters()),
55-
equalTo(Collections.singletonList(new Uint(BigInteger.valueOf(55)))));
53+
(Collections.singletonList(new Uint(BigInteger.valueOf(55)))));
5654
}
5755

5856
@Test
@@ -70,7 +68,7 @@ public void testSimpleFunctionStringResultDecode() {
7068
+ "6f6e65206d6f72652074696d6500000000000000000000000000000000000000",
7169
function.getOutputParameters());
7270

73-
assertThat(utf8Strings.get(0).getValue(), is("one more time"));
71+
assertEquals(utf8Strings.get(0).getValue(), ("one more time"));
7472
}
7573

7674
@Test
@@ -87,7 +85,7 @@ public void testFunctionEmptyStringResultDecode() {
8785
+ "0000000000000000000000000000000000000000000000000000000000000000",
8886
function.getOutputParameters());
8987

90-
assertThat(utf8Strings.get(0).getValue(), is(""));
88+
assertEquals(utf8Strings.get(0).getValue(), (""));
9189
}
9290

9391
@Test
@@ -98,15 +96,12 @@ public void testMultipleResultFunctionDecode() {
9896
Collections.<Type>emptyList(),
9997
Arrays.asList(new TypeReference<Uint>() {}, new TypeReference<Uint>() {}));
10098

101-
assertThat(
99+
assertEquals(
102100
FunctionReturnDecoder.decode(
103101
"0x0000000000000000000000000000000000000000000000000000000000000037"
104102
+ "0000000000000000000000000000000000000000000000000000000000000007",
105103
function.getOutputParameters()),
106-
equalTo(
107-
Arrays.asList(
108-
new Uint(BigInteger.valueOf(55)),
109-
new Uint(BigInteger.valueOf(7)))));
104+
(Arrays.asList(new Uint(BigInteger.valueOf(55)), new Uint(BigInteger.valueOf(7)))));
110105
}
111106

112107
@Test
@@ -121,7 +116,7 @@ public void testDecodeMultipleStringValues() {
121116
new TypeReference<Utf8String>() {},
122117
new TypeReference<Utf8String>() {}));
123118

124-
assertThat(
119+
assertEquals(
125120
FunctionReturnDecoder.decode(
126121
"0x0000000000000000000000000000000000000000000000000000000000000080"
127122
+ "00000000000000000000000000000000000000000000000000000000000000c0"
@@ -136,10 +131,9 @@ public void testDecodeMultipleStringValues() {
136131
+ "0000000000000000000000000000000000000000000000000000000000000004"
137132
+ "6d6e6f3200000000000000000000000000000000000000000000000000000000",
138133
function.getOutputParameters()),
139-
equalTo(
140-
Arrays.asList(
141-
new Utf8String("def1"), new Utf8String("ghi1"),
142-
new Utf8String("jkl1"), new Utf8String("mno2"))));
134+
(Arrays.asList(
135+
new Utf8String("def1"), new Utf8String("ghi1"),
136+
new Utf8String("jkl1"), new Utf8String("mno2"))));
143137
}
144138

145139
@Test
@@ -163,16 +157,16 @@ public void testDecodeStaticArrayValue() {
163157
new Uint256(BigInteger.valueOf(55)), new Uint256(BigInteger.ONE));
164158

165159
List<Type> expected = Arrays.asList(uint256StaticArray2, new Uint256(BigInteger.TEN));
166-
assertThat(decoded, equalTo(expected));
160+
assertEquals(decoded, (expected));
167161
}
168162

169163
@Test
170164
public void testVoidResultFunctionDecode() {
171165
Function function = new Function("test", Collections.emptyList(), Collections.emptyList());
172166

173-
assertThat(
167+
assertEquals(
174168
FunctionReturnDecoder.decode("0x", function.getOutputParameters()),
175-
is(Collections.emptyList()));
169+
(Collections.emptyList()));
176170
}
177171

178172
@Test
@@ -183,19 +177,19 @@ public void testEmptyResultFunctionDecode() {
183177
Collections.emptyList(),
184178
Collections.singletonList(new TypeReference<Uint>() {}));
185179

186-
assertThat(
180+
assertEquals(
187181
FunctionReturnDecoder.decode("0x", function.getOutputParameters()),
188-
is(Collections.emptyList()));
182+
(Collections.emptyList()));
189183
}
190184

191185
@Test
192186
public void testDecodeIndexedUint256Value() {
193187
Uint256 value = new Uint256(BigInteger.TEN);
194188
String encoded = TypeEncoder.encodeNumeric(value);
195189

196-
assertThat(
190+
assertEquals(
197191
FunctionReturnDecoder.decodeIndexedValue(encoded, new TypeReference<Uint256>() {}),
198-
equalTo(value));
192+
(value));
199193
}
200194

201195
@Test
@@ -204,29 +198,29 @@ public void testDecodeIndexedStringValue() {
204198
String encoded = TypeEncoder.encodeString(string);
205199
String hash = Hash.sha3(encoded);
206200

207-
assertThat(
201+
assertEquals(
208202
FunctionReturnDecoder.decodeIndexedValue(hash, new TypeReference<Utf8String>() {}),
209-
equalTo(new Bytes32(Numeric.hexStringToByteArray(hash))));
203+
(new Bytes32(Numeric.hexStringToByteArray(hash))));
210204
}
211205

212206
@Test
213207
public void testDecodeIndexedBytes32Value() {
214208
String rawInput = "0x1234567890123456789012345678901234567890123456789012345678901234";
215209
byte[] rawInputBytes = Numeric.hexStringToByteArray(rawInput);
216210

217-
assertThat(
211+
assertEquals(
218212
FunctionReturnDecoder.decodeIndexedValue(rawInput, new TypeReference<Bytes32>() {}),
219-
equalTo(new Bytes32(rawInputBytes)));
213+
(new Bytes32(rawInputBytes)));
220214
}
221215

222216
@Test
223217
public void testDecodeIndexedBytes16Value() {
224218
String rawInput = "0x1234567890123456789012345678901200000000000000000000000000000000";
225219
byte[] rawInputBytes = Numeric.hexStringToByteArray(rawInput.substring(0, 34));
226220

227-
assertThat(
221+
assertEquals(
228222
FunctionReturnDecoder.decodeIndexedValue(rawInput, new TypeReference<Bytes16>() {}),
229-
equalTo(new Bytes16(rawInputBytes)));
223+
(new Bytes16(rawInputBytes)));
230224
}
231225

232226
@Test
@@ -235,10 +229,10 @@ public void testDecodeIndexedDynamicBytesValue() {
235229
String encoded = TypeEncoder.encodeDynamicBytes(bytes);
236230
String hash = Hash.sha3(encoded);
237231

238-
assertThat(
232+
assertEquals(
239233
FunctionReturnDecoder.decodeIndexedValue(
240234
hash, new TypeReference<DynamicBytes>() {}),
241-
equalTo(new Bytes32(Numeric.hexStringToByteArray(hash))));
235+
(new Bytes32(Numeric.hexStringToByteArray(hash))));
242236
}
243237

244238
@Test
@@ -249,9 +243,9 @@ public void testDecodeIndexedDynamicArrayValue() {
249243
String encoded = TypeEncoder.encodeDynamicArray(array);
250244
String hash = Hash.sha3(encoded);
251245

252-
assertThat(
246+
assertEquals(
253247
FunctionReturnDecoder.decodeIndexedValue(
254248
hash, new TypeReference<DynamicArray>() {}),
255-
equalTo(new Bytes32(Numeric.hexStringToByteArray(hash))));
249+
(new Bytes32(Numeric.hexStringToByteArray(hash))));
256250
}
257251
}

0 commit comments

Comments
 (0)