lu.uni.serval.ikora.smells.checks.LoggingInFixtureCodeCheck 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.smells.visitors.CollectCallsByTypeVisitor;
import lu.uni.serval.ikora.core.analytics.difference.Edit;
import lu.uni.serval.ikora.core.analytics.KeywordStatistics;
import lu.uni.serval.ikora.core.analytics.visitor.PathMemory;
import lu.uni.serval.ikora.core.model.Keyword;
import lu.uni.serval.ikora.core.model.SourceNode;
import lu.uni.serval.ikora.core.model.TestCase;
import java.util.Collections;
import java.util.Set;
public class LoggingInFixtureCodeCheck implements SmellCheck {
@Override
public SmellResult computeMetric(TestCase testCase, SmellConfiguration configuration) {
Set nodes = Collections.emptySet();
double rawValue = Double.NaN;
double normalizedValud = Double.NaN;
if(testCase.getSetup().isPresent() || testCase.getTearDown().isPresent()){
int statements = testCase.getSetup().map(KeywordStatistics::getStatementCount).orElse(1) - 1
+ testCase.getTearDown().map(KeywordStatistics::getStatementCount).orElse(1) - 1;
nodes = getFixtureLoggingNodes(testCase);
rawValue = nodes.size();
normalizedValud = rawValue / statements;
}
return new SmellResult(SmellMetric.Type.LOGGING_IN_FIXTURE_CODE, rawValue, normalizedValud, nodes);
}
@Override
public boolean isFix(Edit edit, Set nodes, SmellConfiguration configuration) {
return SmellCheck.isFix(edit, nodes, Edit.Type.REMOVE_STEP);
}
private Set getFixtureLoggingNodes(TestCase testCase){
CollectCallsByTypeVisitor visitor = new CollectCallsByTypeVisitor(Keyword.Type.LOG);
testCase.getSetup().ifPresent(s -> visitor.visit(s, new PathMemory()));
testCase.getTearDown().ifPresent(s -> visitor.visit(s, new PathMemory()));
return visitor.getNodes();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy