Commit 1d912ac7 authored by Romain F. T's avatar Romain F. T
Browse files

fix minor issue in the output of #633

parent 105ccab0
......@@ -39,7 +39,6 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.useNotifyAllInsteadOfNotify(),
thisModule.dontCallThreadRun(),
-- Code Style rules
--
thisModule.avoidDollarSigns(),
......@@ -112,10 +111,9 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
--
thisModule.commentContent(),
thisModule.commentRequired(),
thisModule.uncommentedEmptyConstructor(),
-- FIXME thisModule.uncommentedEmptyConstructor(),
thisModule.uncommentedEmptyMethodBody(),
-- Error prone rules
--
thisModule.avoidCallingFinalize(),
......@@ -156,8 +154,8 @@ helper def: allMeasures(project : java!Model): Set(smm!Measure) =
thisModule.avoidReassigningParameters(),
thisModule.avoidStringBufferField(),
thisModule.forLoopVariableCount(),
thisModule.JUnitTestsShouldIncludeAssert(),
thisModule.JUnitTestContainsTooManyAsserts(1), -- TODO il s'agit d'une
thisModule.jUnitTestsShouldIncludeAssert(),
thisModule.jUnitTestContainsTooManyAsserts(1), -- TODO il s'agit d'une
-- règle paramétrée, je ne sais pas du tout où l'utilisateur indiquerait
-- sa préférence donc en attendant je mets 1 (valeur par défaut).
thisModule.oneDeclarationPerLine(),
......@@ -1374,7 +1372,7 @@ rule MeasureJUnitTestContainsTooManyAsserts(m: java!MethodDeclaration, c: java!C
shortDescription <- 'Unit tests should not contain too many asserts.'
),
measurement: smm!DirectMeasurement (
error<- 'The JUnit test ' + m.getName() + ' in the class ' + c.getName() + ' contains more than ' + max + ' assertions.'
error<- 'The JUnit test ' + m.name + ' in the class ' + c.name + ' contains more than ' + max + ' assertions.'
)
do {
noc;
......
......@@ -62,7 +62,6 @@ helper def: avoidReassigningParameters(): Set(smm!Measure) =
)->flatten();
--- Rule for metrics AvoidStringBufferField
-- TODO: improve comment
helper def: avoidStringBufferField() : Set(smm!Measure) =
......@@ -71,7 +70,6 @@ helper def: avoidStringBufferField() : Set(smm!Measure) =
->select(dec | ( dec.type.type.name = 'StringBuffer' or dec.type.type.name = 'StringBuilder'))
->collect(dec | thisModule.MeasureAvoidStringBufferField(dec));
--- Detects the use of empty statements blocks. These blocks serve no purpose and should be removed
helper def: emptyStatementBlock() : Set(smm!Measure) =
java!Block.allInstances()
......@@ -127,7 +125,7 @@ helper context java!VariableDeclarationExpression def: nbLocalVariableDeclaratio
--- helper for the rule JUnitTestsShouldIncludeAssert
--TODO ne couvre pas du tout tous les cas possibles que fait le vrai PMD (mockito, etc.)
helper def: JUnitTestsShouldIncludeAssert() : Set(smm!Measure) =
helper def: jUnitTestsShouldIncludeAssert() : Set(smm!Measure) =
java!ClassDeclaration.allInstances()
-> select(cl | cl.isTestClass())
-> iterate(i; res : Set(smm!Measure) = Set{} | i.bodyDeclarations
......@@ -137,22 +135,19 @@ helper def: JUnitTestsShouldIncludeAssert() : Set(smm!Measure) =
and mtd.numberOfAsserts() < 1
)
-> collect(mtd | thisModule.MeasureJUnitTestsShouldIncludeAssert(mtd, i))
)
;
);
-- counts the number of assertions in a method declaration
helper context java!MethodDeclaration def: numberOfAsserts() : Integer =
self.getBody().statements
-> select(sttm | sttm <> OclUndefined) -- utile?
-> select(sttm | sttm.oclIsTypeOf(java!AssertStatement))
-> size()
;
-> size();
-- tells if a method is a test (assuming its class is a TestCase)
-- XXX we maybe could check the annotation too?
helper context java!MethodDeclaration def: isTestMethod() : Boolean =
self.name.substring(1, 4) = 'test'
;
self.name.substring(1, 4) = 'test';
-- tells if a class extends TestCase
helper context java!ClassDeclaration def: isTestClass() : Boolean =
......@@ -162,11 +157,10 @@ helper context java!ClassDeclaration def: isTestClass() : Boolean =
self.superClass.type.name = 'junit.framework.TestCase' or self.superClass.type.name = 'TestCase'
else
false
endif
;
endif;
--- helper for the rule JUnitTestContainsTooManyAsserts
helper def: JUnitTestContainsTooManyAsserts(maximumAsserts : Integer) : Set(smm!Measure) =
helper def: jUnitTestContainsTooManyAsserts(maximumAsserts : Integer) : Set(smm!Measure) =
java!ClassDeclaration.allInstances()
-> select(cl | cl.isTestClass())
-> iterate(i; res : Set(smm!Measure) = Set{} | i.bodyDeclarations
......@@ -176,8 +170,7 @@ helper def: JUnitTestContainsTooManyAsserts(maximumAsserts : Integer) : Set(smm!
and mtd.numberOfAsserts() > maximumAsserts
)
-> collect(mtd | thisModule.MeasureJUnitTestContainsTooManyAsserts(mtd, i, maximumAsserts))
)
;
);
-- #TODO: Add comment
helper def: oneDeclarationPerLine(): Set(smm!Measure) =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment