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

moosetechnology / Famix-UnitTest / 8756162640

19 Apr 2024 03:41PM UTC coverage: 36.187% (-0.7%) from 36.931%
8756162640

push

github

Gabriel-Darbord
Exporter: Rename classes + Configurable AssertJ strategy

29 of 118 new or added lines in 9 files covered. (24.58%)

503 of 1390 relevant lines covered (36.19%)

0.36 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
        #category : #'Famix-UnitTest-Exporter-Strategies'
8
}
9

10
{ #category : #ast }
NEW
11
FamixUTHelperSetUpStrategy >> ensureHelperClassOn: aFamixUTExporter [
×
12
        "Get or create the helper class for the exporter's current class."
×
13

×
14
        | model className |
×
15
        model := aFamixUTExporter model.
×
16
        className := aFamixUTExporter currentClass name , 'Helper'.
×
17
        ^ model allFASTJavaClassDeclaration
×
18
                  detect: [ :class | class name = className ]
×
19
                  ifNone: [ "add import for the helper class and create it"
×
20
                          aFamixUTExporter currentCompilationUnit addImportDeclaration:
×
21
                                  (model newImportDeclaration
×
22
                                           qualifiedName:
×
23
                                                   (model newQualifiedName name: ((WriteStream with:
×
24
                                                                                      aFamixUTExporter currentCompilationUnit
×
25
                                                                                              packageDeclaration qualifiedName name) << '.'
×
26
                                                                     << className) contents);
×
27
                                           isStatic: true;
×
28
                                           isOnDemand: true).
×
29
                          self makeHelperClassNamed: className on: aFamixUTExporter ]
×
30
]
×
31

32
{ #category : #exporting }
NEW
33
FamixUTHelperSetUpStrategy >> export: aFamixUTSetUp on: aFamixUTExporter [
×
34

×
35
        | model valueExporter helperClass comment |
×
36
        aFamixUTSetUp values ifEmpty: [ ^ self ].
×
37
        model := aFamixUTExporter model.
×
38
        valueExporter := aFamixUTExporter valueExporter.
×
39
        comment := '/**{@link ' , aFamixUTSetUp method case name , '#'
×
40
                   , aFamixUTSetUp method name , '()}*/'.
×
41
        "Only make helper if necessary => at least one non-empty object, collection or dictionary."
×
42
        aFamixUTSetUp values do: [ :value |
×
43
                ((value isOfObject or: [
×
44
                          value isOfCollection or: [ value isOfDictionary ] ]) and: [
×
45
                         value value isNotEmpty ])
×
46
                        ifFalse: [ value accept: valueExporter ]
×
47
                        ifTrue: [
×
48
                                | methodName |
×
49
                                methodName := ((WriteStream with: 'given_')
×
50
                                               << value typedEntity name
×
51
                                               <<
×
52
                                               (value resultInSpan
×
53
                                                        ifNotNil: [ '_expected' ]
×
54
                                                        ifNil: [ '_argument' ]) << '_for_'
×
55
                                               << aFamixUTSetUp method name) contents.
×
56
                                helperClass ifNil: [
×
57
                                        helperClass := self ensureHelperClassOn: aFamixUTExporter ].
×
58
                                helperClass addDeclaration:
×
59
                                        ((self makeHelperMethodFor: value on: aFamixUTExporter)
×
60
                                                 name: methodName;
×
61
                                                 addComment: (model newComment content: comment);
×
62
                                                 yourself).
×
63
                                "add necessary imports to the helper class"
×
64
                                helperClass compilationUnit importDeclarations addAll:
×
65
                                        (valueExporter builder makeImportDeclarations: value).
×
66
                                "IMPORTANT: build the method before calling it and assigning it to the variable,
×
67
                                because a value is considered already exported if it has been named!"
×
68
                                valueExporter statementBlock addStatement:
×
69
                                        (model newVarDeclStatement
×
70
                                                 type: (value asFASTJavaTypeExpressionOn: valueExporter);
×
71
                                                 addDeclarator: (model newVariableDeclarator
×
72
                                                                  variable: (valueExporter makeVariableExpression: value);
×
73
                                                                  expression: (model newMethodInvocation name: methodName));
×
74
                                                 yourself) ] ]
×
75
]
×
76

77
{ #category : #ast }
NEW
78
FamixUTHelperSetUpStrategy >> makeHelperClassNamed: className on: aFamixUTExporter [
×
79
        "Make a compilation unit containing the helper class and return the latter."
×
80

×
81
        | model |
×
82
        model := aFamixUTExporter model.
×
83
        ^ model newCompilationUnit
×
84
                  packageDeclaration: (model newPackageDeclaration qualifiedName:
×
85
                                           (model newQualifiedName name:
×
86
                                                            aFamixUTExporter currentCompilationUnit packageDeclaration
×
87
                                                                    qualifiedName name));
×
88
                  importDeclarations:
×
89
                          (aFamixUTExporter valueExporter objectExportStrategy
×
90
                                   dependencyImportsOn: model);
×
91
                  addClassDeclaration: (model newClassDeclaration name: className)
×
92
]
×
93

94
{ #category : #ast }
NEW
95
FamixUTHelperSetUpStrategy >> makeHelperMethodFor: value on: aFamixUTExporter [
×
96
        "Export the value inside the helper method, then restore the previous context."
×
97

×
98
        | model valueExporter method oldStatementBlock newStatementBlock |
×
99
        model := aFamixUTExporter model.
×
100
        valueExporter := aFamixUTExporter valueExporter.
×
101
        oldStatementBlock := valueExporter statementBlock.
×
102
        method := model newMethodEntity
×
103
                          addModifier: (model newModifier token: 'public');
×
104
                          addModifier: (model newModifier token: 'static');
×
105
                          type: (valueExporter builder referType: value type);
×
106
                          statementBlock:
×
107
                                  (newStatementBlock := model newStatementBlock).
×
108
        value accept: (valueExporter statementBlock: newStatementBlock).
×
109
        newStatementBlock addStatement:
×
110
                (model newReturnStatement expression:
×
111
                         (valueExporter makeVariableExpression: value)).
×
112
        valueExporter statementBlock: oldStatementBlock.
×
113
        ^ method
×
114
]
×
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