• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

moosetechnology / Famix-UnitTest / 15590759202

11 Jun 2025 04:47PM UTC coverage: 27.322% (-4.2%) from 31.536%
15590759202

push

github

Gabriel-Darbord
Complete mappings
And finally fix tests!?

64 of 199 new or added lines in 10 files covered. (32.16%)

614 existing lines in 23 files now uncovered.

603 of 2207 relevant lines covered (27.32%)

0.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Famix-UnitTest-Exporter/FamixUTHelperSetUpStrategy.class.st
1
"
2
I export Arrange elements as methods in an external helper class.
3
"
4
Class {
5
        #name : 'FamixUTHelperSetUpStrategy',
6
        #superclass : 'FamixUTAbstractSetUpStrategy',
7
        #instVars : [
8
                'helpers'
9
        ],
10
        #category : 'Famix-UnitTest-Exporter-Strategies',
11
        #package : 'Famix-UnitTest-Exporter',
12
        #tag : 'Strategies'
13
}
14

15
{ #category : 'ast' }
16
FamixUTHelperSetUpStrategy >> ensureHelperClassOn: aFamixUTExporter [
×
17
        "Get or create the helper class for the exporter's current class."
×
18

×
19
        | model className |
×
20
        model := aFamixUTExporter model.
×
21
        className := aFamixUTExporter currentClass name , 'Helper'.
×
22
        ^ helpers
×
23
                  at: className
×
24
                  ifAbsentPut: [ "add import for the helper class and create it"
×
25
                          aFamixUTExporter currentCompilationUnit addImportDeclaration:
×
26
                                  (model newImportDeclaration
×
27
                                           qualifiedName:
×
28
                                                   (model newQualifiedName name: ((WriteStream with:
×
29
                                                                                      aFamixUTExporter currentCompilationUnit
×
30
                                                                                              packageDeclaration qualifiedName name) << '.'
×
UNCOV
31
                                                                     << className) contents);
×
UNCOV
32
                                           isStatic: true;
×
33
                                           isOnDemand: true).
×
34
                          self makeHelperClassNamed: className on: aFamixUTExporter ]
×
35
]
×
36

37
{ #category : 'exporting' }
38
FamixUTHelperSetUpStrategy >> export: aFamixUTSetUp on: aFamixUTExporter [
×
39

×
40
        | model valueExporter helperClass comment |
×
41
        aFamixUTSetUp values ifEmpty: [ ^ self ].
×
42
        model := aFamixUTExporter model.
×
43
        valueExporter := aFamixUTExporter valueExporter.
×
44
        comment := '/**{@link ' , aFamixUTSetUp method case name , '#'
×
45
                   , aFamixUTSetUp method name , '()}*/'.
×
46

×
47
        "Only make helper if necessary => at least one non-empty object, collection or dictionary."
×
48
        aFamixUTSetUp values do: [ :value |
×
49
                ((value isOfObject or: [
×
50
                          value isOfCollection or: [ value isOfDictionary ] ]) and: [
×
51
                         value value isNotEmpty ])
×
52
                        ifFalse: [ value accept: valueExporter ]
×
53
                        ifTrue: [ "make the helper method to reconstruct the value"
×
NEW
54
                                | helperName helperMethod |
×
NEW
55
                                helperName := ((WriteStream with: 'given_') << value roleName
×
56
                                               << '_for_' << aFamixUTSetUp method name) contents.
×
57

×
NEW
58
                                (helperMethod := self
×
NEW
59
                                                         makeHelperMethodFor: value
×
NEW
60
                                                         on: aFamixUTExporter)
×
NEW
61
                                        name: helperName;
×
NEW
62
                                        addComment: (model newComment content: comment).
×
NEW
63

×
64
                                helperClass ifNil: [
×
65
                                        helperClass := self ensureHelperClassOn: aFamixUTExporter ].
×
NEW
66
                                helperClass addDeclaration: helperMethod.
×
67

×
NEW
68
                                "Add necessary imports to the helper class"
×
69
                                helperClass compilationUnit importDeclarations addAll:
×
70
                                        (valueExporter builder makeImportDeclarations: value).
×
71

×
NEW
72
                                "Add the helper to the method mapping"
×
NEW
73
                                (aFamixUTExporter mapping atMethod: aFamixUTSetUp method)
×
NEW
74
                                        addHelper: helperMethod
×
NEW
75
                                        named: helperName.
×
NEW
76

×
77
                                "IMPORTANT: build the method before calling it and assigning it to the variable,
×
78
                                because a value is considered already exported if it has been named!"
×
79
                                valueExporter statementBlock addStatement:
×
80
                                        (model newVarDeclStatement
×
81
                                                 type: (value asFASTJavaTypeExpressionOn: valueExporter);
×
82
                                                 addDeclarator: (model newVariableDeclarator
×
UNCOV
83
                                                                  variable: (valueExporter makeVariableExpression: value);
×
NEW
84
                                                                  expression: (model newMethodInvocation name: helperName));
×
85
                                                 yourself) ] ]
×
86
]
×
87

88
{ #category : 'accessing' }
89
FamixUTHelperSetUpStrategy >> helpers [
×
90

×
91
        ^ helpers
×
92
]
×
93

94
{ #category : 'initialization' }
95
FamixUTHelperSetUpStrategy >> initialize [
×
96

×
97
        helpers := Dictionary new
×
98
]
×
99

100
{ #category : 'ast' }
UNCOV
101
FamixUTHelperSetUpStrategy >> makeHelperClassNamed: className on: aFamixUTExporter [
×
102
        "Make a compilation unit containing the helper class and return the latter."
×
103

×
104
        | model |
×
105
        model := aFamixUTExporter model.
×
106
        ^ model newCompilationUnit
×
107
                  packageDeclaration: (model newPackageDeclaration qualifiedName:
×
108
                                           (model newQualifiedName name:
×
109
                                                            aFamixUTExporter currentCompilationUnit packageDeclaration
×
110
                                                                    qualifiedName name));
×
111
                  addClassDeclaration: (model newClassDeclaration name: className)
×
112
]
×
113

114
{ #category : 'ast' }
115
FamixUTHelperSetUpStrategy >> makeHelperMethodFor: value on: aFamixUTExporter [
×
116
        "Export the value inside the helper method, then restore the previous context."
×
117

×
118
        | model valueExporter method oldStatementBlock newStatementBlock |
×
119
        model := aFamixUTExporter model.
×
120
        valueExporter := aFamixUTExporter valueExporter.
×
121
        oldStatementBlock := valueExporter statementBlock.
×
UNCOV
122
        method := model newMethodEntity
×
UNCOV
123
                          addModifier: (model newModifier token: 'public');
×
UNCOV
124
                          addModifier: (model newModifier token: 'static');
×
UNCOV
125
                          type: (valueExporter builder referType: value type);
×
UNCOV
126
                          statementBlock:
×
UNCOV
127
                                  (newStatementBlock := model newStatementBlock).
×
UNCOV
128
        value accept: (valueExporter statementBlock: newStatementBlock).
×
UNCOV
129
        newStatementBlock addStatement:
×
UNCOV
130
                (model newReturnStatement expression:
×
UNCOV
131
                         (valueExporter makeVariableExpression: value)).
×
UNCOV
132
        valueExporter statementBlock: oldStatementBlock.
×
UNCOV
133
        ^ method
×
UNCOV
134
]
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc