lu.uni.serval.ikora.smells.checks.LongTestStepsCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ikora-smells Show documentation
Show all versions of ikora-smells Show documentation
Package performing smell detection on the Robot Framework language.
package lu.uni.serval.ikora.smells.checks;
import lu.uni.serval.ikora.smells.SmellCheck;
import lu.uni.serval.ikora.smells.SmellConfiguration;
import lu.uni.serval.ikora.smells.SmellMetric;
import lu.uni.serval.ikora.smells.SmellResult;
import lu.uni.serval.ikora.core.analytics.difference.Edit;
import lu.uni.serval.ikora.core.analytics.KeywordStatistics;
import lu.uni.serval.ikora.core.model.KeywordDefinition;
import lu.uni.serval.ikora.core.model.SourceNode;
import lu.uni.serval.ikora.core.model.Step;
import lu.uni.serval.ikora.core.model.TestCase;
import lu.uni.serval.ikora.core.utils.Cfg;
import java.util.*;
public class LongTestStepsCheck implements SmellCheck {
@Override
public SmellResult computeMetric(TestCase testCase, SmellConfiguration configuration) {
final Set nodes = new HashSet<>();
for(Step step: testCase.getSteps()){
if(KeywordStatistics.getSequenceSize(step) > configuration.getMaximumStepSize()){
nodes.add(step);
}
}
double rawValue = nodes.size();
double normalizedValue = rawValue / testCase.getSteps().size();
return new SmellResult(SmellMetric.Type.LONG_TEST_STEPS, rawValue, normalizedValue, nodes);
}
@Override
public boolean isFix(Edit edit, Set nodes, SmellConfiguration configuration) {
final KeywordDefinition previousStep = getPreviousStep(edit, nodes);
if(previousStep == null){
return false;
}
return KeywordStatistics.getSequenceSize(previousStep) < configuration.getMaximumStepSize();
}
private KeywordDefinition getPreviousStep(Edit edit, Set nodes){
if(edit.getType() != Edit.Type.REMOVE_STEP){
return null;
}
if(!Step.class.isAssignableFrom(edit.getLeft().getClass())){
return null;
}
return getRelevantStep((Step) edit.getLeft(), nodes);
}
private KeywordDefinition getRelevantStep(Step step, Set nodes){
for(SourceNode node: nodes){
final Optional parent = Cfg.getCallerByName(step, node.getNameToken());
if(parent.isPresent() ){
return parent.get();
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy