@@ -63,15 +63,15 @@ private final class MockCarResultsIterator implements QueryResultsIterator<KeyVa
63
63
64
64
carList = new ArrayList <KeyValue >();
65
65
66
- carList .add (new MockKeyValue ("CAR000 " ,
66
+ carList .add (new MockKeyValue ("CAR0 " ,
67
67
"{\" color\" :\" blue\" ,\" make\" :\" Toyota\" ,\" model\" :\" Prius\" ,\" owner\" :\" Tomoko\" }" ));
68
- carList .add (new MockKeyValue ("CAR001 " ,
68
+ carList .add (new MockKeyValue ("CAR1 " ,
69
69
"{\" color\" :\" red\" ,\" make\" :\" Ford\" ,\" model\" :\" Mustang\" ,\" owner\" :\" Brad\" }" ));
70
- carList .add (new MockKeyValue ("CAR002 " ,
70
+ carList .add (new MockKeyValue ("CAR2 " ,
71
71
"{\" color\" :\" green\" ,\" make\" :\" Hyundai\" ,\" model\" :\" Tucson\" ,\" owner\" :\" Jin Soo\" }" ));
72
- carList .add (new MockKeyValue ("CAR007 " ,
72
+ carList .add (new MockKeyValue ("CAR7 " ,
73
73
"{\" color\" :\" violet\" ,\" make\" :\" Fiat\" ,\" model\" :\" Punto\" ,\" owner\" :\" Pari\" }" ));
74
- carList .add (new MockKeyValue ("CAR009 " ,
74
+ carList .add (new MockKeyValue ("CAR9 " ,
75
75
"{\" color\" :\" brown\" ,\" make\" :\" Holden\" ,\" model\" :\" Barina\" ,\" owner\" :\" Shotaro\" }" ));
76
76
}
77
77
@@ -112,10 +112,10 @@ public void whenCarExists() {
112
112
Context ctx = mock (Context .class );
113
113
ChaincodeStub stub = mock (ChaincodeStub .class );
114
114
when (ctx .getStub ()).thenReturn (stub );
115
- when (stub .getStringState ("CAR000 " ))
115
+ when (stub .getStringState ("CAR0 " ))
116
116
.thenReturn ("{\" color\" :\" blue\" ,\" make\" :\" Toyota\" ,\" model\" :\" Prius\" ,\" owner\" :\" Tomoko\" }" );
117
117
118
- Car car = contract .queryCar (ctx , "CAR000 " );
118
+ Car car = contract .queryCar (ctx , "CAR0 " );
119
119
120
120
assertThat (car ).isEqualTo (new Car ("Toyota" , "Prius" , "blue" , "Tomoko" ));
121
121
}
@@ -126,14 +126,14 @@ public void whenCarDoesNotExist() {
126
126
Context ctx = mock (Context .class );
127
127
ChaincodeStub stub = mock (ChaincodeStub .class );
128
128
when (ctx .getStub ()).thenReturn (stub );
129
- when (stub .getStringState ("CAR000 " )).thenReturn ("" );
129
+ when (stub .getStringState ("CAR0 " )).thenReturn ("" );
130
130
131
131
Throwable thrown = catchThrowable (() -> {
132
- contract .queryCar (ctx , "CAR000 " );
132
+ contract .queryCar (ctx , "CAR0 " );
133
133
});
134
134
135
135
assertThat (thrown ).isInstanceOf (ChaincodeException .class ).hasNoCause ()
136
- .hasMessage ("Car CAR000 does not exist" );
136
+ .hasMessage ("Car CAR0 does not exist" );
137
137
assertThat (((ChaincodeException ) thrown ).getPayload ()).isEqualTo ("CAR_NOT_FOUND" .getBytes ());
138
138
}
139
139
}
@@ -148,25 +148,25 @@ void invokeInitLedgerTransaction() {
148
148
contract .initLedger (ctx );
149
149
150
150
InOrder inOrder = inOrder (stub );
151
- inOrder .verify (stub ).putStringState ("CAR000 " ,
151
+ inOrder .verify (stub ).putStringState ("CAR0 " ,
152
152
"{\" color\" :\" blue\" ,\" make\" :\" Toyota\" ,\" model\" :\" Prius\" ,\" owner\" :\" Tomoko\" }" );
153
- inOrder .verify (stub ).putStringState ("CAR001 " ,
153
+ inOrder .verify (stub ).putStringState ("CAR1 " ,
154
154
"{\" color\" :\" red\" ,\" make\" :\" Ford\" ,\" model\" :\" Mustang\" ,\" owner\" :\" Brad\" }" );
155
- inOrder .verify (stub ).putStringState ("CAR002 " ,
155
+ inOrder .verify (stub ).putStringState ("CAR2 " ,
156
156
"{\" color\" :\" green\" ,\" make\" :\" Hyundai\" ,\" model\" :\" Tucson\" ,\" owner\" :\" Jin Soo\" }" );
157
- inOrder .verify (stub ).putStringState ("CAR003 " ,
157
+ inOrder .verify (stub ).putStringState ("CAR3 " ,
158
158
"{\" color\" :\" yellow\" ,\" make\" :\" Volkswagen\" ,\" model\" :\" Passat\" ,\" owner\" :\" Max\" }" );
159
- inOrder .verify (stub ).putStringState ("CAR004 " ,
159
+ inOrder .verify (stub ).putStringState ("CAR4 " ,
160
160
"{\" color\" :\" black\" ,\" make\" :\" Tesla\" ,\" model\" :\" S\" ,\" owner\" :\" Adrian\" }" );
161
- inOrder .verify (stub ).putStringState ("CAR005 " ,
161
+ inOrder .verify (stub ).putStringState ("CAR5 " ,
162
162
"{\" color\" :\" purple\" ,\" make\" :\" Peugeot\" ,\" model\" :\" 205\" ,\" owner\" :\" Michel\" }" );
163
- inOrder .verify (stub ).putStringState ("CAR006 " ,
163
+ inOrder .verify (stub ).putStringState ("CAR6 " ,
164
164
"{\" color\" :\" white\" ,\" make\" :\" Chery\" ,\" model\" :\" S22L\" ,\" owner\" :\" Aarav\" }" );
165
- inOrder .verify (stub ).putStringState ("CAR007 " ,
165
+ inOrder .verify (stub ).putStringState ("CAR7 " ,
166
166
"{\" color\" :\" violet\" ,\" make\" :\" Fiat\" ,\" model\" :\" Punto\" ,\" owner\" :\" Pari\" }" );
167
- inOrder .verify (stub ).putStringState ("CAR008 " ,
167
+ inOrder .verify (stub ).putStringState ("CAR8 " ,
168
168
"{\" color\" :\" indigo\" ,\" make\" :\" Tata\" ,\" model\" :\" nano\" ,\" owner\" :\" Valeria\" }" );
169
- inOrder .verify (stub ).putStringState ("CAR009 " ,
169
+ inOrder .verify (stub ).putStringState ("CAR9 " ,
170
170
"{\" color\" :\" brown\" ,\" make\" :\" Holden\" ,\" model\" :\" Barina\" ,\" owner\" :\" Shotaro\" }" );
171
171
}
172
172
@@ -179,15 +179,15 @@ public void whenCarExists() {
179
179
Context ctx = mock (Context .class );
180
180
ChaincodeStub stub = mock (ChaincodeStub .class );
181
181
when (ctx .getStub ()).thenReturn (stub );
182
- when (stub .getStringState ("CAR000 " ))
182
+ when (stub .getStringState ("CAR0 " ))
183
183
.thenReturn ("{\" color\" :\" blue\" ,\" make\" :\" Toyota\" ,\" model\" :\" Prius\" ,\" owner\" :\" Tomoko\" }" );
184
184
185
185
Throwable thrown = catchThrowable (() -> {
186
- contract .createCar (ctx , "CAR000 " , "Nissan" , "Leaf" , "green" , "Siobhán" );
186
+ contract .createCar (ctx , "CAR0 " , "Nissan" , "Leaf" , "green" , "Siobhán" );
187
187
});
188
188
189
189
assertThat (thrown ).isInstanceOf (ChaincodeException .class ).hasNoCause ()
190
- .hasMessage ("Car CAR000 already exists" );
190
+ .hasMessage ("Car CAR0 already exists" );
191
191
assertThat (((ChaincodeException ) thrown ).getPayload ()).isEqualTo ("CAR_ALREADY_EXISTS" .getBytes ());
192
192
}
193
193
@@ -197,9 +197,9 @@ public void whenCarDoesNotExist() {
197
197
Context ctx = mock (Context .class );
198
198
ChaincodeStub stub = mock (ChaincodeStub .class );
199
199
when (ctx .getStub ()).thenReturn (stub );
200
- when (stub .getStringState ("CAR000 " )).thenReturn ("" );
200
+ when (stub .getStringState ("CAR0 " )).thenReturn ("" );
201
201
202
- Car car = contract .createCar (ctx , "CAR000 " , "Nissan" , "Leaf" , "green" , "Siobhán" );
202
+ Car car = contract .createCar (ctx , "CAR0 " , "Nissan" , "Leaf" , "green" , "Siobhán" );
203
203
204
204
assertThat (car ).isEqualTo (new Car ("Nissan" , "Leaf" , "green" , "Siobhán" ));
205
205
}
@@ -213,14 +213,14 @@ void invokeQueryAllCarsTransaction() {
213
213
when (ctx .getStub ()).thenReturn (stub );
214
214
when (stub .getStateByRange ("CAR0" , "CAR999" )).thenReturn (new MockCarResultsIterator ());
215
215
216
- Car [] cars = contract .queryAllCars (ctx );
216
+ CarQueryResult [] cars = contract .queryAllCars (ctx );
217
217
218
- final List <Car > expectedCars = new ArrayList <Car >();
219
- expectedCars .add (new Car ("Toyota" , "Prius" , "blue" , "Tomoko" ));
220
- expectedCars .add (new Car ("Ford" , "Mustang" , "red" , "Brad" ));
221
- expectedCars .add (new Car ("Hyundai" , "Tucson" , "green" , "Jin Soo" ));
222
- expectedCars .add (new Car ("Fiat" , "Punto" , "violet" , "Pari" ));
223
- expectedCars .add (new Car ("Holden" , "Barina" , "brown" , "Shotaro" ));
218
+ final List <CarQueryResult > expectedCars = new ArrayList <CarQueryResult >();
219
+ expectedCars .add (new CarQueryResult ( "CAR0" , new Car ("Toyota" , "Prius" , "blue" , "Tomoko" ) ));
220
+ expectedCars .add (new CarQueryResult ( "CAR1" , new Car ("Ford" , "Mustang" , "red" , "Brad" ) ));
221
+ expectedCars .add (new CarQueryResult ( "CAR2" , new Car ("Hyundai" , "Tucson" , "green" , "Jin Soo" ) ));
222
+ expectedCars .add (new CarQueryResult ( "CAR7" , new Car ("Fiat" , "Punto" , "violet" , "Pari" ) ));
223
+ expectedCars .add (new CarQueryResult ( "CAR9" , new Car ("Holden" , "Barina" , "brown" , "Shotaro" ) ));
224
224
225
225
assertThat (cars ).containsExactlyElementsOf (expectedCars );
226
226
}
@@ -234,12 +234,12 @@ public void whenCarExists() {
234
234
Context ctx = mock (Context .class );
235
235
ChaincodeStub stub = mock (ChaincodeStub .class );
236
236
when (ctx .getStub ()).thenReturn (stub );
237
- when (stub .getStringState ("CAR000 " ))
237
+ when (stub .getStringState ("CAR0 " ))
238
238
.thenReturn ("{\" color\" :\" blue\" ,\" make\" :\" Toyota\" ,\" model\" :\" Prius\" ,\" owner\" :\" Tomoko\" }" );
239
239
240
- Car car = contract .changeCarOwner (ctx , "CAR000 " , "Dr Evil" );
240
+ Car car = contract .changeCarOwner (ctx , "CAR0 " , "Dr Evil" );
241
241
242
- assertThat (car ).isEqualTo (new Car ("Toyota" , "Prius" , "blue" , "Dr Evil" ));
242
+ assertThat (car ).isEqualTo (new CarQueryResult ( "CAR0" , new Car ("Toyota" , "Prius" , "blue" , "Dr Evil" ) ));
243
243
}
244
244
245
245
@ Test
@@ -248,14 +248,14 @@ public void whenCarDoesNotExist() {
248
248
Context ctx = mock (Context .class );
249
249
ChaincodeStub stub = mock (ChaincodeStub .class );
250
250
when (ctx .getStub ()).thenReturn (stub );
251
- when (stub .getStringState ("CAR000 " )).thenReturn ("" );
251
+ when (stub .getStringState ("CAR0 " )).thenReturn ("" );
252
252
253
253
Throwable thrown = catchThrowable (() -> {
254
- contract .changeCarOwner (ctx , "CAR000 " , "Dr Evil" );
254
+ contract .changeCarOwner (ctx , "CAR0 " , "Dr Evil" );
255
255
});
256
256
257
257
assertThat (thrown ).isInstanceOf (ChaincodeException .class ).hasNoCause ()
258
- .hasMessage ("Car CAR000 does not exist" );
258
+ .hasMessage ("Car CAR0 does not exist" );
259
259
assertThat (((ChaincodeException ) thrown ).getPayload ()).isEqualTo ("CAR_NOT_FOUND" .getBytes ());
260
260
}
261
261
}
0 commit comments