Skip to content

Commit 42477ee

Browse files
Merge pull request #252 from OpenSmock/dev-pla
Fix issue #251: MolUtils instanceKindOf: not return nil when not inst…
2 parents 9246107 + bf79e1b commit 42477ee

5 files changed

Lines changed: 71 additions & 29 deletions

File tree

src/Molecule-Tests/MolComponentFactoryTest.class.st

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ MolComponentFactoryTest >> cleanGeneratedClassesAndTraits [
2525
edited := true.
2626
].
2727

28-
edited ifTrue:[(Delay forMilliseconds: 100) wait].
28+
edited ifTrue:[ 100 milliSeconds wait ].
2929
]
3030

3131
{ #category : #running }
@@ -326,7 +326,7 @@ MolComponentFactoryTest >> testComponentContractChanged [
326326

327327
]
328328

329-
{ #category : #'test - overload' }
329+
{ #category : #'tests - overload' }
330330
MolComponentFactoryTest >> testComponentContractImplGeneration [
331331

332332
| toFind |
@@ -353,7 +353,7 @@ MolComponentFactoryTest >> testComponentFactoryDefaultClass [
353353
MolComponentFactory cleanUp.
354354
]
355355

356-
{ #category : #'test - component subclasses' }
356+
{ #category : #'tests - component subclasses' }
357357
MolComponentFactoryTest >> testComponentSubclassesTraitsUses [
358358
"Test if the traits declaration are correctly injected into a component class hierarchy
359359
We have 3 components : A, B and C which inherits one another.
@@ -414,7 +414,7 @@ MolComponentFactoryTest >> testComponentSubclassesTraitsUses [
414414
MolTestComponentImplC setTraitComposition: #().
415415
]
416416

417-
{ #category : #'test - component subclasses' }
417+
{ #category : #'tests - component subclasses' }
418418
MolComponentFactoryTest >> testComponentSubclassesTraitsUses2 [
419419

420420
| type |
@@ -1329,7 +1329,7 @@ MolComponentFactoryTest >> testRebuildComponentAccessorsFor [
13291329
self assert: (MolCompleteComponentImpl selectors includes: #getMolUsedEventsSubscriber).
13301330
]
13311331

1332-
{ #category : #'test - overload' }
1332+
{ #category : #'tests - overload' }
13331333
MolComponentFactoryTest >> testRemoveOverloadedConsumedEvents [
13341334
"Testing issue #210 fix"
13351335

@@ -1342,7 +1342,7 @@ MolComponentFactoryTest >> testRemoveOverloadedConsumedEvents [
13421342
do: [ :e | e signal ]
13431343
]
13441344

1345-
{ #category : #'test - overload' }
1345+
{ #category : #'tests - overload' }
13461346
MolComponentFactoryTest >> testRemoveOverloadedProducedEvents [
13471347
"Testing issue #210 fix"
13481348

@@ -1355,7 +1355,7 @@ MolComponentFactoryTest >> testRemoveOverloadedProducedEvents [
13551355
do: [ :e | e signal ]
13561356
]
13571357

1358-
{ #category : #'test - overload' }
1358+
{ #category : #'tests - overload' }
13591359
MolComponentFactoryTest >> testRemoveOverloadedProvidedParameters [
13601360
"Testing issue #210 fix"
13611361

@@ -1368,7 +1368,7 @@ MolComponentFactoryTest >> testRemoveOverloadedProvidedParameters [
13681368
do: [ :e | e signal ]
13691369
]
13701370

1371-
{ #category : #'test - overload' }
1371+
{ #category : #'tests - overload' }
13721372
MolComponentFactoryTest >> testRemoveOverloadedProvidedServices [
13731373
"Testing issue #210 fix"
13741374

@@ -1381,7 +1381,7 @@ MolComponentFactoryTest >> testRemoveOverloadedProvidedServices [
13811381
do: [ :e | e signal ]
13821382
]
13831383

1384-
{ #category : #'test - overload' }
1384+
{ #category : #'tests - overload' }
13851385
MolComponentFactoryTest >> testRemoveOverloadedUsedParameters [
13861386
"Testing issue #210 fix"
13871387

@@ -1394,7 +1394,7 @@ MolComponentFactoryTest >> testRemoveOverloadedUsedParameters [
13941394
do: [ :e | e signal ]
13951395
]
13961396

1397-
{ #category : #'test - overload' }
1397+
{ #category : #'tests - overload' }
13981398
MolComponentFactoryTest >> testRemoveOverloadedUsedServices [
13991399
"Testing issue #210 fix"
14001400

@@ -1407,7 +1407,7 @@ MolComponentFactoryTest >> testRemoveOverloadedUsedServices [
14071407
do: [ :e | e signal ]
14081408
]
14091409

1410-
{ #category : #'test - overload' }
1410+
{ #category : #'tests - overload' }
14111411
MolComponentFactoryTest >> testSubOverrideOfContractAddingProvidedServices [
14121412
"Related to issue #209, can override an overriden contract"
14131413

@@ -1459,7 +1459,7 @@ MolComponentFactoryTest >> testSubOverrideOfContractAddingProvidedServices [
14591459

14601460
]
14611461

1462-
{ #category : #'test - overload' }
1462+
{ #category : #'tests - overload' }
14631463
MolComponentFactoryTest >> testSubOverrideOfContractAddingUsedServices [
14641464
"Related to issue #209, can override an overriden contract"
14651465

src/Molecule-Tests/MolDirtyComponentTest.class.st

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,19 @@ MolDirtyComponentTest >> generationTag [
3131
{ #category : #running }
3232
MolDirtyComponentTest >> setUp [
3333

34+
super setUp.
35+
3436
MolComponentManager cleanUp.
3537
self cleanGeneratedClassesAndTraits.
3638
]
3739

3840
{ #category : #running }
3941
MolDirtyComponentTest >> tearDown [
4042

41-
(Delay forMilliseconds: 10) wait.
4243
self cleanGeneratedClassesAndTraits.
4344
MolComponentManager cleanUp.
45+
46+
super tearDown
4447
]
4548

4649
{ #category : #tests }

src/Molecule-Tests/MolLocatorServicesTest.class.st

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ MolLocatorServicesTest >> testNotReadySearchEventSubscriberFor [
7373
self assert: (eventSubscriber observersConnection isEmpty).
7474
]
7575

76-
{ #category : #test }
76+
{ #category : #tests }
7777
MolLocatorServicesTest >> testSearchComponentTypeImplementorFor [
7878

7979
| manager component myComponent |
@@ -93,7 +93,7 @@ MolLocatorServicesTest >> testSearchComponentTypeImplementorFor [
9393
self assert: component identicalTo: myComponent
9494
]
9595

96-
{ #category : #test }
96+
{ #category : #tests }
9797
MolLocatorServicesTest >> testSearchComponentTypeImplementorForNamed [
9898

9999
| manager component myComponent |

src/Molecule-Tests/MolUtilsTest.class.st

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,20 @@ Class {
77
#category : #'Molecule-Tests-Cases'
88
}
99

10-
{ #category : #tests }
10+
{ #category : #running }
1111
MolUtilsTest >> setUp [
1212

13+
super setUp.
14+
1315
MolComponentManager cleanUp
1416
]
1517

16-
{ #category : #tests }
18+
{ #category : #running }
1719
MolUtilsTest >> tearDown [
1820

19-
MolComponentManager cleanUp
21+
MolComponentManager cleanUp.
22+
23+
super tearDown
2024
]
2125

2226
{ #category : #tests }
@@ -58,7 +62,21 @@ MolUtilsTest >> testActivateComponents [
5862
{ #category : #tests }
5963
MolUtilsTest >> testAllComponentImplementationClassesOfType [
6064

61-
self assert: (MolUtils allComponentImplementationClassesOfType: MolCompleteComponent) size equals: 7.
65+
| nb |
66+
67+
"Fix #250 by waiting for code-source changes notification from previous tests"
68+
2 second wait.
69+
70+
nb := 0.
71+
MolCompleteComponent users do:[ :e |
72+
e isComponentClass ifTrue:[
73+
nb := nb + 1.
74+
e allSubclassesDo: [ :f | f isComponentClass ifTrue:[ nb := nb + 1 ] ]
75+
].
76+
].
77+
78+
self assert: nb > 0.
79+
self assert: (MolUtils allComponentImplementationClassesOfType: MolCompleteComponent) size equals: nb.
6280
]
6381

6482
{ #category : #tests }
@@ -235,20 +253,36 @@ MolUtilsTest >> testInstanceKindOf [
235253
"Test method instanceKindOf: of Utils"
236254

237255
| homeServices |
238-
MolComponentManager default deploymentServices
239-
deployComponentImplementation: MolBasicSubComponentImpl.
256+
self assert: (MolUtils instanceKindOf: MolBasicComponentImpl) isNil.
257+
258+
MolComponentManager default deploymentServices deployComponentImplementation: MolBasicSubComponentImpl.
240259
homeServices := MolComponentManager default homeServices.
241260
homeServices instantiateComponent: MolBasicSubComponentImpl.
242261
self assert: (MolUtils instanceKindOf: MolBasicComponentImpl) notNil
243262
]
244263

264+
{ #category : #tests }
265+
MolUtilsTest >> testInstanceKindOfNamed [
266+
"Test method instanceKindOf:Named: of Utils"
267+
268+
self assert: (MolUtils instanceKindOf: MolBasicComponentImpl) isNil.
269+
self assert: (MolUtils instanceKindOf: MolBasicComponentImpl named: #myComponent) isNil.
270+
self assert: (MolUtils instanceKindOf: MolBasicComponentImpl named: #otherComponent) isNil.
271+
272+
273+
MolBasicSubComponentImpl start: #myComponent.
274+
self assert: (MolUtils instanceKindOf: MolBasicComponentImpl) isNil.
275+
self assert: (MolUtils instanceKindOf: MolBasicComponentImpl named: #myComponent) notNil.
276+
self assert: (MolUtils instanceKindOf: MolBasicComponentImpl named: #otherComponent) isNil.
277+
]
278+
245279
{ #category : #tests }
246280
MolUtilsTest >> testInstanceOf [
247281

248-
| instance |
282+
self assert: (MolUtils instanceOf: MolBasicComponentImpl) isNil.
283+
249284
MolUtils startComponent: MolBasicComponentImpl.
250-
instance := MolUtils instanceOf: MolBasicComponentImpl.
251-
self assert: instance class equals: MolBasicComponentImpl.
285+
self assert: (MolUtils instanceOf: MolBasicComponentImpl) class equals: MolBasicComponentImpl.
252286

253287
]
254288

src/Molecule/MolUtils.class.st

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,18 @@ MolUtils class >> instanceKindOf: aClass [
191191

192192
{ #category : #accessing }
193193
MolUtils class >> instanceKindOf: aClass named: aName [
194+
194195
| instance |
195-
196-
(self instanceOf: aClass named: aName) ifNil:[
197-
aClass allSubclasses do:
198-
[:c |
196+
"Search instance in class instances"
197+
instance := self instanceOf: aClass named: aName.
198+
instance ifNotNil: [ :e | ^ e ].
199+
200+
"Search instance in subclasses instances"
201+
aClass allSubclasses do: [ :c |
199202
instance := self instanceOf: c named: aName.
200-
instance ifNotNil: [^instance]]].
203+
instance ifNotNil: [ ^ instance ] ].
204+
205+
^ nil
201206
]
202207

203208
{ #category : #accessing }

0 commit comments

Comments
 (0)