7
7
#category : #' Chest-Tests'
8
8
}
9
9
10
+ { #category : #tests }
11
+ ChestTest class >> chestClass [
12
+
13
+ ^ Chest
14
+ ]
15
+
16
+ { #category : #tests }
17
+ ChestTest >> chestClass [
18
+
19
+ ^ self class chestClass
20
+ ]
21
+
10
22
{ #category : #accessing }
11
23
ChestTest >> firstChestNameAvailable [
12
24
@@ -48,7 +60,7 @@ ChestTest >> tearDown [
48
60
49
61
{ #category : #tests }
50
62
ChestTest >> testAddRemoveToChest [
51
- self testAddRemoveToChest: Chest new .
63
+ self testAddRemoveToChest: self chestClass new .
52
64
]
53
65
54
66
{ #category : #tests }
@@ -74,14 +86,14 @@ ChestTest >> testAddRemoveToChest: aChest [
74
86
{ #category : #tests }
75
87
ChestTest >> testAddRemoveToDefaultChest [
76
88
" Tests that the Chest class itself works as a chest"
77
- self testAddRemoveToChest: Chest .
89
+ self testAddRemoveToChest: self chestClass .
78
90
]
79
91
80
92
{ #category : #tests }
81
93
ChestTest >> testAddingAnObjectTwiceInSameChestWithDifferentNamesRemoveTheOldKeyForThisObject [
82
94
83
95
| chest object oldName newName |
84
- chest := Chest new .
96
+ chest := self chestClass new .
85
97
object := Object new .
86
98
oldName := chest add: object.
87
99
@@ -96,16 +108,16 @@ ChestTest >> testAddingAnObjectTwiceInSameChestWithDifferentNamesRemoveTheOldKey
96
108
{ #category : #tests }
97
109
ChestTest >> testAlwaysGiveFreshIDToNewChests [
98
110
| c1 c2 c3 idList c4 |
99
- c1 := Chest new .
100
- c2 := Chest new .
101
- c3 := Chest new .
111
+ c1 := self chestClass new .
112
+ c2 := self chestClass new .
113
+ c3 := self chestClass new .
102
114
self assert: c1 name ~= c2 name.
103
115
self assert: c2 name ~= c3 name.
104
116
self assert: c1 name ~= c3 name.
105
117
idList := OrderedCollection new .
106
118
idList add: (c1 name); add: (c2 name); add: (c3 name).
107
- Chest removeChest: c3.
108
- c4 := Chest new .
119
+ self chestClass removeChest: c3.
120
+ c4 := self chestClass new .
109
121
self assert: ((idList includes: c4 name) not ).
110
122
111
123
@@ -115,7 +127,7 @@ ChestTest >> testAlwaysGiveFreshIDToNewChests [
115
127
ChestTest >> testAtPutAddsObjectToChestWithCorrectName [
116
128
117
129
| chest object |
118
- chest := Chest new .
130
+ chest := self chestClass new .
119
131
object := 42 .
120
132
121
133
self should: [chest at: ' toto' ] raise: KeyNotFound .
@@ -129,7 +141,7 @@ ChestTest >> testAtPutAddsObjectToChestWithCorrectName [
129
141
ChestTest >> testCannotNameChestWithInvalidName [
130
142
131
143
| chest |
132
- chest := Chest new .
144
+ chest := self chestClass new .
133
145
134
146
self
135
147
should: [ chest name: ' \n\t' ] raise: ChestInvalidNameError ;
@@ -142,7 +154,7 @@ ChestTest >> testCannotNameChestWithInvalidName [
142
154
ChestTest >> testCannotNameObjectInChestWithInvalidName [
143
155
144
156
| chest |
145
- chest := Chest new .
157
+ chest := self chestClass new .
146
158
147
159
self
148
160
should: [ chest at: ' \n\t' put: Object new ]
@@ -159,7 +171,7 @@ ChestTest >> testCannotNameObjectInChestWithInvalidName [
159
171
ChestTest >> testCannotReNameObjectInChestWithInvalidName [
160
172
161
173
| chest object |
162
- chest := Chest new .
174
+ chest := self chestClass new .
163
175
object := Object new .
164
176
165
177
chest at: ' toto' put: object.
@@ -185,13 +197,13 @@ ChestTest >> testChestCreationWithCustomName [
185
197
| firstNameAvailable chestWithCustomName |
186
198
firstNameAvailable := self firstChestNameAvailable.
187
199
188
- self should: [ Chest named: firstNameAvailable ] raise: KeyNotFound .
200
+ self should: [ self chestClass named: firstNameAvailable ] raise: KeyNotFound .
189
201
190
- chestWithCustomName := Chest newNamed: firstNameAvailable.
202
+ chestWithCustomName := self chestClass newNamed: firstNameAvailable.
191
203
192
204
self assert: chestWithCustomName name equals: firstNameAvailable.
193
205
self
194
- assert: (Chest named: firstNameAvailable)
206
+ assert: (self chestClass named: firstNameAvailable)
195
207
identicalTo: chestWithCustomName
196
208
]
197
209
@@ -234,21 +246,21 @@ ChestTest >> testChestCreationWithNameThatAlreadyExistsRaisesAnError [
234
246
ChestTest >> testChestDictionaryProvidesCopyOfAllChests [
235
247
236
248
| chestDictionary firstNameAvailable |
237
- chestDictionary := Chest chestDictionary.
249
+ chestDictionary := self chestClass chestDictionary.
238
250
firstNameAvailable := self firstChestNameAvailable.
239
251
240
252
chestDictionary at: firstNameAvailable put: 42 .
241
253
242
254
self
243
- should: [ Chest named: firstNameAvailable ]
255
+ should: [ self chestClass named: firstNameAvailable ]
244
256
raise: KeyNotFound
245
257
]
246
258
247
259
{ #category : #tests }
248
260
ChestTest >> testContentsProvidesCopyOfChestContent [
249
261
250
262
| chest object contents objectInCopy |
251
- chest := Chest new .
263
+ chest := self chestClass new .
252
264
object := 42 .
253
265
objectInCopy := 72 .
254
266
@@ -271,7 +283,7 @@ ChestTest >> testDefaultInstance [
271
283
ChestTest >> testEmpty [
272
284
273
285
| chest |
274
- chest := Chest new .
286
+ chest := self chestClass new .
275
287
chest
276
288
at: ' toto' put: ' toto' ;
277
289
at: ' tata' put: ' tata' ;
@@ -292,7 +304,7 @@ ChestTest >> testEmpty [
292
304
ChestTest >> testEmptyChest [
293
305
294
306
| chest |
295
- chest := Chest new .
307
+ chest := self chestClass new .
296
308
chest
297
309
at: ' toto' put: 42 ;
298
310
at: ' titi' put: 72 ;
@@ -308,8 +320,8 @@ ChestTest >> testEmptyChest [
308
320
ChestTest >> testGettingChestFromID [
309
321
" Tests that retrieving chests by their id works"
310
322
| c1 c2 |
311
- c1 := Chest new .
312
- c2 := Chest new .
323
+ c1 := self chestClass new .
324
+ c2 := self chestClass new .
313
325
self assert: (Chest named: c1 name) identicalTo: c1.
314
326
self assert: (Chest named: c2 name) identicalTo: c2.
315
327
" Tests that accessing a removed chest signals an error"
@@ -329,7 +341,7 @@ ChestTest >> testNotifications [
329
341
self assert: l chestRemovedReceived not .
330
342
331
343
" Test the event on chest creation"
332
- c := Chest new .
344
+ c := self chestClass new .
333
345
self assert: l newChestReceived.
334
346
self assert: l newChest identicalTo: c.
335
347
@@ -341,7 +353,7 @@ ChestTest >> testNotifications [
341
353
self assert: l newContentsOfUpdatedChest equals: c contents.
342
354
343
355
" Test the event on chest removal"
344
- Chest removeChest: c.
356
+ self chestClass removeChest: c.
345
357
self assert: l chestRemovedReceived.
346
358
self assert: l removedChest identicalTo: c.
347
359
]
@@ -350,47 +362,47 @@ ChestTest >> testNotifications [
350
362
ChestTest >> testRemove [
351
363
352
364
| chest |
353
- chest := Chest new .
365
+ chest := self chestClass new .
354
366
355
- self assert: (Chest named: chest name) identicalTo: chest.
367
+ self assert: (self chestClass named: chest name) identicalTo: chest.
356
368
357
369
chest remove.
358
370
359
- self should: [ Chest named: chest name ] raise: KeyNotFound
371
+ self should: [ self chestClass named: chest name ] raise: KeyNotFound
360
372
]
361
373
362
374
{ #category : #tests }
363
375
ChestTest >> testRemoveChestNamed [
364
376
365
377
| chest |
366
- chest := Chest new .
378
+ chest := self chestClass new .
367
379
368
- self assert: (Chest named: chest name) identicalTo: chest.
380
+ self assert: (self chestClass named: chest name) identicalTo: chest.
369
381
370
- Chest removeChestNamed: chest name.
382
+ self chestClass removeChestNamed: chest name.
371
383
372
- self should: [ Chest named: chest name ] raise: KeyNotFound
384
+ self should: [ self chestClass named: chest name ] raise: KeyNotFound
373
385
]
374
386
375
387
{ #category : #tests }
376
388
ChestTest >> testRemoveChestNamedWithDefaultInstance [
377
389
378
390
| chest |
379
- chest := Chest defaultInstance.
391
+ chest := self chestClass defaultInstance.
380
392
381
- self assert: (Chest named: chest name) identicalTo: chest.
393
+ self assert: (self chestClass named: chest name) identicalTo: chest.
382
394
383
- Chest removeChestNamed: chest name.
395
+ self chestClass removeChestNamed: chest name.
384
396
385
- self should: [ Chest named: chest name ] raise: KeyNotFound .
386
- self deny: Chest defaultInstance identicalTo: chest
397
+ self should: [ self chestClass named: chest name ] raise: KeyNotFound .
398
+ self deny: self chestClass defaultInstance identicalTo: chest
387
399
]
388
400
389
401
{ #category : #tests }
390
402
ChestTest >> testRemoveObjectNamedWithExistingObject [
391
403
392
404
| chest |
393
- chest := Chest new .
405
+ chest := self chestClass new .
394
406
chest
395
407
at: ' toto' put: ' toto' ;
396
408
at: ' tata' put: ' tata' ;
@@ -407,7 +419,7 @@ ChestTest >> testRemoveObjectNamedWithExistingObject [
407
419
ChestTest >> testRemoveObjectNamedWithObjectThatDoesNotExist [
408
420
409
421
| chest |
410
- chest := Chest new .
422
+ chest := self chestClass new .
411
423
chest
412
424
at: ' toto' put: ' toto' ;
413
425
at: ' tata' put: ' tata' ;
@@ -424,21 +436,21 @@ ChestTest >> testRemoveObjectNamedWithObjectThatDoesNotExist [
424
436
ChestTest >> testRemoveWithDefaultInstance [
425
437
426
438
| chest |
427
- chest := Chest defaultInstance.
439
+ chest := self chestClass defaultInstance.
428
440
429
441
self assert: (Chest named: chest name) identicalTo: chest.
430
442
431
443
chest remove.
432
444
433
- self should: [ Chest named: chest name ] raise: KeyNotFound .
434
- self deny: Chest defaultInstance identicalTo: chest
445
+ self should: [ self chestClass named: chest name ] raise: KeyNotFound .
446
+ self deny: self chestClass defaultInstance identicalTo: chest
435
447
]
436
448
437
449
{ #category : #tests }
438
450
ChestTest >> testRenameObjectInto [
439
451
440
452
| chest object |
441
- chest := Chest new .
453
+ chest := self chestClass new .
442
454
object := Object new .
443
455
chest at: ' toto' put: object.
444
456
@@ -454,7 +466,7 @@ ChestTest >> testRenameObjectInto [
454
466
ChestTest >> testRenameObjectIntoRaisesErrorWhenObjectIsNotInChest [
455
467
456
468
| chest objectToBeRenamed objectInChest |
457
- chest := Chest new .
469
+ chest := self chestClass new .
458
470
objectToBeRenamed := Object new .
459
471
objectInChest := Object new .
460
472
chest at: ' tata' put: objectInChest.
@@ -475,7 +487,7 @@ ChestTest >> testRenameObjectIntoRaisesErrorWhenObjectIsNotInChest [
475
487
ChestTest >> testRenameObjectIntoRaisesErrorWhenObjectOfSameNameAlreadyExists [
476
488
477
489
| chest objectToBeRenamed objectAlreadyHavingNewName |
478
- chest := Chest new .
490
+ chest := self chestClass new .
479
491
objectToBeRenamed := Object new .
480
492
objectAlreadyHavingNewName := Object new .
481
493
chest at: ' tata' put: objectAlreadyHavingNewName.
@@ -500,33 +512,33 @@ ChestTest >> testRenameObjectIntoRaisesErrorWhenObjectOfSameNameAlreadyExists [
500
512
ChestTest >> testRenamingChestChangesItsKeyInDictionary [
501
513
502
514
| chest firstNameAvailable oldName |
503
- chest := Chest new .
515
+ chest := self chestClass new .
504
516
oldName := chest name.
505
517
firstNameAvailable := self firstChestNameAvailable.
506
518
507
519
chest name: firstNameAvailable.
508
520
509
521
self assert: chest name equals: firstNameAvailable.
510
- self assert: (Chest named: firstNameAvailable) identicalTo: chest.
511
- self should: [ Chest named: oldName ] raise: KeyNotFound
522
+ self assert: (self chestClass named: firstNameAvailable) identicalTo: chest.
523
+ self should: [ self chestClass named: oldName ] raise: KeyNotFound
512
524
]
513
525
514
526
{ #category : #tests }
515
527
ChestTest >> testRenamingChestRaisesErrorWhenChestOfSameNameAlreadyExists [
516
528
517
529
| chestToBeRenamed firstNameAvailable oldName chestAlreadyHavingNewName |
518
- chestToBeRenamed := Chest new .
530
+ chestToBeRenamed := self chestClass new .
519
531
oldName := chestToBeRenamed name.
520
532
firstNameAvailable := self firstChestNameAvailable.
521
- chestAlreadyHavingNewName := Chest newNamed: firstNameAvailable.
533
+ chestAlreadyHavingNewName := self chestClass newNamed: firstNameAvailable.
522
534
523
535
self
524
536
should: [ chestToBeRenamed name: firstNameAvailable ]
525
537
raise: ChestKeyAlreadyInUseError .
526
538
527
539
self assert: chestToBeRenamed name equals: oldName.
528
540
self
529
- assert: (Chest named: firstNameAvailable)
541
+ assert: (self chestClass named: firstNameAvailable)
530
542
identicalTo: chestAlreadyHavingNewName.
531
- self assert: (Chest named: oldName) identicalTo: chestToBeRenamed
543
+ self assert: (self chestClass named: oldName) identicalTo: chestToBeRenamed
532
544
]
0 commit comments