From 5bbc22a54dd0617b3018d639424ac16fa84de7af Mon Sep 17 00:00:00 2001 From: Yann Le Goff Date: Thu, 1 Aug 2024 13:54:31 +0200 Subject: [PATCH] Add TU --- .../PyramidEditorBuilderTest.class.st | 116 ++++++++++++++++++ src/Pyramid-Tests/PyramidFakePlugin1.class.st | 5 + src/Pyramid-Tests/PyramidFakePlugin2.class.st | 5 + src/Pyramid-Tests/PyramidFakePlugin3.class.st | 5 + .../TPyramidFindPluginTest.class.st | 85 +++++++++++++ src/Pyramid/PyramidEditorBuilder.class.st | 1 + 6 files changed, 217 insertions(+) create mode 100644 src/Pyramid-Tests/PyramidFakePlugin1.class.st create mode 100644 src/Pyramid-Tests/PyramidFakePlugin2.class.st create mode 100644 src/Pyramid-Tests/PyramidFakePlugin3.class.st create mode 100644 src/Pyramid-Tests/TPyramidFindPluginTest.class.st diff --git a/src/Pyramid-Tests/PyramidEditorBuilderTest.class.st b/src/Pyramid-Tests/PyramidEditorBuilderTest.class.st index 76a3d469..a8e20dba 100644 --- a/src/Pyramid-Tests/PyramidEditorBuilderTest.class.st +++ b/src/Pyramid-Tests/PyramidEditorBuilderTest.class.st @@ -41,3 +41,119 @@ PyramidEditorBuilderTest >> testBuild2 [ self assert: plugin1 isInstalled. self deny: plugin2 isInstalled ] + +{ #category : #tests } +PyramidEditorBuilderTest >> testCommandExecutor [ + + | builder target1 target2 editor | + target1 := PyramidMainCommandExecutor new. + target2 := PyramidMainCommandExecutor new. + + "Default value is not nil" + builder := PyramidEditorBuilder new. + self assert: builder commandExecutor isNotNil. + + "editor is correctly set" + builder := PyramidEditorBuilder new. + builder commandExecutor: target1. + self assert: builder commandExecutor equals: target1. + editor := builder build. + self assert: editor commandExecutor equals: target1. + + "cannot set twice" + builder := PyramidEditorBuilder new. + builder commandExecutor: target1. + self assert: builder commandExecutor equals: target1. + [ + builder commandExecutor: target2. + self fail ] + on: PyramidBuilderAlreadyConfiguredError + do: [ self assert: true ] +] + +{ #category : #tests } +PyramidEditorBuilderTest >> testEditor [ + + | builder target1 target2 editor | + target1 := PyramidEditor new. + target2 := PyramidEditor new. + + "Default value is not nil" + builder := PyramidEditorBuilder new. + self assert: builder editor isNotNil. + + "editor is correctly set" + builder := PyramidEditorBuilder new. + builder editor: target1. + self assert: builder editor equals: target1. + editor := builder build. + self assert: editor equals: target1. + + "cannot set twice" + builder := PyramidEditorBuilder new. + builder editor: target1. + self assert: builder editor equals: target1. + [ + builder editor: target2. + self fail ] + on: PyramidBuilderAlreadyConfiguredError + do: [ self assert: true ] +] + +{ #category : #tests } +PyramidEditorBuilderTest >> testProjectModel [ + + | builder target1 target2 editor | + target1 := PyramidProjectModel new. + target2 := PyramidProjectModel new. + + "Default value is not nil" + builder := PyramidEditorBuilder new. + self assert: builder projectModel isNotNil. + + "editor is correctly set" + builder := PyramidEditorBuilder new. + builder projectModel: target1. + self assert: builder projectModel equals: target1. + editor := builder build. + self assert: editor projectModel equals: target1. + + "cannot set twice" + builder := PyramidEditorBuilder new. + builder projectModel: target1. + self assert: builder projectModel equals: target1. + [ + builder projectModel: target2. + self fail ] + on: PyramidBuilderAlreadyConfiguredError + do: [ self assert: true ] +] + +{ #category : #tests } +PyramidEditorBuilderTest >> testWindow [ + + | builder target1 target2 editor | + target1 := PyramidSimpleWindow new. + target2 := PyramidSimpleWindow new. + + "Default value is not nil" + builder := PyramidEditorBuilder new. + self assert: builder window isNotNil. + + "editor is correctly set" + builder := PyramidEditorBuilder new. + builder window: target1. + self assert: builder window equals: target1. + editor := builder build. + self assert: editor window equals: target1. + + "cannot set twice" + builder := PyramidEditorBuilder new. + builder window: target1. + self assert: builder window equals: target1. + [ + builder window: target2. + self fail ] + on: PyramidBuilderAlreadyConfiguredError + do: [ self assert: true ] +] diff --git a/src/Pyramid-Tests/PyramidFakePlugin1.class.st b/src/Pyramid-Tests/PyramidFakePlugin1.class.st new file mode 100644 index 00000000..c4cb4eb5 --- /dev/null +++ b/src/Pyramid-Tests/PyramidFakePlugin1.class.st @@ -0,0 +1,5 @@ +Class { + #name : #PyramidFakePlugin1, + #superclass : #PyramidFakePlugin, + #category : #'Pyramid-Tests-cases-core' +} diff --git a/src/Pyramid-Tests/PyramidFakePlugin2.class.st b/src/Pyramid-Tests/PyramidFakePlugin2.class.st new file mode 100644 index 00000000..f2431ef4 --- /dev/null +++ b/src/Pyramid-Tests/PyramidFakePlugin2.class.st @@ -0,0 +1,5 @@ +Class { + #name : #PyramidFakePlugin2, + #superclass : #PyramidFakePlugin, + #category : #'Pyramid-Tests-cases-core' +} diff --git a/src/Pyramid-Tests/PyramidFakePlugin3.class.st b/src/Pyramid-Tests/PyramidFakePlugin3.class.st new file mode 100644 index 00000000..c1e97451 --- /dev/null +++ b/src/Pyramid-Tests/PyramidFakePlugin3.class.st @@ -0,0 +1,5 @@ +Class { + #name : #PyramidFakePlugin3, + #superclass : #PyramidFakePlugin, + #category : #'Pyramid-Tests-cases-core' +} diff --git a/src/Pyramid-Tests/TPyramidFindPluginTest.class.st b/src/Pyramid-Tests/TPyramidFindPluginTest.class.st new file mode 100644 index 00000000..baebf6d7 --- /dev/null +++ b/src/Pyramid-Tests/TPyramidFindPluginTest.class.st @@ -0,0 +1,85 @@ +Class { + #name : #TPyramidFindPluginTest, + #superclass : #TestCase, + #traits : 'TPyramidFindPlugin', + #classTraits : 'TPyramidFindPlugin classTrait', + #instVars : [ + 'object1', + 'object2', + 'object3' + ], + #category : #'Pyramid-Tests-cases-core' +} + +{ #category : #accessing } +TPyramidFindPluginTest >> object1 [ + + ^ object1 +] + +{ #category : #accessing } +TPyramidFindPluginTest >> object2 [ + + ^ object2 +] + +{ #category : #accessing } +TPyramidFindPluginTest >> object3 [ + + ^ object3 +] + +{ #category : #accessing } +TPyramidFindPluginTest >> plugins [ + "Return a collection of TPyramidPlugin instances." + + ^ { + self object1. + self object2. + self object3. + self object3 } +] + +{ #category : #accessing } +TPyramidFindPluginTest >> setUp [ + + super setUp. + + object1 := PyramidFakePlugin1 new. + object2 := PyramidFakePlugin2 new. + object3 := PyramidFakePlugin3 new +] + +{ #category : #tests } +TPyramidFindPluginTest >> testFindPlugin [ + + self + assert: (self findPlugin: PyramidFakePlugin1) + equals: self object1. + self + assert: (self findPlugin: #PyramidFakePlugin2) + equals: self object2. + [ + self findPlugin: #PyramidFakePlugin3. + self fail ] + on: PyramidMultiplePluginsFoundError + do: [ :err | + self assert: err plugins size equals: 2. + self assert: err plugins first equals: self object3. + self assert: err plugins last equals: self object3 ]. + [ + self findPlugin: PyramidFakePlugin3. + self fail ] + on: PyramidMultiplePluginsFoundError + do: [ :err | + self assert: err plugins size equals: 2. + self assert: err plugins first equals: self object3. + self assert: err plugins last equals: self object3 ]. + [ + self findPlugin: #PyramidFakePlugin4. + self fail ] + on: PyramidNoPluginFoundError + do: [ :err | + self assert: err query equals: #PyramidFakePlugin4. + ] +] diff --git a/src/Pyramid/PyramidEditorBuilder.class.st b/src/Pyramid/PyramidEditorBuilder.class.st index 32fa2d07..05ca869e 100644 --- a/src/Pyramid/PyramidEditorBuilder.class.st +++ b/src/Pyramid/PyramidEditorBuilder.class.st @@ -92,6 +92,7 @@ PyramidEditorBuilder >> editor: anObject [ { #category : #accessing } PyramidEditorBuilder >> plugins [ + plugins ifNil: [ plugins := { } ]. ^ plugins ]